updated script
This commit is contained in:
parent
e4089c9f75
commit
ca9548bfea
|
|
@ -152,10 +152,13 @@ async function main() {
|
|||
pool: { max: 5, min: 0, idle: 10000 },
|
||||
});
|
||||
|
||||
// Sequelize sqlite connection-manager runs PRAGMA FOREIGN_KEYS=ON on every new connection
|
||||
// unless foreignKeys === false, which overrides manual PRAGMA OFF during pooled/transaction use.
|
||||
const sqlite = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: sqlitePath,
|
||||
logging: false,
|
||||
foreignKeys: false,
|
||||
define: { underscored: true, freezeTableName: true },
|
||||
});
|
||||
|
||||
|
|
@ -178,11 +181,7 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
// SQLite enforces FKs on INSERT. `users.created_by` → `users.id` must not depend on row
|
||||
// order from Postgres; same for optional refs. Turn FKs off for the whole clear+copy, then on.
|
||||
console.log('\n🗑️ Clearing SQLite tables…');
|
||||
await sqlite.query('PRAGMA foreign_keys = OFF');
|
||||
try {
|
||||
for (const table of TABLES_DELETE_REVERSE) {
|
||||
await sqlite.query(`DELETE FROM "${table}"`, { type: QueryTypes.DELETE });
|
||||
}
|
||||
|
|
@ -191,10 +190,12 @@ async function main() {
|
|||
console.log('📥 Copying from PostgreSQL → SQLite…\n');
|
||||
for (const table of TABLES_ORDER) {
|
||||
const rows = await fetchPostgresTable(pg, table);
|
||||
try {
|
||||
await insertRows(sqlite, table, rows);
|
||||
} catch (e) {
|
||||
e.message = `[${table}] ${e.message}`;
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
await sqlite.query('PRAGMA foreign_keys = ON');
|
||||
}
|
||||
|
||||
await pg.close();
|
||||
|
|
|
|||
Loading…
Reference in New Issue