fix(db): name the Postgres compose file in the move command hint

The boot refusal beside a SQLite install told the operator to run the move
with plain `docker compose run`, which uses the SQLite compose file. It now
gives the command the wiki gives, and PGBOOT-037 holds both to the page.
This commit is contained in:
Maurice
2026-11-18 13:20:08 +01:00
parent 69e791206e
commit 81628d78ee
3 changed files with 34 additions and 6 deletions
@@ -36,10 +36,16 @@ export interface PostgresBootstrapDeps {
sqliteLeftBehind: () => string | null;
}
/** The command that moves a SQLite install into Postgres, as the refusal names it. */
const MOVE_COMMAND_HINT =
'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 commands that move a SQLite install into Postgres, as the refusal names
* them: the one the wiki page Database-Postgres gives for a compose install,
* and the one outside Docker. A test keeps both the same as the page.
*/
export const MOVE_COMMAND_DOCKER =
'docker compose -f docker-compose.postgres.yml run --rm --user node -w /app/server app ' +
'node --require tsconfig-paths/register dist/move-to-postgres.js';
export const MOVE_COMMAND_NPM = 'npm run db:move-to-postgres';
const MOVE_COMMAND_HINT = `${MOVE_COMMAND_DOCKER} (${MOVE_COMMAND_NPM} in server/ outside Docker)`;
/**
* The refusal of a boot that would come up empty on Postgres while `file`
+1 -1
View File
@@ -8,7 +8,7 @@ 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 \
* docker compose -f docker-compose.postgres.yml 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)
*
@@ -6,6 +6,8 @@
import type { AppEnv } from '../../../../../src/app-config';
import {
bootstrapPostgresSchema,
MOVE_COMMAND_DOCKER,
MOVE_COMMAND_NPM,
postgresSafetyNet,
sqliteLeftBehindCheck,
type PostgresBootstrapDeps,
@@ -15,7 +17,7 @@ import type { AnyOrm } from '../../../../../src/db/orm';
import { answersSchema, failsWith, installFakeTool, writesFile } from '../../../../helpers/fake-pg-tools';
import { Logger } from '@nestjs/common';
import { mkdtempSync, readdirSync, rmSync, utimesSync, writeFileSync } from 'node:fs';
import { mkdtempSync, readdirSync, readFileSync, rmSync, utimesSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -291,6 +293,26 @@ describe('bootstrapPostgresSchema', () => {
expect(db.ensureTable).not.toHaveBeenCalled();
});
it('PGBOOT-037: the refusal names the move commands the wiki gives, word for word', async () => {
const repoRoot = path.resolve(__dirname, '../../../../../..');
const page = readFileSync(path.join(repoRoot, 'wiki', 'Database-Postgres.md'), 'utf8').replace(/\r\n?/g, '\n');
const steps = page.slice(page.indexOf('### Steps with Docker Compose'), page.indexOf('### Going back'));
// The page breaks the command over lines with a trailing backslash; the shell joins them.
const bashBlocks = [...steps.matchAll(/^ *```bash\n([\s\S]*?)\n *```$/gm)].map((match) =>
match[1].replace(/\\\n\s*/g, '').trim(),
);
expect(bashBlocks).toContain(MOVE_COMMAND_DOCKER);
expect(steps).toContain(`\`${MOVE_COMMAND_NPM}\``);
const { orm } = fakeOrm({ executed: [], pending: [M1], tables: [] });
const refusal = bootstrapPostgresSchema(
orm,
deps(noNet(), () => LEFT_BEHIND),
);
await expect(refusal).rejects.toThrow(MOVE_COMMAND_DOCKER);
await expect(refusal).rejects.toThrow(MOVE_COMMAND_NPM);
});
it('PGBOOT-031: a schema without a single account (a move cut short) beside such an install is refused too', async () => {
const { orm, db } = fakeOrm({ executed: [M1, M2], pending: [M3], tables: ['users'], accounts: false });
const net = deps(noNet(), () => LEFT_BEHIND);