Skip to content

Commit db93d6d

Browse files
author
Josh Calder
committed
Add migrate check script
1 parent 7a4837d commit db93d6d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { runMigrateWithDbUrl, withMigrate } from '../../lib/migrations';
2+
import { loadBuiltConfig } from '../../lib/config/loadConfig';
3+
import { ExitError } from '../utils';
4+
import { getSchemaPaths } from '../../artifacts';
5+
6+
export async function checkMigrations(cwd: string) {
7+
const config = loadBuiltConfig(cwd);
8+
await withMigrate(getSchemaPaths(cwd).prisma, async migrate => {
9+
const evaluateDataLossResult = await runMigrateWithDbUrl(
10+
config.db.url,
11+
config.db.shadowDatabaseUrl,
12+
() => migrate.evaluateDataLoss()
13+
);
14+
if (evaluateDataLossResult.migrationSteps) {
15+
console.log('Migrations are out of date - run `keystone migrate generate` to update them');
16+
throw new ExitError(1);
17+
} else {
18+
console.log('✅ Migrations are up to date');
19+
}
20+
});
21+
}

packages/core/src/scripts/migrate/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ExitError } from '../utils';
22
import { applyMigrations } from './apply';
3+
import { checkMigrations } from './check';
34
import { generateMigrations } from './generate';
45

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

0 commit comments

Comments
 (0)