-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmigrate.js
More file actions
58 lines (50 loc) · 1.4 KB
/
migrate.js
File metadata and controls
58 lines (50 loc) · 1.4 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
"use strict";
const { Command } = require("commander");
const { create } = require("./create");
const { up } = require("./up");
const program = new Command();
const CONFIG = {
MIGRATIONS_DB_REGION: process.env.MIGRATIONS_DB_REGION || "ca-central-1",
MIGRATIONS_DB_ENDPOINT: process.env.DYNAMODB_ENDPOINT || "http://localhost:8000",
MIGRATIONS_TABLE_NAME: process.env.MIGRATIONS_TABLE_NAME || "migrations",
MIGRATIONS_DIR: process.env.MIGRATIONS_DIR || "../../migrations",
MIGRATIONS_TEMPLATE: process.env.MIGRATIONS_TEMPLATE || "migration.template",
};
program
.version("0.0.1")
.option(
"-r, --remote",
"Apply migration on remote target, requires AWS credentials in environment"
);
program
.command("create")
.argument("[name]", "name of the migration to create")
.description("create a new migration")
.action((name) => {
create(CONFIG, name);
})
.addHelpText(
"after",
`
Examples:
node migrate.js create helloworld`
);
program
.command("up")
.argument(
"[migration]",
"migration to apply, all preceding migrations will also be applied"
)
.description("apply all migrations or up to a certain migration")
.action((migration) => {
CONFIG.REMOTE = program.opts().remote;
up(CONFIG, migration);
})
.addHelpText(
"after",
`
Examples:
node migrate.js up
ndoe migrate.js up 20211108120000-helloworld.js`
);
program.parse();