Skip to content

Commit edc47db

Browse files
arnegmattcph
authored andcommitted
Migration: create table only if necessary
1 parent ae8ed4f commit edc47db

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

lib/SyncDB.pmod/Migration.pmod

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,19 +309,21 @@ class Base {
309309
.MySQL.Query alter = upgrade_table(table_name);
310310
if (alter) alter(sql);
311311

312-
object tbl = SyncDB.MySQL.Table(table_name, sql, to);
313-
314-
if (update_table) {
315-
update_table(tbl);
316-
} else if (update_row) {
317-
// fetch all rows and update
318-
foreach (tbl->PageIterator(0, 0, 100);; array|object rows) {
319-
foreach (rows;; mapping row) {
320-
mapping changes = update_row(row);
321-
if (changes) {
322-
object filter = tbl->schema->get_versioned_filter(row);
323-
if (!tbl->update(changes, filter)) {
324-
error("Updating row %O during migration failed.\n", row);
312+
if (update_table || update_row) {
313+
object tbl = SyncDB.MySQL.Table(table_name, sql, to);
314+
315+
if (update_table) {
316+
update_table(tbl);
317+
} else if (update_row) {
318+
// fetch all rows and update
319+
foreach (tbl->PageIterator(0, 0, 100);; array|object rows) {
320+
foreach (rows;; mapping row) {
321+
mapping changes = update_row(row);
322+
if (changes) {
323+
object filter = tbl->schema->get_versioned_filter(row);
324+
if (!tbl->update(changes, filter)) {
325+
error("Updating row %O during migration failed.\n", row);
326+
}
325327
}
326328
}
327329
}

0 commit comments

Comments
 (0)