-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathcli.ts
More file actions
52 lines (51 loc) · 1.37 KB
/
cli.ts
File metadata and controls
52 lines (51 loc) · 1.37 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
#!/usr/bin/env node
import yargs from "yargs"
import { migrate, reset, generate, createMigration, initPgstrap } from "./"
import { getProjectContext } from "./get-project-context"
;(yargs as any)
.command("init", "initialize pgstrap", {}, async () => {
await initPgstrap({
cwd: process.cwd(),
})
})
.command(
"create-migration [name]",
"create a new migration",
(yargs) => {
yargs.positional("name", {
describe: "name of the migration file",
type: "string",
})
},
async (argv) => {
const ctx = await getProjectContext()
createMigration(argv.name as string, ctx)
},
)
.command("reset", "resets the database", {}, async () => {
await reset(await getProjectContext())
// Reset hangs, probably due to unclosed pg connection
process.exit(0)
})
.command("migrate", "migrates the database", {}, async () => {
migrate(await getProjectContext())
})
.command(
"generate",
"generate types and sql documentation from database",
(yargs) => {
yargs.option("pglite", {
type: "boolean",
default: true,
describe:
"run migrations in an in-memory PGlite database before generating types",
})
},
async (argv) => {
await generate({
...(await getProjectContext()),
pglite: argv.pglite !== false,
})
},
)
.parse()