-
-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathcurrent.ts
More file actions
73 lines (66 loc) · 1.91 KB
/
current.ts
File metadata and controls
73 lines (66 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { CommandModule } from "yargs";
import { getCurrentMigrationLocation, writeCurrentMigration } from "../current";
import { ParsedSettings, parseSettings, Settings } from "../settings";
import { CommonArgv, getSettings } from "./_common";
import { _migrate } from "./migrate";
import { _makeCurrentMigrationRunner } from "./watch";
interface CurrentArgv extends CommonArgv {
shadow: boolean;
forceActions: boolean;
}
export async function _current(
parsedSettings: ParsedSettings,
shadow = false,
forceActions = false,
): Promise<void> {
await _migrate(parsedSettings, shadow);
const currentLocation = await getCurrentMigrationLocation(parsedSettings);
if (!currentLocation.exists) {
await writeCurrentMigration(
parsedSettings,
currentLocation,
parsedSettings.blankMigrationContent.trim() + "\n",
);
}
const run = _makeCurrentMigrationRunner(
parsedSettings,
false,
shadow,
forceActions,
);
return run();
}
export async function current(
settings: Settings,
shadow = false,
forceActions = false,
): Promise<void> {
const parsedSettings = await parseSettings(settings, shadow);
return _current(parsedSettings, shadow, forceActions);
}
export const currentCommand: CommandModule<never, CurrentArgv> = {
command: "current",
aliases: [],
describe:
"Runs any un-executed committed migrations, as well as the current migration. For development.",
builder: {
shadow: {
type: "boolean",
default: false,
description: "Apply migrations to the shadow DB (for development).",
},
forceActions: {
type: "boolean",
default: false,
description:
"Run beforeAllMigrations and afterAllMigrations actions even if no migration was necessary.",
},
},
handler: async argv => {
await current(
await getSettings({ configFile: argv.config }),
argv.shadow,
argv.forceActions,
);
},
};