Skip to content

Migrator

renameSystemTables()

renameSystemTables() — returns struct

Available in: migrator Category: General Functions

F15 Phase 2: rename legacy c_o_r_e_ system tables to wheels_. Public API for the wheels migrate rename-system-tables CLI command. Reads the current schema, generates per-adapter rename SQL, and (unless dryRun is true) executes it inside a transaction. After a successful rename, updates application.wheels.{levelsTableName, migratorTableName} to the new names so the running app picks them up without a restart. Result struct:

  • success: boolean
  • renamed: array of “old -> new” strings (empty if no-op)
  • skipped: human message when there’s nothing to do
  • errors: array of error messages (when success=false)
  • sql: array of SQL statements that would run / did run Refuses to run (returns success=false) when both c_o_r_e_ AND wheels_ versions of either table coexist — that’s a partial- rename state which warrants manual cleanup, not silent destruction.
NameTypeRequiredDefaultDescription
dryRunbooleannofalseWhen true, returns the SQL that would run without executing.
// 1. Rename legacy c_o_r_e_* tables to wheels_* in one step
result = application.wheels.migrator.renameSystemTables();
// result.success  -> true
// result.renamed  -> ["c_o_r_e_levels -> wheels_levels", "c_o_r_e_migrator_versions -> wheels_migrator_versions"]
// result.sql      -> ["ALTER TABLE c_o_r_e_migrator_versions RENAME TO wheels_migrator_versions", "ALTER TABLE c_o_r_e_levels RENAME TO wheels_levels"]
// result.skipped  -> ""
// result.errors   -> []

// 2. Dry-run: preview the SQL without executing any changes
result = application.wheels.migrator.renameSystemTables(dryRun=true);
// result.success  -> true
// result.renamed  -> []   (nothing executed)
// result.sql      -> ["ALTER TABLE c_o_r_e_migrator_versions RENAME TO wheels_migrator_versions", "ALTER TABLE c_o_r_e_levels RENAME TO wheels_levels"]

// 3. Handle all possible outcomes after running the rename
result = application.wheels.migrator.renameSystemTables();
if (!result.success) {
    // Partial-rename conflict or execution error
    writeOutput("Rename failed: " & arrayToList(result.errors, "; "));
} else if (len(result.skipped)) {
    // Tables were already on wheels_* names (or no legacy tables found)
    writeOutput(result.skipped);
} else {
    writeOutput("Renamed: " & arrayToList(result.renamed, ", "));
}