Fix bugs, improve schema gen
This commit is contained in:
@@ -7,6 +7,8 @@ import type {
|
||||
import handleDBSchemaTable from "./handle-db-schema-table";
|
||||
import getExistingTablesFromTablesManagerTable from "./get-existing-tables-from-tables-manager-table";
|
||||
import MariaDBQuoteGen from "./mariadb-quote-gen";
|
||||
import resolveTable from "./resolve-table";
|
||||
import { ensureForeignKeys } from "./sync-foreign-keys";
|
||||
import runSchemaQuery, { querySchemaRows } from "./run-schema-query";
|
||||
import schemaCondition from "./schema-condition";
|
||||
import { removeDbManagerTable } from "./upsert-db-manager-table";
|
||||
@@ -51,6 +53,19 @@ export default async function handleDBSchemaTables(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Foreign keys last: every referenced table now exists, so forward
|
||||
* references, self references and cycles between tables all resolve.
|
||||
*/
|
||||
for (const table of db_schema.tables) {
|
||||
if (!table) continue;
|
||||
|
||||
await ensureForeignKeys({
|
||||
table: resolveTable(table, db_schema),
|
||||
config,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop tables tracked by the manager but no longer in the schema.
|
||||
* Skip drops when remaining schema tables still reference the table via FK
|
||||
|
||||
Reference in New Issue
Block a user