MCPcopy
hub / github.com/drizzle-team/drizzle-orm / dropMigration

Function dropMigration

drizzle-kit/src/cli/commands/drop.ts:10–60  ·  view source on GitHub ↗
({
	out,
	bundle,
}: {
	out: string;
	bundle: boolean;
})

Source from the content-addressed store, hash-verified

8import { embeddedMigrations } from './migrate';
9
10export const dropMigration = async ({
11 out,
12 bundle,
13}: {
14 out: string;
15 bundle: boolean;
16}) => {
17 const metaFilePath = join(out, 'meta', '_journal.json');
18 const journal = JSON.parse(readFileSync(metaFilePath, 'utf-8')) as Journal;
19
20 if (journal.entries.length === 0) {
21 console.log(
22 `[${chalk.blue('i')}] no migration entries found in ${metaFilePath}`,
23 );
24 return;
25 }
26
27 const result = await render(new DropMigrationView(journal.entries));
28 if (result.status === 'aborted') return;
29
30 delete journal.entries[journal.entries.indexOf(result.data!)];
31
32 const resultJournal: Journal = {
33 ...journal,
34 entries: journal.entries.filter(Boolean),
35 };
36 const sqlFilePath = join(out, `${result.data.tag}.sql`);
37 const snapshotFilePath = join(
38 out,
39 'meta',
40 `${result.data.tag.split('_')[0]}_snapshot.json`,
41 );
42 rmSync(sqlFilePath);
43 rmSync(snapshotFilePath);
44 writeFileSync(metaFilePath, JSON.stringify(resultJournal, null, 2));
45
46 if (bundle) {
47 fs.writeFileSync(
48 join(out, `migrations.js`),
49 embeddedMigrations(resultJournal),
50 );
51 }
52
53 console.log(
54 `[${chalk.green('✓')}] ${
55 chalk.bold(
56 result.data.tag,
57 )
58 } migration successfully dropped`,
59 );
60};

Callers 1

schema.tsFile · 0.90

Calls 2

embeddedMigrationsFunction · 0.90
joinFunction · 0.85

Tested by

no test coverage detected