diff --git a/server/src/db/engine/postgres/schema-bootstrap.ts b/server/src/db/engine/postgres/schema-bootstrap.ts index 0b6871db2..e243b97a8 100644 --- a/server/src/db/engine/postgres/schema-bootstrap.ts +++ b/server/src/db/engine/postgres/schema-bootstrap.ts @@ -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` diff --git a/server/src/move-to-postgres.ts b/server/src/move-to-postgres.ts index 3eefba3a5..dab162889 100644 --- a/server/src/move-to-postgres.ts +++ b/server/src/move-to-postgres.ts @@ -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) * diff --git a/server/tests/unit/db/engine/postgres/schema-bootstrap.test.ts b/server/tests/unit/db/engine/postgres/schema-bootstrap.test.ts index 31b8e063f..703153a7a 100644 --- a/server/tests/unit/db/engine/postgres/schema-bootstrap.test.ts +++ b/server/tests/unit/db/engine/postgres/schema-bootstrap.test.ts @@ -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);