From 104f071b93b7a8b6ebbc2c28f0af0f5d0c616023 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Tue, 13 Feb 2024 15:28:26 -0600 Subject: [PATCH] feat: allow verify to mock migration file --- packages/db/src/core/cli/commands/verify/index.ts | 12 ++++++++++++ packages/db/src/core/cli/migrations.ts | 1 + 2 files changed, 13 insertions(+) diff --git a/packages/db/src/core/cli/commands/verify/index.ts b/packages/db/src/core/cli/commands/verify/index.ts index 6e67ec1da8..bed2ff3c12 100644 --- a/packages/db/src/core/cli/commands/verify/index.ts +++ b/packages/db/src/core/cli/commands/verify/index.ts @@ -1,11 +1,23 @@ import type { AstroConfig } from 'astro'; import type { Arguments } from 'yargs-parser'; import { getMigrationStatus, MIGRATION_NEEDED, MIGRATIONS_NOT_INITIALIZED, MIGRATIONS_UP_TO_DATE } from '../../migrations.js'; +import { getMigrationQueries } from '../../migration-queries.js'; export async function cmd({ config, flags }: { config: AstroConfig; flags: Arguments }) { const status = await getMigrationStatus(config); const { state } = status; if (flags.json) { + if (state === 'ahead') { + const { queries: migrationQueries } = await getMigrationQueries({ + oldSnapshot: status.oldSnapshot, + newSnapshot: status.newSnapshot + }); + const newFileContent = { + diff: status.diff, + db: migrationQueries, + } + status.newFileContent = JSON.stringify(newFileContent, null, 2); + } console.log(JSON.stringify(status)); process.exit(state === 'up-to-date' ? 0 : 1); } diff --git a/packages/db/src/core/cli/migrations.ts b/packages/db/src/core/cli/migrations.ts index 176211d523..977816ecf1 100644 --- a/packages/db/src/core/cli/migrations.ts +++ b/packages/db/src/core/cli/migrations.ts @@ -15,6 +15,7 @@ export type MigrationStatus = { diff: deepDiff.Diff[], newFilename: string, summary: string, + newFileContent?: string, } | { state: 'up-to-date', currentSnapshot: DBSnapshot