Skip to content

Commit

Permalink
Add migrate check script
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Calder committed Dec 13, 2022
1 parent 7a4837d commit db93d6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/core/src/scripts/migrate/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { runMigrateWithDbUrl, withMigrate } from '../../lib/migrations';
import { loadBuiltConfig } from '../../lib/config/loadConfig';
import { ExitError } from '../utils';
import { getSchemaPaths } from '../../artifacts';

export async function checkMigrations(cwd: string) {
const config = loadBuiltConfig(cwd);
await withMigrate(getSchemaPaths(cwd).prisma, async migrate => {
const evaluateDataLossResult = await runMigrateWithDbUrl(
config.db.url,
config.db.shadowDatabaseUrl,
() => migrate.evaluateDataLoss()
);
if (evaluateDataLossResult.migrationSteps) {
console.log('Migrations are out of date - run `keystone migrate generate` to update them');
throw new ExitError(1);
} else {
console.log('✅ Migrations are up to date');
}
});
}
3 changes: 3 additions & 0 deletions packages/core/src/scripts/migrate/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ExitError } from '../utils';
import { applyMigrations } from './apply';
import { checkMigrations } from './check';
import { generateMigrations } from './generate';

export async function migrate(cwd: string, input: string[], shouldDropDatabase: boolean) {
Expand All @@ -9,6 +10,8 @@ export async function migrate(cwd: string, input: string[], shouldDropDatabase:
return generateMigrations(cwd, shouldDropDatabase);
case 'apply':
return applyMigrations(cwd);
case 'check':
return checkMigrations(cwd);
default:
console.log(`${migrateCommand} is not a migrate command that keystone accepts`);
throw new ExitError(1);
Expand Down

0 comments on commit db93d6d

Please sign in to comment.