@@ -1303,51 +1303,48 @@ func (e *Extractor) mysqlDump() (retErr error) {
1303
1303
1304
1304
e .gotCoordinateCh <- struct {}{}
1305
1305
1306
- // Transform the current schema so that it reflects the *current* state of the MySQL server's contents.
1307
- // First, get the DROP TABLE and CREATE TABLE statement (with keys and constraint definitions) for our tables ...
1308
- if ! e .mysqlContext .SkipCreateDbTable {
1309
- e .logger .Info ("generating DROP and CREATE statements to reflect current database schemas" ,
1310
- "replicateDoDb" , e .replicateDoDb )
1311
-
1312
- for _ , db := range e .replicateDoDb {
1313
- var dbSQL string
1314
- if strings .ToLower (db .TableSchema ) != "mysql" {
1315
- if db .TableSchemaRename != "" {
1316
- dbSQL , err = base .RenameCreateSchemaAddINE (db .CreateSchemaString , db .TableSchemaRename )
1317
- if err != nil {
1318
- return errors .Wrap (err , "RenameCreateSchemaAddINE" )
1319
- }
1320
- } else {
1321
- dbSQL = db .CreateSchemaString
1306
+ // Go through all tables to get DDL and row numbers.
1307
+ for _ , db := range e .replicateDoDb {
1308
+ if strings .ToLower (db .TableSchema ) == "mysql" {
1309
+ continue
1310
+ }
1311
+
1312
+ // Create the schema.
1313
+ entry := & common.DumpEntry {}
1314
+ if ! e .mysqlContext .SkipCreateDbTable {
1315
+ if db .TableSchemaRename != "" {
1316
+ entry .DbSQL , err = base .RenameCreateSchemaAddINE (db .CreateSchemaString , db .TableSchemaRename )
1317
+ if err != nil {
1318
+ return errors .Wrap (err , "RenameCreateSchemaAddINE" )
1322
1319
}
1320
+ } else {
1321
+ entry .DbSQL = db .CreateSchemaString
1322
+ }
1323
+ }
1324
+ if err := e .encodeAndSendDumpEntry (entry ); err != nil {
1325
+ return errors .Wrap (err , "encodeAndSendDumpEntry. create schema entry" )
1326
+ }
1323
1327
1328
+ // Create the tables.
1329
+ for _ , tbCtx := range db .TableMap {
1330
+ tb := tbCtx .Table
1331
+ tb .Counter , err = e .CountTableRows (tb )
1332
+ if err != nil {
1333
+ return errors .Wrapf (err , "CountTableRows %v.%v" , tb .TableSchema , tb .TableName )
1324
1334
}
1335
+ e .logger .Info ("count table" , "schema" , db .TableSchema , "table" , tb .TableName , "rows" , tb .Counter )
1336
+
1325
1337
entry := & common.DumpEntry {
1326
- DbSQL : dbSQL ,
1327
- }
1328
- atomic .AddInt64 (& e .mysqlContext .RowsEstimate , 1 )
1329
- atomic .AddInt64 (& e .TotalRowsCopied , 1 )
1330
- if err := e .encodeAndSendDumpEntry (entry ); err != nil {
1331
- return errors .Wrap (err , "encodeAndSendDumpEntry. create schema entry" )
1338
+ TbSQL : []string {},
1339
+ TotalCount : tb .Counter ,
1332
1340
}
1333
-
1334
- for _ , tbCtx := range db .TableMap {
1335
- tb := tbCtx .Table
1336
- if tb .TableSchema != db .TableSchema {
1337
- continue
1338
- }
1339
- total , err := e .CountTableRows (tb )
1340
- if err != nil {
1341
- return errors .Wrapf (err , "CountTableRows %v.%v" , tb .TableSchema , tb .TableName )
1342
- }
1343
- tb .Counter = total
1344
- var tbSQL []string
1341
+ if ! e .mysqlContext .SkipCreateDbTable {
1345
1342
if strings .ToLower (tb .TableType ) == "view" {
1346
1343
/*tbSQL, err = base.ShowCreateView(e.singletonDB, tb.TableSchema, tb.TableName, e.mysqlContext.DropTableIfExists)
1347
1344
if err != nil {
1348
1345
return err
1349
1346
}*/
1350
- } else if strings . ToLower ( tb . TableSchema ) != "mysql" {
1347
+ } else {
1351
1348
ctStmt , err := base .ShowCreateTable (e .singletonDB , tb .TableSchema , tb .TableName )
1352
1349
if err != nil {
1353
1350
return err
@@ -1362,23 +1359,17 @@ func (e *Extractor) mysqlDump() (retErr error) {
1362
1359
}
1363
1360
1364
1361
if e .mysqlContext .DropTableIfExists {
1365
- tbSQL = append (tbSQL , fmt .Sprintf ("DROP TABLE IF EXISTS %s.%s" ,
1362
+ entry . TbSQL = append (entry . TbSQL , fmt .Sprintf ("DROP TABLE IF EXISTS %s.%s" ,
1366
1363
mysqlconfig .EscapeName (targetSchema ), mysqlconfig .EscapeName (targetTable )))
1367
1364
}
1368
- tbSQL = append (tbSQL , ctStmt )
1369
- }
1370
- entry := & common.DumpEntry {
1371
- TbSQL : tbSQL ,
1372
- TotalCount : tb .Counter ,
1373
- }
1374
- atomic .AddInt64 (& e .mysqlContext .RowsEstimate , 1 )
1375
- atomic .AddInt64 (& e .TotalRowsCopied , 1 )
1376
- if err := e .encodeAndSendDumpEntry (entry ); err != nil {
1377
- return errors .Wrap (err , "encodeAndSendDumpEntry. create table" )
1365
+ entry .TbSQL = append (entry .TbSQL , ctStmt )
1378
1366
}
1379
1367
}
1380
- e .tableCount += len (db .TableMap )
1368
+ if err := e .encodeAndSendDumpEntry (entry ); err != nil {
1369
+ return errors .Wrap (err , "encodeAndSendDumpEntry. create table" )
1370
+ }
1381
1371
}
1372
+ e .tableCount += len (db .TableMap )
1382
1373
}
1383
1374
step ++
1384
1375
0 commit comments