mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
feat: allow verify to mock migration file
This commit is contained in:
parent
30cf903fe0
commit
104f071b93
2 changed files with 13 additions and 0 deletions
|
@ -1,11 +1,23 @@
|
||||||
import type { AstroConfig } from 'astro';
|
import type { AstroConfig } from 'astro';
|
||||||
import type { Arguments } from 'yargs-parser';
|
import type { Arguments } from 'yargs-parser';
|
||||||
import { getMigrationStatus, MIGRATION_NEEDED, MIGRATIONS_NOT_INITIALIZED, MIGRATIONS_UP_TO_DATE } from '../../migrations.js';
|
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 }) {
|
export async function cmd({ config, flags }: { config: AstroConfig; flags: Arguments }) {
|
||||||
const status = await getMigrationStatus(config);
|
const status = await getMigrationStatus(config);
|
||||||
const { state } = status;
|
const { state } = status;
|
||||||
if (flags.json) {
|
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));
|
console.log(JSON.stringify(status));
|
||||||
process.exit(state === 'up-to-date' ? 0 : 1);
|
process.exit(state === 'up-to-date' ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ export type MigrationStatus = {
|
||||||
diff: deepDiff.Diff<DBSnapshot, DBSnapshot>[],
|
diff: deepDiff.Diff<DBSnapshot, DBSnapshot>[],
|
||||||
newFilename: string,
|
newFilename: string,
|
||||||
summary: string,
|
summary: string,
|
||||||
|
newFileContent?: string,
|
||||||
} | {
|
} | {
|
||||||
state: 'up-to-date',
|
state: 'up-to-date',
|
||||||
currentSnapshot: DBSnapshot
|
currentSnapshot: DBSnapshot
|
||||||
|
|
Loading…
Add table
Reference in a new issue