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 },
|
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({
|
const sqlite = new Sequelize({
|
||||||
dialect: 'sqlite',
|
dialect: 'sqlite',
|
||||||
storage: sqlitePath,
|
storage: sqlitePath,
|
||||||
logging: false,
|
logging: false,
|
||||||
|
foreignKeys: false,
|
||||||
define: { underscored: true, freezeTableName: true },
|
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…');
|
console.log('\n🗑️ Clearing SQLite tables…');
|
||||||
await sqlite.query('PRAGMA foreign_keys = OFF');
|
|
||||||
try {
|
|
||||||
for (const table of TABLES_DELETE_REVERSE) {
|
for (const table of TABLES_DELETE_REVERSE) {
|
||||||
await sqlite.query(`DELETE FROM "${table}"`, { type: QueryTypes.DELETE });
|
await sqlite.query(`DELETE FROM "${table}"`, { type: QueryTypes.DELETE });
|
||||||
}
|
}
|
||||||
|
|
@ -191,10 +190,12 @@ async function main() {
|
||||||
console.log('📥 Copying from PostgreSQL → SQLite…\n');
|
console.log('📥 Copying from PostgreSQL → SQLite…\n');
|
||||||
for (const table of TABLES_ORDER) {
|
for (const table of TABLES_ORDER) {
|
||||||
const rows = await fetchPostgresTable(pg, table);
|
const rows = await fetchPostgresTable(pg, table);
|
||||||
|
try {
|
||||||
await insertRows(sqlite, table, rows);
|
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();
|
await pg.close();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue