mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
36f64c51c8
npm run db:move-to-postgres (dist/move-to-postgres.js in the image) copies a SQLite file at this build's migration level into an empty Postgres database. It refuses a file at another level, rows whose references point at nothing and a target holding any table or plugin schema, creates the schema with the engine's own bootstrap, then in one transaction copies every table in foreign key order (setting a self-reference once its rows are in), converts each value to its column's type and refuses one Postgres cannot hold exactly, copies each plugin's plugin.db into its schema, moves the sequences past the copied ids and compares every table's row count and an order-free checksum over all rows before it commits. A failure drops the schema again. The SQLite files and the uploads are never written.
21 lines
915 B
TypeScript
21 lines
915 B
TypeScript
import 'reflect-metadata';
|
|
import 'dotenv/config';
|
|
// The same fail-fast validation as a server start: TREK_DB_URL is read as the server reads it.
|
|
import './app-config/boot-validate';
|
|
|
|
import { runMoveCommand } from './db/engine/postgres/sqlite-move/command';
|
|
|
|
/**
|
|
* Moves a SQLite install into an empty Postgres database, with TREK stopped:
|
|
*
|
|
* docker compose run --rm --user node -w /app/server app \
|
|
* node --require tsconfig-paths/register dist/move-to-postgres.js
|
|
* npm run db:move-to-postgres (in server/, outside Docker)
|
|
*
|
|
* The target is TREK_DB_URL; the source is data/travel.db, or --from=<file>.
|
|
* The SQLite files and the uploads are never changed. The wiki page
|
|
* Database-Postgres ("Moving an existing install to Postgres") has the steps,
|
|
* and src/db/engine/postgres/sqlite-move/ the move itself.
|
|
*/
|
|
void runMoveCommand(process.argv.slice(2)).then((code) => process.exit(code));
|