mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -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 { 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);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ export type MigrationStatus = {
|
|||
diff: deepDiff.Diff<DBSnapshot, DBSnapshot>[],
|
||||
newFilename: string,
|
||||
summary: string,
|
||||
newFileContent?: string,
|
||||
} | {
|
||||
state: 'up-to-date',
|
||||
currentSnapshot: DBSnapshot
|
||||
|
|
Loading…
Reference in a new issue