@@ -11,6 +11,7 @@ import (
11
11
12
12
// Skeleton the main type with captures all the yaml data
13
13
type Skeleton struct {
14
+ RandomDataForMissingTables bool `yaml: "RandomDataForMissingTables"`
14
15
Custom []TableModel `yaml:"Custom"`
15
16
}
16
17
@@ -277,12 +278,39 @@ func (c *Skeleton) LoadDataByConfiguration() {
277
278
db := ConnectDB ()
278
279
defer db .Close ()
279
280
281
+ if c .RandomDataForMissingTables {
282
+ var w []string
283
+ for _ , s := range c .Custom {
284
+ w = append (w , fmt .Sprintf ("'%s.%s'" , s .Table , s .Schema ))
285
+ }
286
+ whereClause := fmt .Sprintf ("AND (n.nspname || '.' || c.relname) NOT IN (%s)" , strings .Join (w , "," ))
287
+ allTables := dbExtractTables (whereClause )
288
+
289
+ var tablesToAutoMock []DBTables
290
+ AllTablesLoop:
291
+ for _ , t := range allTables {
292
+ for _ , s := range c .Custom {
293
+ if t .Table == s .Table && t .Schema == s .Schema {
294
+ continue AllTablesLoop
295
+ }
296
+ }
297
+ Debugf ("Table to automatically mock: %s" , t .Table )
298
+ tablesToAutoMock = append (tablesToAutoMock , t )
299
+ }
300
+ tableMocker (tablesToAutoMock )
301
+ } else {
302
+ BackupDDL () // tableMocker does it automatically
303
+ }
304
+
305
+
280
306
for _ , s := range c .Custom {
281
307
// Initialize the mocking process
282
308
tab := GenerateTableName (s .Table , s .Schema )
283
309
msg := fmt .Sprintf ("Mocking Table %s" , tab )
284
310
bar := StartProgressBar (msg , cmdOptions .Rows )
285
-
311
+ if c .RandomDataForMissingTables {
312
+ RemoveConstraints (tab )
313
+ }
286
314
// Name the for loop to break when we encounter error
287
315
DataTypePickerLoop:
288
316
// Loop through the row count and start loading the data
@@ -314,10 +342,14 @@ func (c *Skeleton) LoadDataByConfiguration() {
314
342
col = append (col , v .Name )
315
343
data = append (data , fmt .Sprintf ("%v" , d ))
316
344
}
317
-
318
345
// Copy the data to the table
319
346
CopyData (tab , col , data , db )
320
347
_ = bar .Add (1 )
321
348
}
322
349
}
350
+
351
+ if c .RandomDataForMissingTables && ! cmdOptions .IgnoreConstraint {
352
+ FixConstraints ()
353
+ }
354
+
323
355
}
0 commit comments