@bejibun/core 0.1.37 → 0.1.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +45 -0
- package/ace.d.ts +1 -0
- package/ace.js +18 -0
- package/bootstrap.js +2 -10
- package/bun.lock +41 -6
- package/commands/DbSeedCommand.d.ts +27 -0
- package/commands/DbSeedCommand.js +51 -0
- package/commands/Kernel.d.ts +4 -0
- package/commands/Kernel.js +39 -0
- package/commands/MigrateFreshCommand.d.ts +27 -0
- package/commands/MigrateFreshCommand.js +66 -0
- package/commands/MigrateLatestCommand.d.ts +27 -0
- package/commands/MigrateLatestCommand.js +50 -0
- package/commands/MigrateRollbackCommand.d.ts +27 -0
- package/commands/MigrateRollbackCommand.js +64 -0
- package/commands/MigrateStatusCommand.d.ts +27 -0
- package/commands/MigrateStatusCommand.js +58 -0
- package/config/database.d.ts +1 -0
- package/config/database.js +12 -0
- package/package.json +6 -5
- package/src/ace.ts +22 -0
- package/src/bases/BaseModel.ts +1 -0
- package/src/bootstrap.ts +3 -11
- package/src/commands/DbSeedCommand.ts +57 -0
- package/src/commands/Kernel.ts +49 -0
- package/src/commands/MigrateFreshCommand.ts +76 -0
- package/src/commands/MigrateLatestCommand.ts +56 -0
- package/src/commands/MigrateRollbackCommand.ts +72 -0
- package/src/commands/MigrateStatusCommand.ts +64 -0
- package/src/config/database.ts +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
## [v0.1.38](https://github.com/crenata/bejibun-core/compare/v0.1.36...v0.1.38) - 2025-10-17
|
|
7
|
+
|
|
8
|
+
### 🩹 Fixes
|
|
9
|
+
|
|
10
|
+
### 📖 Changes
|
|
11
|
+
What's New :
|
|
12
|
+
- Adding `ace` for commands
|
|
13
|
+
- Adding commands directory structure
|
|
14
|
+
|
|
15
|
+
Available Commands :
|
|
16
|
+
- `db:seed` Run database seeders
|
|
17
|
+
- `migrate:fresh` Rollback all migrations and re-run migrations
|
|
18
|
+
- `migrate:latest` Run latest migration
|
|
19
|
+
- `migrate:rollback` Rollback the latest migrations
|
|
20
|
+
- `migrate:status` List migrations status
|
|
21
|
+
|
|
22
|
+
### ❤️Contributors
|
|
23
|
+
- Havea Crenata ([@crenata](https://github.com/crenata))
|
|
24
|
+
- Ghulje ([@ghulje](https://github.com/ghulje))
|
|
25
|
+
|
|
26
|
+
**Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
6
30
|
## [v0.1.36](https://github.com/crenata/bejibun-core/compare/v0.1.35...v0.1.36) - 2025-10-14
|
|
7
31
|
|
|
8
32
|
### 🩹 Fixes
|
package/README.md
CHANGED
|
@@ -24,6 +24,51 @@ bun add @bejibun/core
|
|
|
24
24
|
bun ace install @bejibun/core
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
### Ace
|
|
28
|
+
Any commands for development
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
Usage: ace [options] [command]
|
|
32
|
+
|
|
33
|
+
Ace for your commander
|
|
34
|
+
Author: Havea Crenata <havea.crenata@gmail.com>
|
|
35
|
+
|
|
36
|
+
Options:
|
|
37
|
+
-v, --version Show the current version
|
|
38
|
+
-h, --help display help for command
|
|
39
|
+
|
|
40
|
+
Commands:
|
|
41
|
+
db:seed Run database seeders
|
|
42
|
+
migrate:fresh [options] Rollback all migrations and re-run migrations
|
|
43
|
+
migrate:latest Run latest migration
|
|
44
|
+
migrate:rollback Rollback the latest migrations
|
|
45
|
+
migrate:status List migrations status
|
|
46
|
+
help [command] display help for command
|
|
47
|
+
|
|
48
|
+
Examples:
|
|
49
|
+
$ bun ace --help
|
|
50
|
+
$ bun ace --version
|
|
51
|
+
$ bun ace migrate:latest
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Available Commands
|
|
55
|
+
To see list of available commands, run.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
bun ace
|
|
59
|
+
bun ace help
|
|
60
|
+
bun ace --h
|
|
61
|
+
bun ace --help
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
To see help of specific command, run :
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
bun ace help migrate:latest
|
|
68
|
+
bun ace migrate:latest --h
|
|
69
|
+
bun ace migrate:latest --help
|
|
70
|
+
```
|
|
71
|
+
|
|
27
72
|
## Contributors
|
|
28
73
|
- [Havea Crenata](mailto:havea.crenata@gmail.com)
|
|
29
74
|
|
package/ace.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/ace.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Str from "@bejibun/utils/facades/Str";
|
|
2
|
+
import { program } from "commander";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import Kernel from "./commands/Kernel";
|
|
5
|
+
import { version } from "package.json";
|
|
6
|
+
const commandExec = "ace";
|
|
7
|
+
program
|
|
8
|
+
.name(commandExec)
|
|
9
|
+
.version(version, "-v, --version", "Show the current version")
|
|
10
|
+
.description(`${Str.toPascalCase(commandExec)} for your commander${os.EOL}Author: Havea Crenata <havea.crenata@gmail.com>`)
|
|
11
|
+
.addHelpText("after", [
|
|
12
|
+
`${os.EOL}Examples:`,
|
|
13
|
+
`$ bun ${commandExec} --help`,
|
|
14
|
+
`$ bun ${commandExec} --version`,
|
|
15
|
+
`$ bun ${commandExec} migrate:latest`
|
|
16
|
+
].join(`${os.EOL} `));
|
|
17
|
+
Kernel.registerCommands(program);
|
|
18
|
+
program.parse();
|
package/bootstrap.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
import BaseModel from "./bases/BaseModel";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import path from "path";
|
|
5
|
-
const configPath = path.resolve(process.cwd(), "config/database.ts");
|
|
6
|
-
let config;
|
|
7
|
-
if (fs.existsSync(configPath))
|
|
8
|
-
config = require(configPath).default;
|
|
9
|
-
else
|
|
10
|
-
config = require("./config/database").default;
|
|
11
|
-
BaseModel.knex(knex(config));
|
|
2
|
+
import { initDatabase } from "./config/database";
|
|
3
|
+
BaseModel.knex(initDatabase());
|
package/bun.lock
CHANGED
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@bejibun/cors": "^0.1.0",
|
|
8
8
|
"@bejibun/logger": "^0.1.13",
|
|
9
|
-
"@bejibun/utils": "^0.1.
|
|
9
|
+
"@bejibun/utils": "^0.1.1",
|
|
10
10
|
"@vinejs/vine": "^3.0.1",
|
|
11
|
-
"
|
|
11
|
+
"commander": "^14.0.1",
|
|
12
12
|
"knex": "^3.1.0",
|
|
13
13
|
"luxon": "^3.7.2",
|
|
14
14
|
"objection": "^3.1.5",
|
|
15
|
+
"ora": "^9.0.0",
|
|
15
16
|
"pg": "^8.16.3",
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
@@ -22,11 +23,11 @@
|
|
|
22
23
|
},
|
|
23
24
|
},
|
|
24
25
|
"packages": {
|
|
25
|
-
"@bejibun/cors": ["@bejibun/cors@0.1.
|
|
26
|
+
"@bejibun/cors": ["@bejibun/cors@0.1.1", "", { "dependencies": { "@bejibun/utils": "^0.1.0" } }, "sha512-9riA6+yZbCyS1KSB+DnUqF7EevecqbwwMWlJsq29Cqq15fX7YJJr6T/GIt6t905dlAQkbMOloPUp1mpKCKBhFg=="],
|
|
26
27
|
|
|
27
|
-
"@bejibun/logger": ["@bejibun/logger@0.1.
|
|
28
|
+
"@bejibun/logger": ["@bejibun/logger@0.1.14", "", { "dependencies": { "@bejibun/utils": "^0.1.0", "chalk": "^5.6.2", "luxon": "^3.7.2" } }, "sha512-Y0rwHMUaJpKE2G3ZRsXKlpwKPQAVlqut44laFJfltTUS7vMZbnKMuWYdfaCp3rX6DCUNxeaChX+8Jte3tYJ50g=="],
|
|
28
29
|
|
|
29
|
-
"@bejibun/utils": ["@bejibun/utils@0.1.
|
|
30
|
+
"@bejibun/utils": ["@bejibun/utils@0.1.1", "", {}, "sha512-8TofYYN+EhPQgNOkyovMaAamRqbK/PisrAxjspXFlqVLj8bnmdOsZjosTpNXesLGIftn4rKkaFsfaafD//31Hg=="],
|
|
30
31
|
|
|
31
32
|
"@nodelib/fs.scandir": ["@nodelib/fs.scandir@2.1.5", "", { "dependencies": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" } }, "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g=="],
|
|
32
33
|
|
|
@@ -54,6 +55,8 @@
|
|
|
54
55
|
|
|
55
56
|
"ajv-formats": ["ajv-formats@2.1.1", "", { "dependencies": { "ajv": "^8.0.0" } }, "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA=="],
|
|
56
57
|
|
|
58
|
+
"ansi-regex": ["ansi-regex@6.2.2", "", {}, "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg=="],
|
|
59
|
+
|
|
57
60
|
"anymatch": ["anymatch@3.1.3", "", { "dependencies": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" } }, "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw=="],
|
|
58
61
|
|
|
59
62
|
"array-union": ["array-union@2.1.0", "", {}, "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw=="],
|
|
@@ -70,9 +73,13 @@
|
|
|
70
73
|
|
|
71
74
|
"chokidar": ["chokidar@3.6.0", "", { "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", "normalize-path": "~3.0.0", "readdirp": "~3.6.0" }, "optionalDependencies": { "fsevents": "~2.3.2" } }, "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw=="],
|
|
72
75
|
|
|
76
|
+
"cli-cursor": ["cli-cursor@5.0.0", "", { "dependencies": { "restore-cursor": "^5.0.0" } }, "sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw=="],
|
|
77
|
+
|
|
78
|
+
"cli-spinners": ["cli-spinners@3.3.0", "", {}, "sha512-/+40ljC3ONVnYIttjMWrlL51nItDAbBrq2upN8BPyvGU/2n5Oxw3tbNwORCaNuNqLJnxGqOfjUuhsv7l5Q4IsQ=="],
|
|
79
|
+
|
|
73
80
|
"colorette": ["colorette@2.0.19", "", {}, "sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ=="],
|
|
74
81
|
|
|
75
|
-
"commander": ["commander@
|
|
82
|
+
"commander": ["commander@14.0.1", "", {}, "sha512-2JkV3gUZUVrbNA+1sjBOYLsMZ5cEEl8GTFP2a4AVz5hvasAMCQ1D2l2le/cX+pV4N6ZU17zjUahLpIXRrnWL8A=="],
|
|
76
83
|
|
|
77
84
|
"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
|
|
78
85
|
|
|
@@ -104,6 +111,8 @@
|
|
|
104
111
|
|
|
105
112
|
"function-bind": ["function-bind@1.1.2", "", {}, "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="],
|
|
106
113
|
|
|
114
|
+
"get-east-asian-width": ["get-east-asian-width@1.4.0", "", {}, "sha512-QZjmEOC+IT1uk6Rx0sX22V6uHWVwbdbxf1faPqJ1QhLdGgsRGCZoyaQBm/piRdJy/D2um6hM1UP7ZEeQ4EkP+Q=="],
|
|
115
|
+
|
|
107
116
|
"get-package-type": ["get-package-type@0.1.0", "", {}, "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q=="],
|
|
108
117
|
|
|
109
118
|
"get-tsconfig": ["get-tsconfig@4.12.0", "", { "dependencies": { "resolve-pkg-maps": "^1.0.0" } }, "sha512-LScr2aNr2FbjAjZh2C6X6BxRx1/x+aTDExct/xyq2XKbYOiG5c0aK7pMsSuyc0brz3ibr/lbQiHD9jzt4lccJw=="],
|
|
@@ -128,20 +137,28 @@
|
|
|
128
137
|
|
|
129
138
|
"is-glob": ["is-glob@4.0.3", "", { "dependencies": { "is-extglob": "^2.1.1" } }, "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg=="],
|
|
130
139
|
|
|
140
|
+
"is-interactive": ["is-interactive@2.0.0", "", {}, "sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ=="],
|
|
141
|
+
|
|
131
142
|
"is-number": ["is-number@7.0.0", "", {}, "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="],
|
|
132
143
|
|
|
144
|
+
"is-unicode-supported": ["is-unicode-supported@2.1.0", "", {}, "sha512-mE00Gnza5EEB3Ds0HfMyllZzbBrmLOX3vfWoj9A9PEnTfratQ/BcaJOuMhnkhjXvb2+FkY3VuHqtAGpTPmglFQ=="],
|
|
145
|
+
|
|
133
146
|
"json-schema-traverse": ["json-schema-traverse@1.0.0", "", {}, "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="],
|
|
134
147
|
|
|
135
148
|
"knex": ["knex@3.1.0", "", { "dependencies": { "colorette": "2.0.19", "commander": "^10.0.0", "debug": "4.3.4", "escalade": "^3.1.1", "esm": "^3.2.25", "get-package-type": "^0.1.0", "getopts": "2.3.0", "interpret": "^2.2.0", "lodash": "^4.17.21", "pg-connection-string": "2.6.2", "rechoir": "^0.8.0", "resolve-from": "^5.0.0", "tarn": "^3.0.2", "tildify": "2.0.0" }, "bin": { "knex": "bin/cli.js" } }, "sha512-GLoII6hR0c4ti243gMs5/1Rb3B+AjwMOfjYm97pu0FOQa7JH56hgBxYf5WK2525ceSbBY1cjeZ9yk99GPMB6Kw=="],
|
|
136
149
|
|
|
137
150
|
"lodash": ["lodash@4.17.21", "", {}, "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="],
|
|
138
151
|
|
|
152
|
+
"log-symbols": ["log-symbols@7.0.1", "", { "dependencies": { "is-unicode-supported": "^2.0.0", "yoctocolors": "^2.1.1" } }, "sha512-ja1E3yCr9i/0hmBVaM0bfwDjnGy8I/s6PP4DFp+yP+a+mrHO4Rm7DtmnqROTUkHIkqffC84YY7AeqX6oFk0WFg=="],
|
|
153
|
+
|
|
139
154
|
"luxon": ["luxon@3.7.2", "", {}, "sha512-vtEhXh/gNjI9Yg1u4jX/0YVPMvxzHuGgCm6tC5kZyb08yjGWGnqAjGJvcXbqQR2P3MyMEFnRbpcdFS6PBcLqew=="],
|
|
140
155
|
|
|
141
156
|
"merge2": ["merge2@1.4.1", "", {}, "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg=="],
|
|
142
157
|
|
|
143
158
|
"micromatch": ["micromatch@4.0.8", "", { "dependencies": { "braces": "^3.0.3", "picomatch": "^2.3.1" } }, "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA=="],
|
|
144
159
|
|
|
160
|
+
"mimic-function": ["mimic-function@5.0.1", "", {}, "sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA=="],
|
|
161
|
+
|
|
145
162
|
"ms": ["ms@2.1.2", "", {}, "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="],
|
|
146
163
|
|
|
147
164
|
"mylas": ["mylas@2.1.13", "", {}, "sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg=="],
|
|
@@ -152,6 +169,10 @@
|
|
|
152
169
|
|
|
153
170
|
"objection": ["objection@3.1.5", "", { "dependencies": { "ajv": "^8.17.1", "ajv-formats": "^2.1.1", "db-errors": "^0.2.3" }, "peerDependencies": { "knex": ">=1.0.1" } }, "sha512-Hx/ipAwXSuRBbOMWFKtRsAN0yITafqXtWB4OT4Z9wED7ty1h7bOnBdhLtcNus23GwLJqcMsRWdodL2p5GwlnfQ=="],
|
|
154
171
|
|
|
172
|
+
"onetime": ["onetime@7.0.0", "", { "dependencies": { "mimic-function": "^5.0.0" } }, "sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ=="],
|
|
173
|
+
|
|
174
|
+
"ora": ["ora@9.0.0", "", { "dependencies": { "chalk": "^5.6.2", "cli-cursor": "^5.0.0", "cli-spinners": "^3.2.0", "is-interactive": "^2.0.0", "is-unicode-supported": "^2.1.0", "log-symbols": "^7.0.1", "stdin-discarder": "^0.2.2", "string-width": "^8.1.0", "strip-ansi": "^7.1.2" } }, "sha512-m0pg2zscbYgWbqRR6ABga5c3sZdEon7bSgjnlXC64kxtxLOyjRcbbUkLj7HFyy/FTD+P2xdBWu8snGhYI0jc4A=="],
|
|
175
|
+
|
|
155
176
|
"path-parse": ["path-parse@1.0.7", "", {}, "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw=="],
|
|
156
177
|
|
|
157
178
|
"path-type": ["path-type@4.0.0", "", {}, "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw=="],
|
|
@@ -200,14 +221,24 @@
|
|
|
200
221
|
|
|
201
222
|
"resolve-pkg-maps": ["resolve-pkg-maps@1.0.0", "", {}, "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw=="],
|
|
202
223
|
|
|
224
|
+
"restore-cursor": ["restore-cursor@5.1.0", "", { "dependencies": { "onetime": "^7.0.0", "signal-exit": "^4.1.0" } }, "sha512-oMA2dcrw6u0YfxJQXm342bFKX/E4sG9rbTzO9ptUcR/e8A33cHuvStiYOwH7fszkZlZ1z/ta9AAoPk2F4qIOHA=="],
|
|
225
|
+
|
|
203
226
|
"reusify": ["reusify@1.1.0", "", {}, "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw=="],
|
|
204
227
|
|
|
205
228
|
"run-parallel": ["run-parallel@1.2.0", "", { "dependencies": { "queue-microtask": "^1.2.2" } }, "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA=="],
|
|
206
229
|
|
|
230
|
+
"signal-exit": ["signal-exit@4.1.0", "", {}, "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw=="],
|
|
231
|
+
|
|
207
232
|
"slash": ["slash@3.0.0", "", {}, "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q=="],
|
|
208
233
|
|
|
209
234
|
"split2": ["split2@4.2.0", "", {}, "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg=="],
|
|
210
235
|
|
|
236
|
+
"stdin-discarder": ["stdin-discarder@0.2.2", "", {}, "sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ=="],
|
|
237
|
+
|
|
238
|
+
"string-width": ["string-width@8.1.0", "", { "dependencies": { "get-east-asian-width": "^1.3.0", "strip-ansi": "^7.1.0" } }, "sha512-Kxl3KJGb/gxkaUMOjRsQ8IrXiGW75O4E3RPjFIINOVH8AMl2SQ/yWdTzWwF3FevIX9LcMAjJW+GRwAlAbTSXdg=="],
|
|
239
|
+
|
|
240
|
+
"strip-ansi": ["strip-ansi@7.1.2", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA=="],
|
|
241
|
+
|
|
211
242
|
"supports-preserve-symlinks-flag": ["supports-preserve-symlinks-flag@1.0.0", "", {}, "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w=="],
|
|
212
243
|
|
|
213
244
|
"tarn": ["tarn@3.0.2", "", {}, "sha512-51LAVKUSZSVfI05vjPESNc5vwqqZpbXCsU+/+wxlOrUjk2SnFTt97v9ZgQrD4YmxYW1Px6w2KjaDitCfkvgxMQ=="],
|
|
@@ -224,8 +255,12 @@
|
|
|
224
255
|
|
|
225
256
|
"xtend": ["xtend@4.0.2", "", {}, "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="],
|
|
226
257
|
|
|
258
|
+
"yoctocolors": ["yoctocolors@2.1.2", "", {}, "sha512-CzhO+pFNo8ajLM2d2IW/R93ipy99LWjtwblvC1RsoSUMZgyLbYFr221TnSNT7GjGdYui6P459mw9JH/g/zW2ug=="],
|
|
259
|
+
|
|
227
260
|
"knex/commander": ["commander@10.0.1", "", {}, "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug=="],
|
|
228
261
|
|
|
229
262
|
"pg/pg-connection-string": ["pg-connection-string@2.9.1", "", {}, "sha512-nkc6NpDcvPVpZXxrreI/FOtX3XemeLl8E0qFr6F2Lrm/I8WOnaWNhIPK2Z7OHpw7gh5XJThi6j6ppgNoaT1w4w=="],
|
|
263
|
+
|
|
264
|
+
"tsc-alias/commander": ["commander@9.5.0", "", {}, "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ=="],
|
|
230
265
|
}
|
|
231
266
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default class DbSeedCommand {
|
|
2
|
+
/**
|
|
3
|
+
* The name and signature of the console command.
|
|
4
|
+
*
|
|
5
|
+
* @var $signature string
|
|
6
|
+
*/
|
|
7
|
+
protected $signature: string;
|
|
8
|
+
/**
|
|
9
|
+
* The console command description.
|
|
10
|
+
*
|
|
11
|
+
* @var $description string
|
|
12
|
+
*/
|
|
13
|
+
protected $description: string;
|
|
14
|
+
/**
|
|
15
|
+
* The options or optional flag of the console command.
|
|
16
|
+
*
|
|
17
|
+
* @var $options Array<Array<string>>
|
|
18
|
+
*/
|
|
19
|
+
protected $options: Array<Array<string>>;
|
|
20
|
+
/**
|
|
21
|
+
* The arguments of the console command.
|
|
22
|
+
*
|
|
23
|
+
* @var $arguments Array<Array<string>>
|
|
24
|
+
*/
|
|
25
|
+
protected $arguments: Array<Array<string>>;
|
|
26
|
+
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { initDatabase } from "../config/database";
|
|
5
|
+
export default class DbSeedCommand {
|
|
6
|
+
/**
|
|
7
|
+
* The name and signature of the console command.
|
|
8
|
+
*
|
|
9
|
+
* @var $signature string
|
|
10
|
+
*/
|
|
11
|
+
$signature = "db:seed";
|
|
12
|
+
/**
|
|
13
|
+
* The console command description.
|
|
14
|
+
*
|
|
15
|
+
* @var $description string
|
|
16
|
+
*/
|
|
17
|
+
$description = "Run database seeders";
|
|
18
|
+
/**
|
|
19
|
+
* The options or optional flag of the console command.
|
|
20
|
+
*
|
|
21
|
+
* @var $options Array<Array<string>>
|
|
22
|
+
*/
|
|
23
|
+
$options = [];
|
|
24
|
+
/**
|
|
25
|
+
* The arguments of the console command.
|
|
26
|
+
*
|
|
27
|
+
* @var $arguments Array<Array<string>>
|
|
28
|
+
*/
|
|
29
|
+
$arguments = [];
|
|
30
|
+
async handle(options, args) {
|
|
31
|
+
const database = initDatabase();
|
|
32
|
+
const spinner = ora(Chalk.setValue("Seeding...")
|
|
33
|
+
.info()
|
|
34
|
+
.show()).start();
|
|
35
|
+
try {
|
|
36
|
+
const logs = (await database.seed.run()).flat();
|
|
37
|
+
spinner.succeed("Seeding finished");
|
|
38
|
+
if (logs.length > 0)
|
|
39
|
+
logs.forEach((seeder) => spinner.succeed(path.basename(seeder)));
|
|
40
|
+
else
|
|
41
|
+
spinner.succeed("No seeders were run.");
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
spinner.fail(`Seeding failed : ${error.message}`);
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
await database.destroy();
|
|
48
|
+
spinner.stop();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { defineValue, isEmpty } from "@bejibun/utils";
|
|
2
|
+
import { readdirSync } from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
export default class Kernel {
|
|
5
|
+
static registerCommands(program) {
|
|
6
|
+
const commandsDir = path.resolve(__dirname);
|
|
7
|
+
const files = readdirSync(commandsDir).filter((file) => {
|
|
8
|
+
return (/\.(m?js|ts)$/.test(file) &&
|
|
9
|
+
!file.endsWith(".d.ts") &&
|
|
10
|
+
!file.includes("Kernel"));
|
|
11
|
+
});
|
|
12
|
+
for (const file of files) {
|
|
13
|
+
const modulePath = path.join(commandsDir, file);
|
|
14
|
+
const { default: CommandClass } = require(modulePath);
|
|
15
|
+
const instance = new CommandClass();
|
|
16
|
+
if (isEmpty(instance.$signature) || typeof instance.handle !== "function")
|
|
17
|
+
continue;
|
|
18
|
+
const cmd = program
|
|
19
|
+
.command(instance.$signature)
|
|
20
|
+
.description(defineValue(instance.$description, ""))
|
|
21
|
+
.action(instance.handle);
|
|
22
|
+
if (Array.isArray(instance.$options)) {
|
|
23
|
+
for (const option of instance.$options) {
|
|
24
|
+
cmd.option(...option);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(instance.$arguments)) {
|
|
28
|
+
for (const argument of instance.$arguments) {
|
|
29
|
+
cmd.argument(...argument);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
cmd.action(async (...args) => {
|
|
33
|
+
const lastArg = args[args.length - 1];
|
|
34
|
+
const options = defineValue(lastArg, {});
|
|
35
|
+
await instance.handle(options, args.slice(0, -1));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default class MigrateFreshCommand {
|
|
2
|
+
/**
|
|
3
|
+
* The name and signature of the console command.
|
|
4
|
+
*
|
|
5
|
+
* @var $signature string
|
|
6
|
+
*/
|
|
7
|
+
protected $signature: string;
|
|
8
|
+
/**
|
|
9
|
+
* The console command description.
|
|
10
|
+
*
|
|
11
|
+
* @var $description string
|
|
12
|
+
*/
|
|
13
|
+
protected $description: string;
|
|
14
|
+
/**
|
|
15
|
+
* The options or optional flag of the console command.
|
|
16
|
+
*
|
|
17
|
+
* @var $options Array<Array<string>>
|
|
18
|
+
*/
|
|
19
|
+
protected $options: Array<Array<string>>;
|
|
20
|
+
/**
|
|
21
|
+
* The arguments of the console command.
|
|
22
|
+
*
|
|
23
|
+
* @var $arguments Array<Array<string>>
|
|
24
|
+
*/
|
|
25
|
+
protected $arguments: Array<Array<string>>;
|
|
26
|
+
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
+
import { ask, isNotEmpty } from "@bejibun/utils";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { initDatabase } from "../config/database";
|
|
5
|
+
export default class MigrateFreshCommand {
|
|
6
|
+
/**
|
|
7
|
+
* The name and signature of the console command.
|
|
8
|
+
*
|
|
9
|
+
* @var $signature string
|
|
10
|
+
*/
|
|
11
|
+
$signature = "migrate:fresh";
|
|
12
|
+
/**
|
|
13
|
+
* The console command description.
|
|
14
|
+
*
|
|
15
|
+
* @var $description string
|
|
16
|
+
*/
|
|
17
|
+
$description = "Rollback all migrations and re-run migrations";
|
|
18
|
+
/**
|
|
19
|
+
* The options or optional flag of the console command.
|
|
20
|
+
*
|
|
21
|
+
* @var $options Array<Array<string>>
|
|
22
|
+
*/
|
|
23
|
+
$options = [
|
|
24
|
+
["-f, --force", "Skip command confirmation."]
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* The arguments of the console command.
|
|
28
|
+
*
|
|
29
|
+
* @var $arguments Array<Array<string>>
|
|
30
|
+
*/
|
|
31
|
+
$arguments = [];
|
|
32
|
+
async handle(options, args) {
|
|
33
|
+
const database = initDatabase();
|
|
34
|
+
const bypass = isNotEmpty(options.force);
|
|
35
|
+
let confirm = "Y";
|
|
36
|
+
if (!bypass)
|
|
37
|
+
confirm = await ask(Chalk.setValue("This will DROP ALL tables and re-run ALL migrations. Are you want to continue? (Y/N): ")
|
|
38
|
+
.inline()
|
|
39
|
+
.error()
|
|
40
|
+
.show());
|
|
41
|
+
if (confirm.toUpperCase() === "Y") {
|
|
42
|
+
if (!bypass)
|
|
43
|
+
console.log();
|
|
44
|
+
const spinner = ora(Chalk.setValue("Rollback...")
|
|
45
|
+
.info()
|
|
46
|
+
.show()).start();
|
|
47
|
+
try {
|
|
48
|
+
await database.migrate.rollback({}, true);
|
|
49
|
+
spinner.succeed("Rolled back all migrations");
|
|
50
|
+
const [batchNo, logs] = await database.migrate.latest();
|
|
51
|
+
spinner.succeed(`Batch ${batchNo} finished`);
|
|
52
|
+
if (logs.length > 0)
|
|
53
|
+
logs.forEach((migration) => spinner.succeed(migration));
|
|
54
|
+
else
|
|
55
|
+
spinner.succeed("No migrations were run.");
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
spinner.fail(`Migration failed : ${error.message}`);
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
await database.destroy();
|
|
62
|
+
spinner.stop();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default class MigrateLatestCommand {
|
|
2
|
+
/**
|
|
3
|
+
* The name and signature of the console command.
|
|
4
|
+
*
|
|
5
|
+
* @var $signature string
|
|
6
|
+
*/
|
|
7
|
+
protected $signature: string;
|
|
8
|
+
/**
|
|
9
|
+
* The console command description.
|
|
10
|
+
*
|
|
11
|
+
* @var $description string
|
|
12
|
+
*/
|
|
13
|
+
protected $description: string;
|
|
14
|
+
/**
|
|
15
|
+
* The options or optional flag of the console command.
|
|
16
|
+
*
|
|
17
|
+
* @var $options Array<Array<string>>
|
|
18
|
+
*/
|
|
19
|
+
protected $options: Array<Array<string>>;
|
|
20
|
+
/**
|
|
21
|
+
* The arguments of the console command.
|
|
22
|
+
*
|
|
23
|
+
* @var $arguments Array<Array<string>>
|
|
24
|
+
*/
|
|
25
|
+
protected $arguments: Array<Array<string>>;
|
|
26
|
+
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import { initDatabase } from "../config/database";
|
|
4
|
+
export default class MigrateLatestCommand {
|
|
5
|
+
/**
|
|
6
|
+
* The name and signature of the console command.
|
|
7
|
+
*
|
|
8
|
+
* @var $signature string
|
|
9
|
+
*/
|
|
10
|
+
$signature = "migrate:latest";
|
|
11
|
+
/**
|
|
12
|
+
* The console command description.
|
|
13
|
+
*
|
|
14
|
+
* @var $description string
|
|
15
|
+
*/
|
|
16
|
+
$description = "Run latest migration";
|
|
17
|
+
/**
|
|
18
|
+
* The options or optional flag of the console command.
|
|
19
|
+
*
|
|
20
|
+
* @var $options Array<Array<string>>
|
|
21
|
+
*/
|
|
22
|
+
$options = [];
|
|
23
|
+
/**
|
|
24
|
+
* The arguments of the console command.
|
|
25
|
+
*
|
|
26
|
+
* @var $arguments Array<Array<string>>
|
|
27
|
+
*/
|
|
28
|
+
$arguments = [];
|
|
29
|
+
async handle(options, args) {
|
|
30
|
+
const database = initDatabase();
|
|
31
|
+
const spinner = ora(Chalk.setValue("Migrating...")
|
|
32
|
+
.info()
|
|
33
|
+
.show()).start();
|
|
34
|
+
try {
|
|
35
|
+
const [batchNo, logs] = await database.migrate.latest();
|
|
36
|
+
spinner.succeed(`Batch ${batchNo} finished`);
|
|
37
|
+
if (logs.length > 0)
|
|
38
|
+
logs.forEach((migration) => spinner.succeed(migration));
|
|
39
|
+
else
|
|
40
|
+
spinner.succeed("No migrations were run.");
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
spinner.fail(`Migration failed : ${error.message}`);
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
await database.destroy();
|
|
47
|
+
spinner.stop();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default class MigrateRollbackCommand {
|
|
2
|
+
/**
|
|
3
|
+
* The name and signature of the console command.
|
|
4
|
+
*
|
|
5
|
+
* @var $signature string
|
|
6
|
+
*/
|
|
7
|
+
protected $signature: string;
|
|
8
|
+
/**
|
|
9
|
+
* The console command description.
|
|
10
|
+
*
|
|
11
|
+
* @var $description string
|
|
12
|
+
*/
|
|
13
|
+
protected $description: string;
|
|
14
|
+
/**
|
|
15
|
+
* The options or optional flag of the console command.
|
|
16
|
+
*
|
|
17
|
+
* @var $options Array<Array<string>>
|
|
18
|
+
*/
|
|
19
|
+
protected $options: Array<Array<string>>;
|
|
20
|
+
/**
|
|
21
|
+
* The arguments of the console command.
|
|
22
|
+
*
|
|
23
|
+
* @var $arguments Array<Array<string>>
|
|
24
|
+
*/
|
|
25
|
+
protected $arguments: Array<Array<string>>;
|
|
26
|
+
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
+
import { ask, isNotEmpty } from "@bejibun/utils";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { initDatabase } from "../config/database";
|
|
5
|
+
export default class MigrateRollbackCommand {
|
|
6
|
+
/**
|
|
7
|
+
* The name and signature of the console command.
|
|
8
|
+
*
|
|
9
|
+
* @var $signature string
|
|
10
|
+
*/
|
|
11
|
+
$signature = "migrate:rollback";
|
|
12
|
+
/**
|
|
13
|
+
* The console command description.
|
|
14
|
+
*
|
|
15
|
+
* @var $description string
|
|
16
|
+
*/
|
|
17
|
+
$description = "Rollback the latest migrations";
|
|
18
|
+
/**
|
|
19
|
+
* The options or optional flag of the console command.
|
|
20
|
+
*
|
|
21
|
+
* @var $options Array<Array<string>>
|
|
22
|
+
*/
|
|
23
|
+
$options = [
|
|
24
|
+
["-f, --force", "Skip command confirmation."]
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* The arguments of the console command.
|
|
28
|
+
*
|
|
29
|
+
* @var $arguments Array<Array<string>>
|
|
30
|
+
*/
|
|
31
|
+
$arguments = [];
|
|
32
|
+
async handle(options, args) {
|
|
33
|
+
const database = initDatabase();
|
|
34
|
+
const bypass = isNotEmpty(options.force);
|
|
35
|
+
let confirm = "Y";
|
|
36
|
+
if (!bypass)
|
|
37
|
+
confirm = await ask(Chalk.setValue("This will ROLLBACK latest migrations. Are you want to continue? (Y/N): ")
|
|
38
|
+
.inline()
|
|
39
|
+
.error()
|
|
40
|
+
.show());
|
|
41
|
+
if (confirm.toUpperCase() === "Y") {
|
|
42
|
+
if (!bypass)
|
|
43
|
+
console.log();
|
|
44
|
+
const spinner = ora(Chalk.setValue("Rollback...")
|
|
45
|
+
.info()
|
|
46
|
+
.show()).start();
|
|
47
|
+
try {
|
|
48
|
+
const [batchNo, logs] = await database.migrate.rollback();
|
|
49
|
+
spinner.succeed(`Batch ${batchNo} finished`);
|
|
50
|
+
if (logs.length > 0)
|
|
51
|
+
logs.forEach((migration) => spinner.succeed(migration));
|
|
52
|
+
else
|
|
53
|
+
spinner.succeed("No migrations were rolled back.");
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
spinner.fail(`Rollback failed : ${error.message}`);
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
await database.destroy();
|
|
60
|
+
spinner.stop();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default class MigrateStatusCommand {
|
|
2
|
+
/**
|
|
3
|
+
* The name and signature of the console command.
|
|
4
|
+
*
|
|
5
|
+
* @var $signature string
|
|
6
|
+
*/
|
|
7
|
+
protected $signature: string;
|
|
8
|
+
/**
|
|
9
|
+
* The console command description.
|
|
10
|
+
*
|
|
11
|
+
* @var $description string
|
|
12
|
+
*/
|
|
13
|
+
protected $description: string;
|
|
14
|
+
/**
|
|
15
|
+
* The options or optional flag of the console command.
|
|
16
|
+
*
|
|
17
|
+
* @var $options Array<Array<string>>
|
|
18
|
+
*/
|
|
19
|
+
protected $options: Array<Array<string>>;
|
|
20
|
+
/**
|
|
21
|
+
* The arguments of the console command.
|
|
22
|
+
*
|
|
23
|
+
* @var $arguments Array<Array<string>>
|
|
24
|
+
*/
|
|
25
|
+
protected $arguments: Array<Array<string>>;
|
|
26
|
+
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import { initDatabase } from "../config/database";
|
|
4
|
+
export default class MigrateStatusCommand {
|
|
5
|
+
/**
|
|
6
|
+
* The name and signature of the console command.
|
|
7
|
+
*
|
|
8
|
+
* @var $signature string
|
|
9
|
+
*/
|
|
10
|
+
$signature = "migrate:status";
|
|
11
|
+
/**
|
|
12
|
+
* The console command description.
|
|
13
|
+
*
|
|
14
|
+
* @var $description string
|
|
15
|
+
*/
|
|
16
|
+
$description = "List migrations status";
|
|
17
|
+
/**
|
|
18
|
+
* The options or optional flag of the console command.
|
|
19
|
+
*
|
|
20
|
+
* @var $options Array<Array<string>>
|
|
21
|
+
*/
|
|
22
|
+
$options = [
|
|
23
|
+
["-f, --force", "Skip command confirmation."]
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* The arguments of the console command.
|
|
27
|
+
*
|
|
28
|
+
* @var $arguments Array<Array<string>>
|
|
29
|
+
*/
|
|
30
|
+
$arguments = [];
|
|
31
|
+
async handle(options, args) {
|
|
32
|
+
const database = initDatabase();
|
|
33
|
+
const spinner = ora(Chalk.setValue("Fetching...")
|
|
34
|
+
.info()
|
|
35
|
+
.show()).start();
|
|
36
|
+
try {
|
|
37
|
+
const [completed, pending] = await database.migrate.list();
|
|
38
|
+
spinner.succeed("Completed Migrations :");
|
|
39
|
+
if (completed.length > 0)
|
|
40
|
+
completed.forEach((migration) => spinner.succeed(migration.name));
|
|
41
|
+
else
|
|
42
|
+
spinner.succeed("No migrations were completed.");
|
|
43
|
+
console.log();
|
|
44
|
+
spinner.succeed("Pending Migrations :");
|
|
45
|
+
if (pending.length > 0)
|
|
46
|
+
pending.forEach((migration) => spinner.succeed(migration.file));
|
|
47
|
+
else
|
|
48
|
+
spinner.succeed("No migrations were pending.");
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
spinner.fail(`Fetching failed : ${error.message}`);
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
await database.destroy();
|
|
55
|
+
spinner.stop();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
package/config/database.d.ts
CHANGED
package/config/database.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import knex from "knex";
|
|
3
|
+
import path from "path";
|
|
1
4
|
const config = {
|
|
2
5
|
client: "pg",
|
|
3
6
|
connection: {
|
|
@@ -21,4 +24,13 @@ const config = {
|
|
|
21
24
|
directory: "./database/seeders"
|
|
22
25
|
}
|
|
23
26
|
};
|
|
27
|
+
export const initDatabase = () => {
|
|
28
|
+
const configPath = path.resolve(process.cwd(), "config/database.ts");
|
|
29
|
+
let _config;
|
|
30
|
+
if (fs.existsSync(configPath))
|
|
31
|
+
_config = require(configPath).default;
|
|
32
|
+
else
|
|
33
|
+
_config = config;
|
|
34
|
+
return knex(_config);
|
|
35
|
+
};
|
|
24
36
|
export default config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bejibun/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.39",
|
|
4
4
|
"author": "Havea Crenata <havea.crenata@gmail.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,14 +9,15 @@
|
|
|
9
9
|
"main": "index.js",
|
|
10
10
|
"module": "index.js",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@bejibun/cors": "^0.1.
|
|
13
|
-
"@bejibun/logger": "^0.1.
|
|
14
|
-
"@bejibun/utils": "^0.1.
|
|
12
|
+
"@bejibun/cors": "^0.1.1",
|
|
13
|
+
"@bejibun/logger": "^0.1.14",
|
|
14
|
+
"@bejibun/utils": "^0.1.1",
|
|
15
15
|
"@vinejs/vine": "^3.0.1",
|
|
16
|
-
"
|
|
16
|
+
"commander": "^14.0.1",
|
|
17
17
|
"knex": "^3.1.0",
|
|
18
18
|
"luxon": "^3.7.2",
|
|
19
19
|
"objection": "^3.1.5",
|
|
20
|
+
"ora": "^9.0.0",
|
|
20
21
|
"pg": "^8.16.3"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
package/src/ace.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Str from "@bejibun/utils/facades/Str";
|
|
2
|
+
import {program} from "commander";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import Kernel from "@/commands/Kernel";
|
|
5
|
+
import {version} from "package.json";
|
|
6
|
+
|
|
7
|
+
const commandExec = "ace";
|
|
8
|
+
|
|
9
|
+
program
|
|
10
|
+
.name(commandExec)
|
|
11
|
+
.version(version, "-v, --version", "Show the current version")
|
|
12
|
+
.description(`${Str.toPascalCase(commandExec)} for your commander${os.EOL}Author: Havea Crenata <havea.crenata@gmail.com>`)
|
|
13
|
+
.addHelpText("after", [
|
|
14
|
+
`${os.EOL}Examples:`,
|
|
15
|
+
`$ bun ${commandExec} --help`,
|
|
16
|
+
`$ bun ${commandExec} --version`,
|
|
17
|
+
`$ bun ${commandExec} migrate:latest`
|
|
18
|
+
].join(`${os.EOL} `));
|
|
19
|
+
|
|
20
|
+
Kernel.registerCommands(program);
|
|
21
|
+
|
|
22
|
+
program.parse();
|
package/src/bases/BaseModel.ts
CHANGED
package/src/bootstrap.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
+
import {Model} from "objection";
|
|
1
2
|
import BaseModel from "@/bases/BaseModel";
|
|
2
|
-
import
|
|
3
|
-
import knex from "knex";
|
|
4
|
-
import path from "path";
|
|
3
|
+
import {initDatabase} from "@/config/database";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let config: any;
|
|
9
|
-
|
|
10
|
-
if (fs.existsSync(configPath)) config = require(configPath).default;
|
|
11
|
-
else config = require("@/config/database").default;
|
|
12
|
-
|
|
13
|
-
BaseModel.knex(knex(config));
|
|
5
|
+
(BaseModel as any as typeof Model).knex(initDatabase());
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import {initDatabase} from "@/config/database";
|
|
5
|
+
|
|
6
|
+
export default class DbSeedCommand {
|
|
7
|
+
/**
|
|
8
|
+
* The name and signature of the console command.
|
|
9
|
+
*
|
|
10
|
+
* @var $signature string
|
|
11
|
+
*/
|
|
12
|
+
protected $signature: string = "db:seed";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The console command description.
|
|
16
|
+
*
|
|
17
|
+
* @var $description string
|
|
18
|
+
*/
|
|
19
|
+
protected $description: string = "Run database seeders";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The options or optional flag of the console command.
|
|
23
|
+
*
|
|
24
|
+
* @var $options Array<Array<string>>
|
|
25
|
+
*/
|
|
26
|
+
protected $options: Array<Array<string>> = [];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The arguments of the console command.
|
|
30
|
+
*
|
|
31
|
+
* @var $arguments Array<Array<string>>
|
|
32
|
+
*/
|
|
33
|
+
protected $arguments: Array<Array<string>> = [];
|
|
34
|
+
|
|
35
|
+
public async handle(options: any, args: Array<string>): Promise<void> {
|
|
36
|
+
const database = initDatabase();
|
|
37
|
+
|
|
38
|
+
const spinner = ora(
|
|
39
|
+
Chalk.setValue("Seeding...")
|
|
40
|
+
.info()
|
|
41
|
+
.show()
|
|
42
|
+
).start();
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const logs = (await database.seed.run()).flat();
|
|
46
|
+
spinner.succeed("Seeding finished");
|
|
47
|
+
|
|
48
|
+
if (logs.length > 0) logs.forEach((seeder: string) => spinner.succeed(path.basename(seeder)));
|
|
49
|
+
else spinner.succeed("No seeders were run.");
|
|
50
|
+
} catch (error: any) {
|
|
51
|
+
spinner.fail(`Seeding failed : ${error.message}`);
|
|
52
|
+
} finally {
|
|
53
|
+
await database.destroy();
|
|
54
|
+
spinner.stop();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type {Command} from "commander";
|
|
2
|
+
import {defineValue, isEmpty} from "@bejibun/utils";
|
|
3
|
+
import {readdirSync} from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
|
|
6
|
+
export default class Kernel {
|
|
7
|
+
public static registerCommands(program: Command): void {
|
|
8
|
+
const commandsDir = path.resolve(__dirname);
|
|
9
|
+
const files = readdirSync(commandsDir).filter((file: string) => {
|
|
10
|
+
return (
|
|
11
|
+
/\.(m?js|ts)$/.test(file) &&
|
|
12
|
+
!file.endsWith(".d.ts") &&
|
|
13
|
+
!file.includes("Kernel")
|
|
14
|
+
)
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
for (const file of files) {
|
|
18
|
+
const modulePath = path.join(commandsDir, file);
|
|
19
|
+
const {default: CommandClass} = require(modulePath);
|
|
20
|
+
|
|
21
|
+
const instance = new CommandClass();
|
|
22
|
+
|
|
23
|
+
if (isEmpty(instance.$signature) || typeof instance.handle !== "function") continue;
|
|
24
|
+
|
|
25
|
+
const cmd = program
|
|
26
|
+
.command(instance.$signature)
|
|
27
|
+
.description(defineValue(instance.$description, ""))
|
|
28
|
+
.action(instance.handle);
|
|
29
|
+
|
|
30
|
+
if (Array.isArray(instance.$options)) {
|
|
31
|
+
for (const option of instance.$options) {
|
|
32
|
+
cmd.option(...(option as [string, string?, any?]));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (Array.isArray(instance.$arguments)) {
|
|
37
|
+
for (const argument of instance.$arguments) {
|
|
38
|
+
cmd.argument(...(argument as [string, string?, unknown?]));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
cmd.action(async (...args: any[]) => {
|
|
43
|
+
const lastArg = args[args.length - 1];
|
|
44
|
+
const options = defineValue(lastArg, {});
|
|
45
|
+
await instance.handle(options, args.slice(0, -1));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
+
import {ask, isNotEmpty} from "@bejibun/utils";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import {initDatabase} from "@/config/database";
|
|
5
|
+
|
|
6
|
+
export default class MigrateFreshCommand {
|
|
7
|
+
/**
|
|
8
|
+
* The name and signature of the console command.
|
|
9
|
+
*
|
|
10
|
+
* @var $signature string
|
|
11
|
+
*/
|
|
12
|
+
protected $signature: string = "migrate:fresh";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The console command description.
|
|
16
|
+
*
|
|
17
|
+
* @var $description string
|
|
18
|
+
*/
|
|
19
|
+
protected $description: string = "Rollback all migrations and re-run migrations";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The options or optional flag of the console command.
|
|
23
|
+
*
|
|
24
|
+
* @var $options Array<Array<string>>
|
|
25
|
+
*/
|
|
26
|
+
protected $options: Array<Array<string>> = [
|
|
27
|
+
["-f, --force", "Skip command confirmation."]
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The arguments of the console command.
|
|
32
|
+
*
|
|
33
|
+
* @var $arguments Array<Array<string>>
|
|
34
|
+
*/
|
|
35
|
+
protected $arguments: Array<Array<string>> = [];
|
|
36
|
+
|
|
37
|
+
public async handle(options: any, args: Array<string>): Promise<void> {
|
|
38
|
+
const database = initDatabase();
|
|
39
|
+
|
|
40
|
+
const bypass = isNotEmpty(options.force);
|
|
41
|
+
|
|
42
|
+
let confirm = "Y";
|
|
43
|
+
if (!bypass) confirm = await ask(
|
|
44
|
+
Chalk.setValue("This will DROP ALL tables and re-run ALL migrations. Are you want to continue? (Y/N): ")
|
|
45
|
+
.inline()
|
|
46
|
+
.error()
|
|
47
|
+
.show()
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (confirm.toUpperCase() === "Y") {
|
|
51
|
+
if (!bypass) console.log();
|
|
52
|
+
|
|
53
|
+
const spinner = ora(
|
|
54
|
+
Chalk.setValue("Rollback...")
|
|
55
|
+
.info()
|
|
56
|
+
.show()
|
|
57
|
+
).start();
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
await database.migrate.rollback({}, true);
|
|
61
|
+
spinner.succeed("Rolled back all migrations");
|
|
62
|
+
|
|
63
|
+
const [batchNo, logs] = await database.migrate.latest();
|
|
64
|
+
spinner.succeed(`Batch ${batchNo} finished`);
|
|
65
|
+
|
|
66
|
+
if (logs.length > 0) logs.forEach((migration: string) => spinner.succeed(migration));
|
|
67
|
+
else spinner.succeed("No migrations were run.");
|
|
68
|
+
} catch (error: any) {
|
|
69
|
+
spinner.fail(`Migration failed : ${error.message}`);
|
|
70
|
+
} finally {
|
|
71
|
+
await database.destroy();
|
|
72
|
+
spinner.stop();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import {initDatabase} from "@/config/database";
|
|
4
|
+
|
|
5
|
+
export default class MigrateLatestCommand {
|
|
6
|
+
/**
|
|
7
|
+
* The name and signature of the console command.
|
|
8
|
+
*
|
|
9
|
+
* @var $signature string
|
|
10
|
+
*/
|
|
11
|
+
protected $signature: string = "migrate:latest";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The console command description.
|
|
15
|
+
*
|
|
16
|
+
* @var $description string
|
|
17
|
+
*/
|
|
18
|
+
protected $description: string = "Run latest migration";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The options or optional flag of the console command.
|
|
22
|
+
*
|
|
23
|
+
* @var $options Array<Array<string>>
|
|
24
|
+
*/
|
|
25
|
+
protected $options: Array<Array<string>> = [];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The arguments of the console command.
|
|
29
|
+
*
|
|
30
|
+
* @var $arguments Array<Array<string>>
|
|
31
|
+
*/
|
|
32
|
+
protected $arguments: Array<Array<string>> = [];
|
|
33
|
+
|
|
34
|
+
public async handle(options: any, args: Array<string>): Promise<void> {
|
|
35
|
+
const database = initDatabase();
|
|
36
|
+
|
|
37
|
+
const spinner = ora(
|
|
38
|
+
Chalk.setValue("Migrating...")
|
|
39
|
+
.info()
|
|
40
|
+
.show()
|
|
41
|
+
).start();
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const [batchNo, logs] = await database.migrate.latest();
|
|
45
|
+
spinner.succeed(`Batch ${batchNo} finished`);
|
|
46
|
+
|
|
47
|
+
if (logs.length > 0) logs.forEach((migration: string) => spinner.succeed(migration));
|
|
48
|
+
else spinner.succeed("No migrations were run.");
|
|
49
|
+
} catch (error: any) {
|
|
50
|
+
spinner.fail(`Migration failed : ${error.message}`);
|
|
51
|
+
} finally {
|
|
52
|
+
await database.destroy();
|
|
53
|
+
spinner.stop();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
+
import {ask, isNotEmpty} from "@bejibun/utils";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import {initDatabase} from "@/config/database";
|
|
5
|
+
|
|
6
|
+
export default class MigrateRollbackCommand {
|
|
7
|
+
/**
|
|
8
|
+
* The name and signature of the console command.
|
|
9
|
+
*
|
|
10
|
+
* @var $signature string
|
|
11
|
+
*/
|
|
12
|
+
protected $signature: string = "migrate:rollback";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The console command description.
|
|
16
|
+
*
|
|
17
|
+
* @var $description string
|
|
18
|
+
*/
|
|
19
|
+
protected $description: string = "Rollback the latest migrations";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The options or optional flag of the console command.
|
|
23
|
+
*
|
|
24
|
+
* @var $options Array<Array<string>>
|
|
25
|
+
*/
|
|
26
|
+
protected $options: Array<Array<string>> = [
|
|
27
|
+
["-f, --force", "Skip command confirmation."]
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The arguments of the console command.
|
|
32
|
+
*
|
|
33
|
+
* @var $arguments Array<Array<string>>
|
|
34
|
+
*/
|
|
35
|
+
protected $arguments: Array<Array<string>> = [];
|
|
36
|
+
|
|
37
|
+
public async handle(options: any, args: Array<string>): Promise<void> {
|
|
38
|
+
const database = initDatabase();
|
|
39
|
+
|
|
40
|
+
const bypass = isNotEmpty(options.force);
|
|
41
|
+
|
|
42
|
+
let confirm = "Y";
|
|
43
|
+
if (!bypass) confirm = await ask(
|
|
44
|
+
Chalk.setValue("This will ROLLBACK latest migrations. Are you want to continue? (Y/N): ")
|
|
45
|
+
.inline()
|
|
46
|
+
.error()
|
|
47
|
+
.show()
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (confirm.toUpperCase() === "Y") {
|
|
51
|
+
if (!bypass) console.log();
|
|
52
|
+
|
|
53
|
+
const spinner = ora(
|
|
54
|
+
Chalk.setValue("Rollback...")
|
|
55
|
+
.info()
|
|
56
|
+
.show()
|
|
57
|
+
).start();
|
|
58
|
+
try {
|
|
59
|
+
const [batchNo, logs] = await database.migrate.rollback();
|
|
60
|
+
spinner.succeed(`Batch ${batchNo} finished`);
|
|
61
|
+
|
|
62
|
+
if (logs.length > 0) logs.forEach((migration: string) => spinner.succeed(migration));
|
|
63
|
+
else spinner.succeed("No migrations were rolled back.");
|
|
64
|
+
} catch (error: any) {
|
|
65
|
+
spinner.fail(`Rollback failed : ${error.message}`);
|
|
66
|
+
} finally {
|
|
67
|
+
await database.destroy();
|
|
68
|
+
spinner.stop();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import {initDatabase} from "@/config/database";
|
|
4
|
+
|
|
5
|
+
export default class MigrateStatusCommand {
|
|
6
|
+
/**
|
|
7
|
+
* The name and signature of the console command.
|
|
8
|
+
*
|
|
9
|
+
* @var $signature string
|
|
10
|
+
*/
|
|
11
|
+
protected $signature: string = "migrate:status";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The console command description.
|
|
15
|
+
*
|
|
16
|
+
* @var $description string
|
|
17
|
+
*/
|
|
18
|
+
protected $description: string = "List migrations status";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The options or optional flag of the console command.
|
|
22
|
+
*
|
|
23
|
+
* @var $options Array<Array<string>>
|
|
24
|
+
*/
|
|
25
|
+
protected $options: Array<Array<string>> = [
|
|
26
|
+
["-f, --force", "Skip command confirmation."]
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The arguments of the console command.
|
|
31
|
+
*
|
|
32
|
+
* @var $arguments Array<Array<string>>
|
|
33
|
+
*/
|
|
34
|
+
protected $arguments: Array<Array<string>> = [];
|
|
35
|
+
|
|
36
|
+
public async handle(options: any, args: Array<string>): Promise<void> {
|
|
37
|
+
const database = initDatabase();
|
|
38
|
+
|
|
39
|
+
const spinner = ora(
|
|
40
|
+
Chalk.setValue("Fetching...")
|
|
41
|
+
.info()
|
|
42
|
+
.show()
|
|
43
|
+
).start();
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const [completed, pending] = await database.migrate.list();
|
|
47
|
+
|
|
48
|
+
spinner.succeed("Completed Migrations :");
|
|
49
|
+
if (completed.length > 0) completed.forEach((migration: { name: string }) => spinner.succeed(migration.name));
|
|
50
|
+
else spinner.succeed("No migrations were completed.");
|
|
51
|
+
|
|
52
|
+
console.log();
|
|
53
|
+
|
|
54
|
+
spinner.succeed("Pending Migrations :");
|
|
55
|
+
if (pending.length > 0) pending.forEach((migration: { file: string, directory: string }) => spinner.succeed(migration.file));
|
|
56
|
+
else spinner.succeed("No migrations were pending.");
|
|
57
|
+
} catch (error: any) {
|
|
58
|
+
spinner.fail(`Fetching failed : ${error.message}`);
|
|
59
|
+
} finally {
|
|
60
|
+
await database.destroy();
|
|
61
|
+
spinner.stop();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/config/database.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type {Knex} from "knex";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import knex from "knex";
|
|
4
|
+
import path from "path";
|
|
2
5
|
|
|
3
6
|
const config: Knex.Config = {
|
|
4
7
|
client: "pg",
|
|
@@ -24,4 +27,15 @@ const config: Knex.Config = {
|
|
|
24
27
|
}
|
|
25
28
|
};
|
|
26
29
|
|
|
30
|
+
export const initDatabase = (): Knex => {
|
|
31
|
+
const configPath = path.resolve(process.cwd(), "config/database.ts");
|
|
32
|
+
|
|
33
|
+
let _config: any;
|
|
34
|
+
|
|
35
|
+
if (fs.existsSync(configPath)) _config = require(configPath).default;
|
|
36
|
+
else _config = config;
|
|
37
|
+
|
|
38
|
+
return knex(_config);
|
|
39
|
+
};
|
|
40
|
+
|
|
27
41
|
export default config;
|