This repository has been archived by the owner on Nov 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·117 lines (101 loc) · 2.81 KB
/
index.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env node
'use strict';
const
chalk = require('chalk'),
clear = require('clear'),
figlet = require('figlet'),
cli = require('commander'),
inquirer = require('inquirer'),
checkConfig = require('./helpers/check-config');
const
migrationReset = require('./command/migrationReset'),
migrationRollback = require('./command/migrationRollback'),
migrationRun = require('./command/migrationRun'),
migrationStatus = require('./command/migrationStatus'),
seed = require('./command/seed'),
makeMigration = require('./command/makeMigration'),
makeSeed = require('./command/makeSeed');
clear();
console.log(
chalk.yellow(
figlet.textSync('Knex CLI', { horizontalLayout: 'full' })
)
);
cli
.version('0.0.1')
.description('DB Management')
.option('-s --stage [stage]', 'Configures the current environment', 'dev')
.option('-c --config [config]', 'Path of the JSON config')
.parse(process.argv);
checkConfig({ stage: cli.stage, filePathConfig: cli.config });
console.log(`Using environment: ${chalk.red(`${cli.stage}`)}`);
console.log(`Current project: ${chalk.green(`${process.env.project_name}`)}`);
cli
.command('migration:refresh')
.description('Refresh migrations by performing rollback and then running from start')
.action(async () => {
await migrationReset();
await migrationRun();
DbClient.destroy();
});
cli
.command('migration:reset')
.description('Rollback migration to the first batch')
.action(async () => {
await migrationReset();
DbClient.destroy();
});
cli
.command('migration:rollback')
.description('Rollback migration to latest batch or to a specific batch number')
.action(async () => {
await migrationRollback();
DbClient.destroy();
});
cli
.command('migration:run')
.description('Run all pending migrations')
.action(async () => {
await migrationRun();
DbClient.destroy();
});
cli
.command('migration:status')
.description('Check migrations current status')
.action(async () => {
await migrationStatus();
DbClient.destroy();
});
cli
.command('seed')
.description('Seed database using seed files')
.action(async () => {
await seed();
DbClient.destroy();
});
cli
.command('make:migration <name> <tableName>')
.description('Create a new migration file')
.action((name, tableName) => {
inquirer.prompt({
type: 'list',
name: 'type',
message: 'Choose an action',
choices: [
{
name: 'Create table',
value: 'create'
},
{
name: 'Select table',
value: 'select'
}
]
}).then(({ type }) => makeMigration({name, tableName, type}));
});
cli
.command('make:seed <name>')
.description('Create a database seeder')
.action(makeSeed);
cli.parse(process.argv);
if (!cli.args.length) cli.help();