@devbro/pashmak 0.1.9 → 0.1.11
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/dist/app/console/DefaultCommand.mjs +3 -1
- package/dist/app/console/DefaultCommand.mjs.map +1 -1
- package/dist/app/console/KeyGenerateCommand.mjs +19 -17
- package/dist/app/console/KeyGenerateCommand.mjs.map +1 -1
- package/dist/app/console/StartCommand.mjs +9 -13
- package/dist/app/console/StartCommand.mjs.map +1 -1
- package/dist/app/console/generate/GenerateControllerCommand.mjs +14 -17
- package/dist/app/console/generate/GenerateControllerCommand.mjs.map +1 -1
- package/dist/app/console/generate/index.mjs +1 -1
- package/dist/app/console/generate/index.mjs.map +1 -1
- package/dist/app/console/index.mjs +7 -7
- package/dist/app/console/index.mjs.map +1 -1
- package/dist/app/console/migrate/GenerateMigrateCommand.mjs +14 -17
- package/dist/app/console/migrate/GenerateMigrateCommand.mjs.map +1 -1
- package/dist/app/console/migrate/MigrateCommand.d.mts +1 -0
- package/dist/app/console/migrate/MigrateCommand.mjs +38 -26
- package/dist/app/console/migrate/MigrateCommand.mjs.map +1 -1
- package/dist/app/console/migrate/MigrateRollbackCommand.d.mts +1 -1
- package/dist/app/console/migrate/MigrateRollbackCommand.mjs +7 -15
- package/dist/app/console/migrate/MigrateRollbackCommand.mjs.map +1 -1
- package/dist/app/console/migrate/index.mjs +3 -3
- package/dist/app/console/migrate/index.mjs.map +1 -1
- package/dist/app/console/project/CreateProjectCommand.mjs +17 -23
- package/dist/app/console/project/CreateProjectCommand.mjs.map +1 -1
- package/dist/bin/app/console/DefaultCommand.cjs +99 -7
- package/dist/bin/app/console/KeyGenerateCommand.cjs +117 -25
- package/dist/bin/app/console/StartCommand.cjs +105 -19
- package/dist/bin/app/console/generate/GenerateControllerCommand.cjs +114 -27
- package/dist/bin/app/console/generate/index.cjs +114 -27
- package/dist/bin/app/console/index.cjs +241 -159
- package/dist/bin/app/console/migrate/GenerateMigrateCommand.cjs +113 -26
- package/dist/bin/app/console/migrate/MigrateCommand.cjs +136 -34
- package/dist/bin/app/console/migrate/MigrateRollbackCommand.cjs +105 -23
- package/dist/bin/app/console/migrate/index.cjs +164 -73
- package/dist/bin/app/console/project/CreateProjectCommand.cjs +21 -27
- package/dist/bin/bin/pashmak_cli.cjs +21 -27
- package/dist/bin/facades.cjs +94 -4
- package/dist/bin/index.cjs +257 -176
- package/dist/bin/middlewares.cjs +94 -4
- package/dist/bin/pashmak_cli.mjs +2 -2
- package/dist/bin/pashmak_cli.mjs.map +1 -1
- package/dist/bin/router.cjs +95 -5
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +2 -5
- package/dist/index.mjs.map +1 -1
- package/dist/router.mjs +1 -1
- package/dist/router.mjs.map +1 -1
- package/package.json +4 -3
|
@@ -19,7 +19,9 @@ class DefaultCommand extends Command {
|
|
|
19
19
|
async execute() {
|
|
20
20
|
const commandList = cli().registrations;
|
|
21
21
|
const paths = [];
|
|
22
|
-
commandList.forEach(
|
|
22
|
+
commandList.forEach(
|
|
23
|
+
(index, val) => paths.push(index.builder.paths[0]?.join(" ") || "")
|
|
24
|
+
);
|
|
23
25
|
console.log("Available commands:");
|
|
24
26
|
for (const cmd of paths) {
|
|
25
27
|
if (cmd) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/app/console/DefaultCommand.
|
|
1
|
+
{"version":3,"sources":["../../../src/app/console/DefaultCommand.mts"],"sourcesContent":["import { Command, Option } from \"clipanion\";\nimport { cli } from \"../../facades.mjs\";\n\nexport class DefaultCommand extends Command {\n static usage = Command.Usage({\n category: `Main`,\n description: `server management command line.`,\n details: `\n The base command for running and managing your server.\n\n Make sure you understand how things work.\n `,\n examples: [],\n });\n\n async execute() {\n // @ts-ignore\n const commandList = cli().registrations; //.definitions().map((def:any) => def.paths.map((path:any) => path.join(' '))).flat();\n\n const paths: string[] = [];\n commandList.forEach((index, val) =>\n paths.push(index.builder.paths[0]?.join(\" \") || \"\"),\n );\n\n console.log(\"Available commands:\");\n for (const cmd of paths) {\n if (cmd) {\n console.log(cmd);\n }\n }\n }\n}\n\ncli().register(DefaultCommand);\n"],"mappings":";;AAAA,SAAS,eAAuB;AAChC,SAAS,WAAW;AAEb,MAAM,uBAAuB,QAAQ;AAAA,EAH5C,OAG4C;AAAA;AAAA;AAAA,EAC1C,OAAO,QAAQ,QAAQ,MAAM;AAAA,IAC3B,UAAU;AAAA,IACV,aAAa;AAAA,IACb,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,IAKT,UAAU,CAAC;AAAA,EACb,CAAC;AAAA,EAED,MAAM,UAAU;AAEd,UAAM,cAAc,IAAI,EAAE;AAE1B,UAAM,QAAkB,CAAC;AACzB,gBAAY;AAAA,MAAQ,CAAC,OAAO,QAC1B,MAAM,KAAK,MAAM,QAAQ,MAAM,CAAC,GAAG,KAAK,GAAG,KAAK,EAAE;AAAA,IACpD;AAEA,YAAQ,IAAI,qBAAqB;AACjC,eAAW,OAAO,OAAO;AACvB,UAAI,KAAK;AACP,gBAAQ,IAAI,GAAG;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAI,EAAE,SAAS,cAAc;","names":[]}
|
|
@@ -9,12 +9,7 @@ class KeyGenerateCommand extends Command {
|
|
|
9
9
|
static {
|
|
10
10
|
__name(this, "KeyGenerateCommand");
|
|
11
11
|
}
|
|
12
|
-
static paths = [
|
|
13
|
-
[
|
|
14
|
-
`generate`,
|
|
15
|
-
"key"
|
|
16
|
-
]
|
|
17
|
-
];
|
|
12
|
+
static paths = [[`generate`, "key"]];
|
|
18
13
|
static usage = Command.Usage({
|
|
19
14
|
category: `Main`,
|
|
20
15
|
description: `generate keys`,
|
|
@@ -23,14 +18,8 @@ class KeyGenerateCommand extends Command {
|
|
|
23
18
|
Use --rotate flag to preserve old public key.
|
|
24
19
|
`,
|
|
25
20
|
examples: [
|
|
26
|
-
[
|
|
27
|
-
|
|
28
|
-
`generate key`
|
|
29
|
-
],
|
|
30
|
-
[
|
|
31
|
-
`Rotate existing keys`,
|
|
32
|
-
`generate key --rotate`
|
|
33
|
-
]
|
|
21
|
+
[`Generate new keys`, `generate key`],
|
|
22
|
+
[`Rotate existing keys`, `generate key --rotate`]
|
|
34
23
|
]
|
|
35
24
|
});
|
|
36
25
|
rotate = Option.Boolean(`--rotate`, false, {
|
|
@@ -40,6 +29,7 @@ class KeyGenerateCommand extends Command {
|
|
|
40
29
|
logger().info("generating keys for jwt token and adding to .env file");
|
|
41
30
|
const { publicKey, privateKey } = generateKeyPairSync("rsa", {
|
|
42
31
|
modulusLength: 2048,
|
|
32
|
+
// 2048-bit key is standard for RS256
|
|
43
33
|
publicKeyEncoding: {
|
|
44
34
|
type: "spki",
|
|
45
35
|
format: "pem"
|
|
@@ -55,10 +45,22 @@ class KeyGenerateCommand extends Command {
|
|
|
55
45
|
} catch {
|
|
56
46
|
}
|
|
57
47
|
let old_public_key = envfile.match(/^jwt_secret_public=(.*)/m);
|
|
58
|
-
envfile = this.addEnvParam(
|
|
59
|
-
|
|
48
|
+
envfile = this.addEnvParam(
|
|
49
|
+
envfile,
|
|
50
|
+
"jwt_secret_public",
|
|
51
|
+
this.stripPemHeaders(publicKey)
|
|
52
|
+
);
|
|
53
|
+
envfile = this.addEnvParam(
|
|
54
|
+
envfile,
|
|
55
|
+
"jwt_secret_private",
|
|
56
|
+
this.stripPemHeaders(privateKey)
|
|
57
|
+
);
|
|
60
58
|
if (this.rotate && old_public_key && old_public_key[1]) {
|
|
61
|
-
envfile = this.addEnvParam(
|
|
59
|
+
envfile = this.addEnvParam(
|
|
60
|
+
envfile,
|
|
61
|
+
"jwt_secret_public_retired",
|
|
62
|
+
old_public_key[1]
|
|
63
|
+
);
|
|
62
64
|
}
|
|
63
65
|
await fs.writeFile(path.join(process.cwd(), ".env"), envfile, "utf-8");
|
|
64
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/app/console/KeyGenerateCommand.
|
|
1
|
+
{"version":3,"sources":["../../../src/app/console/KeyGenerateCommand.mts"],"sourcesContent":["import { Command, Option } from \"clipanion\";\nimport { generateKeyPairSync } from \"crypto\";\nimport fs from \"fs/promises\";\nimport path from \"path\";\nimport { logger, cli } from \"../../facades.mjs\";\n\nexport class KeyGenerateCommand extends Command {\n static paths = [[`generate`, \"key\"]];\n\n static usage = Command.Usage({\n category: `Main`,\n description: `generate keys`,\n details: `\n This command generates RSA key pair for JWT signing.\n Use --rotate flag to preserve old public key.\n `,\n examples: [\n [`Generate new keys`, `generate key`],\n [`Rotate existing keys`, `generate key --rotate`],\n ],\n });\n\n rotate = Option.Boolean(`--rotate`, false, {\n description: `Rotate existing keys (backup old keys before replacement)`,\n });\n\n async execute() {\n logger().info(\"generating keys for jwt token and adding to .env file\");\n const { publicKey, privateKey } = generateKeyPairSync(\"rsa\", {\n modulusLength: 2048, // 2048-bit key is standard for RS256\n publicKeyEncoding: {\n type: \"spki\",\n format: \"pem\",\n },\n privateKeyEncoding: {\n type: \"pkcs8\",\n format: \"pem\",\n },\n });\n\n let envfile = \"\";\n try {\n envfile = await fs.readFile(path.join(process.cwd(), \".env\"), \"utf-8\");\n } catch {}\n let old_public_key = envfile.match(/^jwt_secret_public=(.*)/m);\n\n envfile = this.addEnvParam(\n envfile,\n \"jwt_secret_public\",\n this.stripPemHeaders(publicKey),\n );\n envfile = this.addEnvParam(\n envfile,\n \"jwt_secret_private\",\n this.stripPemHeaders(privateKey),\n );\n\n if (this.rotate && old_public_key && old_public_key[1]) {\n envfile = this.addEnvParam(\n envfile,\n \"jwt_secret_public_retired\",\n old_public_key[1],\n );\n }\n\n await fs.writeFile(path.join(process.cwd(), \".env\"), envfile, \"utf-8\");\n }\n\n addEnvParam(file: string, key: string, value: string) {\n let regex = new RegExp(`^${key}=.*`, \"gm\");\n file = file.replace(regex, `${key}=${value}`);\n const match = file.match(regex);\n\n if (!match) {\n file = file + `\\n${key}=${value}`;\n }\n return file;\n }\n\n stripPemHeaders(pem: string) {\n return pem\n .replace(/-----BEGIN [\\w\\s]+-----/g, \"\")\n .replace(/-----END [\\w\\s]+-----/g, \"\")\n .replace(/\\r?\\n|\\r/g, \"\");\n }\n}\n\ncli().register(KeyGenerateCommand);\n"],"mappings":";;AAAA,SAAS,SAAS,cAAc;AAChC,SAAS,2BAA2B;AACpC,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,QAAQ,WAAW;AAErB,MAAM,2BAA2B,QAAQ;AAAA,EANhD,OAMgD;AAAA;AAAA;AAAA,EAC9C,OAAO,QAAQ,CAAC,CAAC,YAAY,KAAK,CAAC;AAAA,EAEnC,OAAO,QAAQ,QAAQ,MAAM;AAAA,IAC3B,UAAU;AAAA,IACV,aAAa;AAAA,IACb,SAAS;AAAA;AAAA;AAAA;AAAA,IAIT,UAAU;AAAA,MACR,CAAC,qBAAqB,cAAc;AAAA,MACpC,CAAC,wBAAwB,uBAAuB;AAAA,IAClD;AAAA,EACF,CAAC;AAAA,EAED,SAAS,OAAO,QAAQ,YAAY,OAAO;AAAA,IACzC,aAAa;AAAA,EACf,CAAC;AAAA,EAED,MAAM,UAAU;AACd,WAAO,EAAE,KAAK,uDAAuD;AACrE,UAAM,EAAE,WAAW,WAAW,IAAI,oBAAoB,OAAO;AAAA,MAC3D,eAAe;AAAA;AAAA,MACf,mBAAmB;AAAA,QACjB,MAAM;AAAA,QACN,QAAQ;AAAA,MACV;AAAA,MACA,oBAAoB;AAAA,QAClB,MAAM;AAAA,QACN,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAED,QAAI,UAAU;AACd,QAAI;AACF,gBAAU,MAAM,GAAG,SAAS,KAAK,KAAK,QAAQ,IAAI,GAAG,MAAM,GAAG,OAAO;AAAA,IACvE,QAAQ;AAAA,IAAC;AACT,QAAI,iBAAiB,QAAQ,MAAM,0BAA0B;AAE7D,cAAU,KAAK;AAAA,MACb;AAAA,MACA;AAAA,MACA,KAAK,gBAAgB,SAAS;AAAA,IAChC;AACA,cAAU,KAAK;AAAA,MACb;AAAA,MACA;AAAA,MACA,KAAK,gBAAgB,UAAU;AAAA,IACjC;AAEA,QAAI,KAAK,UAAU,kBAAkB,eAAe,CAAC,GAAG;AACtD,gBAAU,KAAK;AAAA,QACb;AAAA,QACA;AAAA,QACA,eAAe,CAAC;AAAA,MAClB;AAAA,IACF;AAEA,UAAM,GAAG,UAAU,KAAK,KAAK,QAAQ,IAAI,GAAG,MAAM,GAAG,SAAS,OAAO;AAAA,EACvE;AAAA,EAEA,YAAY,MAAc,KAAa,OAAe;AACpD,QAAI,QAAQ,IAAI,OAAO,IAAI,GAAG,OAAO,IAAI;AACzC,WAAO,KAAK,QAAQ,OAAO,GAAG,GAAG,IAAI,KAAK,EAAE;AAC5C,UAAM,QAAQ,KAAK,MAAM,KAAK;AAE9B,QAAI,CAAC,OAAO;AACV,aAAO,OAAO;AAAA,EAAK,GAAG,IAAI,KAAK;AAAA,IACjC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,gBAAgB,KAAa;AAC3B,WAAO,IACJ,QAAQ,4BAA4B,EAAE,EACtC,QAAQ,0BAA0B,EAAE,EACpC,QAAQ,aAAa,EAAE;AAAA,EAC5B;AACF;AAEA,IAAI,EAAE,SAAS,kBAAkB;","names":[]}
|
|
@@ -11,19 +11,13 @@ class StartCommand extends Command {
|
|
|
11
11
|
scheduler = Option.Boolean(`--scheduler`, false);
|
|
12
12
|
http = Option.Boolean(`--http`, false);
|
|
13
13
|
all = Option.Boolean("--all", false);
|
|
14
|
-
static paths = [
|
|
15
|
-
[
|
|
16
|
-
`start`
|
|
17
|
-
]
|
|
18
|
-
];
|
|
14
|
+
static paths = [[`start`]];
|
|
19
15
|
async execute() {
|
|
20
|
-
if ([
|
|
21
|
-
this.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.context.stdout.write(`No service was selected. please check -h for details
|
|
26
|
-
`);
|
|
16
|
+
if ([this.all, this.http, this.scheduler].filter((x) => x).length == 0) {
|
|
17
|
+
this.context.stdout.write(
|
|
18
|
+
`No service was selected. please check -h for details
|
|
19
|
+
`
|
|
20
|
+
);
|
|
27
21
|
return;
|
|
28
22
|
}
|
|
29
23
|
logger().info(`Starting Server
|
|
@@ -37,7 +31,9 @@ class StartCommand extends Command {
|
|
|
37
31
|
if (this.http || this.all) {
|
|
38
32
|
const server = httpServer();
|
|
39
33
|
await server.listen(config.get("port"), () => {
|
|
40
|
-
logger().info(
|
|
34
|
+
logger().info(
|
|
35
|
+
"Server is running on http://localhost:" + config.get("port")
|
|
36
|
+
);
|
|
41
37
|
});
|
|
42
38
|
}
|
|
43
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/app/console/StartCommand.
|
|
1
|
+
{"version":3,"sources":["../../../src/app/console/StartCommand.mts"],"sourcesContent":["import { Command, Option } from \"clipanion\";\nimport { config } from \"@devbro/neko-config\";\n\nimport { cli, httpServer, logger, scheduler } from \"../../facades.mjs\";\nimport { PostgresqlConnection } from \"@devbro/neko-sql\";\n\nexport class StartCommand extends Command {\n scheduler = Option.Boolean(`--scheduler`, false);\n http = Option.Boolean(`--http`, false);\n all = Option.Boolean(\"--all\", false);\n static paths = [[`start`]];\n\n async execute() {\n if ([this.all, this.http, this.scheduler].filter((x) => x).length == 0) {\n this.context.stdout.write(\n `No service was selected. please check -h for details\\n`,\n );\n return;\n }\n\n logger().info(`Starting Server\\n`);\n\n PostgresqlConnection.defaults.idleTimeoutMillis = 10000;\n\n if (this.scheduler || this.all) {\n logger().info(`starting scheduler\\n`);\n scheduler().start();\n }\n\n if (this.http || this.all) {\n const server = httpServer();\n await server.listen(config.get(\"port\"), () => {\n logger().info(\n \"Server is running on http://localhost:\" + config.get(\"port\"),\n );\n });\n }\n }\n}\n\ncli().register(StartCommand);\n"],"mappings":";;AAAA,SAAS,SAAS,cAAc;AAChC,SAAS,cAAc;AAEvB,SAAS,KAAK,YAAY,QAAQ,iBAAiB;AACnD,SAAS,4BAA4B;AAE9B,MAAM,qBAAqB,QAAQ;AAAA,EAN1C,OAM0C;AAAA;AAAA;AAAA,EACxC,YAAY,OAAO,QAAQ,eAAe,KAAK;AAAA,EAC/C,OAAO,OAAO,QAAQ,UAAU,KAAK;AAAA,EACrC,MAAM,OAAO,QAAQ,SAAS,KAAK;AAAA,EACnC,OAAO,QAAQ,CAAC,CAAC,OAAO,CAAC;AAAA,EAEzB,MAAM,UAAU;AACd,QAAI,CAAC,KAAK,KAAK,KAAK,MAAM,KAAK,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG;AACtE,WAAK,QAAQ,OAAO;AAAA,QAClB;AAAA;AAAA,MACF;AACA;AAAA,IACF;AAEA,WAAO,EAAE,KAAK;AAAA,CAAmB;AAEjC,yBAAqB,SAAS,oBAAoB;AAElD,QAAI,KAAK,aAAa,KAAK,KAAK;AAC9B,aAAO,EAAE,KAAK;AAAA,CAAsB;AACpC,gBAAU,EAAE,MAAM;AAAA,IACpB;AAEA,QAAI,KAAK,QAAQ,KAAK,KAAK;AACzB,YAAM,SAAS,WAAW;AAC1B,YAAM,OAAO,OAAO,OAAO,IAAI,MAAM,GAAG,MAAM;AAC5C,eAAO,EAAE;AAAA,UACP,2CAA2C,OAAO,IAAI,MAAM;AAAA,QAC9D;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,IAAI,EAAE,SAAS,YAAY;","names":[]}
|
|
@@ -14,43 +14,40 @@ class GenerateControllerCommand extends Command {
|
|
|
14
14
|
__name(this, "GenerateControllerCommand");
|
|
15
15
|
}
|
|
16
16
|
static paths = [
|
|
17
|
-
[
|
|
18
|
-
|
|
19
|
-
`controller`
|
|
20
|
-
],
|
|
21
|
-
[
|
|
22
|
-
`generate`,
|
|
23
|
-
`controller`
|
|
24
|
-
]
|
|
17
|
+
[`make`, `controller`],
|
|
18
|
+
[`generate`, `controller`]
|
|
25
19
|
];
|
|
26
|
-
name = Option.String({
|
|
27
|
-
required: true
|
|
28
|
-
});
|
|
20
|
+
name = Option.String({ required: true });
|
|
29
21
|
async execute() {
|
|
30
22
|
const rootDir = process.cwd();
|
|
31
23
|
const date = /* @__PURE__ */ new Date();
|
|
32
24
|
const year = date.getFullYear();
|
|
33
25
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
34
26
|
const day = String(date.getDate()).padStart(2, "0");
|
|
35
|
-
const secondsOfDay = String(
|
|
27
|
+
const secondsOfDay = String(
|
|
28
|
+
date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()
|
|
29
|
+
).padStart(5, "0");
|
|
36
30
|
const fixed_name = Case.snake(this.name);
|
|
37
31
|
const filename = `${Case.capital(this.name)}Controller.ts`;
|
|
38
32
|
this.context.stdout.write(`creating migration file ${filename}
|
|
39
33
|
`);
|
|
40
|
-
await fs.mkdir(config.get("migration.path"), {
|
|
41
|
-
recursive: true
|
|
42
|
-
});
|
|
34
|
+
await fs.mkdir(config.get("migration.path"), { recursive: true });
|
|
43
35
|
let dirname = typeof __dirname === "string" ? __dirname : void 0;
|
|
44
36
|
if (!dirname) {
|
|
45
37
|
dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
46
38
|
}
|
|
47
|
-
const compiledTemplate = handlebars.compile(
|
|
39
|
+
const compiledTemplate = handlebars.compile(
|
|
40
|
+
(await fs.readFile(path.join(dirname, "./controller.tpl"))).toString()
|
|
41
|
+
);
|
|
48
42
|
const template = await compiledTemplate({
|
|
49
43
|
className: Case.pascal(this.name),
|
|
50
44
|
classNameLower: Case.snake(this.name),
|
|
51
45
|
routeName: Case.kebab(pluralize(this.name))
|
|
52
46
|
});
|
|
53
|
-
await fs.writeFile(
|
|
47
|
+
await fs.writeFile(
|
|
48
|
+
path.join(rootDir, "src/app/controllers", filename),
|
|
49
|
+
template
|
|
50
|
+
);
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
53
|
cli().register(GenerateControllerCommand);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/generate/GenerateControllerCommand.
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/generate/GenerateControllerCommand.mts"],"sourcesContent":["import { cli } from \"../../../facades.mjs\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport handlebars from \"handlebars\";\nimport { fileURLToPath } from \"url\";\nimport pluralize from \"pluralize\";\n\nexport class GenerateControllerCommand extends Command {\n static paths = [\n [`make`, `controller`],\n [`generate`, `controller`],\n ];\n\n name = Option.String({ required: true });\n\n async execute() {\n const rootDir = process.cwd();\n\n const date = new Date();\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const secondsOfDay = String(\n date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds(),\n ).padStart(5, \"0\");\n\n const fixed_name = Case.snake(this.name);\n const filename = `${Case.capital(this.name)}Controller.ts`;\n this.context.stdout.write(`creating migration file ${filename}\\n`);\n\n await fs.mkdir(config.get(\"migration.path\"), { recursive: true });\n\n let dirname = typeof __dirname === \"string\" ? __dirname : undefined;\n if (!dirname) {\n dirname = path.dirname(fileURLToPath(import.meta.url));\n }\n\n const compiledTemplate = handlebars.compile(\n (await fs.readFile(path.join(dirname, \"./controller.tpl\"))).toString(),\n );\n const template = await compiledTemplate({\n className: Case.pascal(this.name),\n classNameLower: Case.snake(this.name),\n routeName: Case.kebab(pluralize(this.name)),\n });\n\n await fs.writeFile(\n path.join(rootDir, \"src/app/controllers\", filename),\n template,\n );\n }\n}\n\ncli().register(GenerateControllerCommand);\n"],"mappings":";;AAAA,SAAS,WAAW;AACpB,SAAS,SAAS,cAAc;AAChC,SAAS,YAAY;AACrB,OAAO,UAAU;AACjB,YAAY,QAAQ;AACpB,SAAS,cAAc;AACvB,OAAO,gBAAgB;AACvB,SAAS,qBAAqB;AAC9B,OAAO,e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AAU,KAAK,IAAI,CAAC;AAAA,IAC5C,CAAC;AAED,UAAM,GAAG;AAAA,MACP,KAAK,KAAK,SAAS,uBAAuB,QAAQ;AAAA,MAClD;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAI,EAAE,SAAS,yBAAyB;","names":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./GenerateControllerCommand";
|
|
1
|
+
export * from "./GenerateControllerCommand.mjs";
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/generate/index.
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/generate/index.mts"],"sourcesContent":["export * from \"./GenerateControllerCommand.mjs\";\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from "./migrate";
|
|
2
|
-
export * from "./StartCommand";
|
|
3
|
-
export * from "./DefaultCommand";
|
|
4
|
-
export * from "./KeyGenerateCommand";
|
|
5
|
-
export * from "./generate";
|
|
6
|
-
export * from "./project/CreateProjectCommand";
|
|
1
|
+
export * from "./migrate/index.mjs";
|
|
2
|
+
export * from "./StartCommand.mjs";
|
|
3
|
+
export * from "./DefaultCommand.mjs";
|
|
4
|
+
export * from "./KeyGenerateCommand.mjs";
|
|
5
|
+
export * from "./generate/index.mjs";
|
|
6
|
+
export * from "./project/CreateProjectCommand.mjs";
|
|
7
7
|
import { cli } from "../../facades.mjs";
|
|
8
|
-
import { CreateProjectCommand } from "./project/CreateProjectCommand";
|
|
8
|
+
import { CreateProjectCommand } from "./project/CreateProjectCommand.mjs";
|
|
9
9
|
cli().register(CreateProjectCommand);
|
|
10
10
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/app/console/index.
|
|
1
|
+
{"version":3,"sources":["../../../src/app/console/index.mts"],"sourcesContent":["export * from \"./migrate/index.mjs\";\nexport * from \"./StartCommand.mjs\";\nexport * from \"./DefaultCommand.mjs\";\nexport * from \"./KeyGenerateCommand.mjs\";\nexport * from \"./generate/index.mjs\";\nexport * from \"./project/CreateProjectCommand.mjs\";\n\nimport { cli } from \"../../facades.mjs\";\nimport { CreateProjectCommand } from \"./project/CreateProjectCommand.mjs\";\n\ncli().register(CreateProjectCommand);\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAAS,WAAW;AACpB,SAAS,4BAA4B;AAErC,IAAI,EAAE,SAAS,oBAAoB;","names":[]}
|
|
@@ -13,41 +13,38 @@ class GenerateMigrateCommand extends Command {
|
|
|
13
13
|
__name(this, "GenerateMigrateCommand");
|
|
14
14
|
}
|
|
15
15
|
static paths = [
|
|
16
|
-
[
|
|
17
|
-
|
|
18
|
-
`migrate`
|
|
19
|
-
],
|
|
20
|
-
[
|
|
21
|
-
"generate",
|
|
22
|
-
"migration"
|
|
23
|
-
]
|
|
16
|
+
[`generate`, `migrate`],
|
|
17
|
+
["generate", "migration"]
|
|
24
18
|
];
|
|
25
|
-
name = Option.String({
|
|
26
|
-
required: true
|
|
27
|
-
});
|
|
19
|
+
name = Option.String({ required: true });
|
|
28
20
|
async execute() {
|
|
29
21
|
const date = /* @__PURE__ */ new Date();
|
|
30
22
|
const year = date.getFullYear();
|
|
31
23
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
32
24
|
const day = String(date.getDate()).padStart(2, "0");
|
|
33
|
-
const secondsOfDay = String(
|
|
25
|
+
const secondsOfDay = String(
|
|
26
|
+
date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()
|
|
27
|
+
).padStart(5, "0");
|
|
34
28
|
const fixed_name = Case.snake(this.name);
|
|
35
29
|
const filename = `${year}_${month}_${day}_${secondsOfDay}_${fixed_name}.ts`;
|
|
36
30
|
this.context.stdout.write(`creating migration file ${filename}
|
|
37
31
|
`);
|
|
38
|
-
await fs.mkdir(config.get("migration.path"), {
|
|
39
|
-
recursive: true
|
|
40
|
-
});
|
|
32
|
+
await fs.mkdir(config.get("migration.path"), { recursive: true });
|
|
41
33
|
let dirname = typeof __dirname === "string" ? __dirname : void 0;
|
|
42
34
|
if (!dirname) {
|
|
43
35
|
dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
44
36
|
}
|
|
45
|
-
const compiledTemplate = handlebars.compile(
|
|
37
|
+
const compiledTemplate = handlebars.compile(
|
|
38
|
+
(await fs.readFile(path.join(dirname, "./make_migration.tpl"))).toString()
|
|
39
|
+
);
|
|
46
40
|
const template = await compiledTemplate({
|
|
47
41
|
className: Case.pascal(this.name) + "Migration",
|
|
48
42
|
tableName: Case.snake(this.name)
|
|
49
43
|
});
|
|
50
|
-
await fs.writeFile(
|
|
44
|
+
await fs.writeFile(
|
|
45
|
+
path.join(config.get("migration.path"), filename),
|
|
46
|
+
template
|
|
47
|
+
);
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
cli().register(GenerateMigrateCommand);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/migrate/GenerateMigrateCommand.
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/migrate/GenerateMigrateCommand.mts"],"sourcesContent":["import { cli } from \"../../../facades.mjs\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport handlebars from \"handlebars\";\nimport { fileURLToPath } from \"url\";\nimport { table } from \"console\";\n\nexport class GenerateMigrateCommand extends Command {\n static paths = [\n [`generate`, `migrate`],\n [\"generate\", \"migration\"],\n ];\n\n name = Option.String({ required: true });\n\n async execute() {\n const date = new Date();\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const secondsOfDay = String(\n date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds(),\n ).padStart(5, \"0\");\n\n const fixed_name = Case.snake(this.name);\n const filename = `${year}_${month}_${day}_${secondsOfDay}_${fixed_name}.ts`;\n this.context.stdout.write(`creating migration file ${filename}\\n`);\n\n await fs.mkdir(config.get(\"migration.path\"), { recursive: true });\n\n let dirname = typeof __dirname === \"string\" ? __dirname : undefined;\n if (!dirname) {\n dirname = path.dirname(fileURLToPath(import.meta.url));\n }\n\n const compiledTemplate = handlebars.compile(\n (\n await fs.readFile(path.join(dirname, \"./make_migration.tpl\"))\n ).toString(),\n );\n const template = await compiledTemplate({\n className: Case.pascal(this.name) + \"Migration\",\n tableName: Case.snake(this.name),\n });\n\n await fs.writeFile(\n path.join(config.get(\"migration.path\"), filename),\n template,\n );\n }\n}\n\ncli().register(GenerateMigrateCommand);\n"],"mappings":";;AAAA,SAAS,WAAW;AACpB,SAAS,SAAS,cAAc;AAChC,SAAS,YAAY;AACrB,OAAO,UAAU;AACjB,YAAY,QAAQ;AACpB,SAAS,cAAc;AACvB,OAAO,gBAAgB;AACvB,SAAS,qBAAqB;AAGvB,MAAM,+BAA+B,QAAQ;AAAA,EAVpD,OAUoD;AAAA;AAAA;AAAA,EAClD,OAAO,QAAQ;AAAA,IACb,CAAC,YAAY,SAAS;AAAA,IACtB,CAAC,YAAY,WAAW;AAAA,EAC1B;AAAA,EAEA,OAAO,OAAO,OAAO,EAAE,UAAU,KAAK,CAAC;AAAA,EAEvC,MAAM,UAAU;AACd,UAAM,OAAO,oBAAI,KAAK;AACtB,UAAM,OAAO,KAAK,YAAY;AAC9B,UAAM,QAAQ,OAAO,KAAK,SAAS,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG;AACzD,UAAM,MAAM,OAAO,KAAK,QAAQ,CAAC,EAAE,SAAS,GAAG,GAAG;AAClD,UAAM,eAAe;AAAA,MACnB,KAAK,SAAS,IAAI,OAAO,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW;AAAA,IACpE,EAAE,SAAS,GAAG,GAAG;AAEjB,UAAM,aAAa,KAAK,MAAM,KAAK,IAAI;AACvC,UAAM,WAAW,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,IAAI,YAAY,IAAI,UAAU;AACtE,SAAK,QAAQ,OAAO,MAAM,2BAA2B,QAAQ;AAAA,CAAI;AAEjE,UAAM,GAAG,MAAM,OAAO,IAAI,gBAAgB,GAAG,EAAE,WAAW,KAAK,CAAC;AAEhE,QAAI,UAAU,OAAO,cAAc,WAAW,YAAY;AAC1D,QAAI,CAAC,SAAS;AACZ,gBAAU,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AAAA,IACvD;AAEA,UAAM,mBAAmB,WAAW;AAAA,OAEhC,MAAM,GAAG,SAAS,KAAK,KAAK,SAAS,sBAAsB,CAAC,GAC5D,SAAS;AAAA,IACb;AACA,UAAM,WAAW,MAAM,iBAAiB;AAAA,MACtC,WAAW,KAAK,OAAO,KAAK,IAAI,IAAI;AAAA,MACpC,WAAW,KAAK,MAAM,KAAK,IAAI;AAAA,IACjC,CAAC;AAED,UAAM,GAAG;AAAA,MACP,KAAK,KAAK,OAAO,IAAI,gBAAgB,GAAG,QAAQ;AAAA,MAChD;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAI,EAAE,SAAS,sBAAsB;","names":[]}
|
|
@@ -10,34 +10,47 @@ class MigrateCommand extends Command {
|
|
|
10
10
|
static {
|
|
11
11
|
__name(this, "MigrateCommand");
|
|
12
12
|
}
|
|
13
|
-
static paths = [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
static paths = [[`migrate`]];
|
|
14
|
+
fresh = Option.Boolean(`--fresh`, false, {
|
|
15
|
+
description: `whether to delete and recreate database`
|
|
16
|
+
});
|
|
17
|
+
refresh = Option.Boolean(`--refresh`, false, {
|
|
18
|
+
description: `whether to drop all tables before running migrations by using rollback function`
|
|
19
|
+
});
|
|
19
20
|
async execute() {
|
|
20
21
|
await context_provider.run(async () => {
|
|
21
22
|
const db = database();
|
|
22
23
|
const schema = db.getSchema();
|
|
23
24
|
if (this.fresh) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
throw new Error("not implemented");
|
|
26
|
+
}
|
|
27
|
+
if (this.refresh) {
|
|
28
|
+
logger().info("reverting all migrations!!");
|
|
29
|
+
const existing_migrations = await db.runQuery({
|
|
30
|
+
sql: "select * from migrations order by created_at DESC",
|
|
31
|
+
bindings: []
|
|
32
|
+
});
|
|
33
|
+
const migrationsDir2 = config.get("migration.path");
|
|
34
|
+
for (const migration_record of existing_migrations) {
|
|
35
|
+
logger().info(`rolling back ${migration_record.filename}`);
|
|
36
|
+
try {
|
|
37
|
+
const MigrationClass = (await import(path.join(migrationsDir2, migration_record.filename))).default;
|
|
38
|
+
const migrationInstance = new MigrationClass();
|
|
39
|
+
await migrationInstance.down(db.getSchema());
|
|
40
|
+
await db.runQuery({
|
|
41
|
+
sql: "delete from migrations where filename = $1",
|
|
42
|
+
bindings: [migration_record.filename]
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
logger().error(
|
|
46
|
+
`Failed to rollback migration ${migration_record.filename}: ${error}`
|
|
47
|
+
);
|
|
48
|
+
throw error;
|
|
39
49
|
}
|
|
40
50
|
}
|
|
51
|
+
logger().info(
|
|
52
|
+
`rolled back ${existing_migrations.length} migrations successfully!`
|
|
53
|
+
);
|
|
41
54
|
}
|
|
42
55
|
if (!await schema.tableExists("migrations")) {
|
|
43
56
|
await schema.createTable("migrations", (blueprint) => {
|
|
@@ -62,7 +75,9 @@ class MigrateCommand extends Command {
|
|
|
62
75
|
bindings: []
|
|
63
76
|
});
|
|
64
77
|
const completed_migrations = migrations.map((r) => r.filename);
|
|
65
|
-
const pending_migrations = files.filter(
|
|
78
|
+
const pending_migrations = files.filter(
|
|
79
|
+
(file) => !completed_migrations.includes(file)
|
|
80
|
+
);
|
|
66
81
|
let migrated_count = 0;
|
|
67
82
|
for (const class_to_migrate of pending_migrations) {
|
|
68
83
|
logger().info(`migrating up ${class_to_migrate}`);
|
|
@@ -71,10 +86,7 @@ class MigrateCommand extends Command {
|
|
|
71
86
|
await c.up(db.getSchema());
|
|
72
87
|
await db.runQuery({
|
|
73
88
|
sql: "insert into migrations (filename, batch) values ($1,$2)",
|
|
74
|
-
bindings: [
|
|
75
|
-
class_to_migrate,
|
|
76
|
-
batch_number
|
|
77
|
-
]
|
|
89
|
+
bindings: [class_to_migrate, batch_number]
|
|
78
90
|
});
|
|
79
91
|
migrated_count++;
|
|
80
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/migrate/MigrateCommand.
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/migrate/MigrateCommand.mts"],"sourcesContent":["import { cli, db as database, logger } from \"../../../facades.mjs\";\nimport { Command, Option } from \"clipanion\";\nimport { Blueprint } from \"@devbro/neko-sql\";\nimport { context_provider } from \"@devbro/neko-context\";\nimport path from \"path\";\nimport fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport { Migration } from \"@devbro/neko-sql\";\n\nexport class MigrateCommand extends Command {\n static paths = [[`migrate`]];\n\n fresh = Option.Boolean(`--fresh`, false, {\n description: `whether to delete and recreate database`,\n });\n\n refresh = Option.Boolean(`--refresh`, false, {\n description: `whether to drop all tables before running migrations by using rollback function`,\n });\n\n async execute() {\n await context_provider.run(async () => {\n // this.context.stdout.write(`Hello Migrate Command!\\n`);\n const db = database();\n const schema = db.getSchema();\n\n if (this.fresh) {\n throw new Error(\"not implemented\");\n }\n\n if (this.refresh) {\n logger().info(\"reverting all migrations!!\");\n // read all migrations and undo them all\n const existing_migrations = await db.runQuery({\n sql: \"select * from migrations order by created_at DESC\",\n bindings: [],\n });\n\n const migrationsDir = config.get(\"migration.path\");\n\n for (const migration_record of existing_migrations) {\n logger().info(`rolling back ${migration_record.filename}`);\n try {\n const MigrationClass = (\n await import(path.join(migrationsDir, migration_record.filename))\n ).default;\n const migrationInstance: Migration = new MigrationClass();\n\n // Call the down method to rollback the migration\n await migrationInstance.down(db.getSchema());\n\n // Remove the migration record from the migrations table\n await db.runQuery({\n sql: \"delete from migrations where filename = $1\",\n bindings: [migration_record.filename],\n });\n } catch (error) {\n logger().error(\n `Failed to rollback migration ${migration_record.filename}: ${error}`,\n );\n throw error;\n }\n }\n\n logger().info(\n `rolled back ${existing_migrations.length} migrations successfully!`,\n );\n }\n\n //create migration table if not exists\n if (!(await schema.tableExists(\"migrations\"))) {\n await schema.createTable(\"migrations\", (blueprint: Blueprint) => {\n blueprint.id();\n blueprint.timestamps();\n blueprint.string(\"filename\");\n blueprint.integer(\"batch\");\n });\n }\n\n const migrationsDir = config.get(\"migration.path\");\n let files: string[] = [];\n\n const dirEntries = await fs.readdir(migrationsDir);\n files = dirEntries\n .filter((entry) => entry.endsWith(\".ts\") || entry.endsWith(\".js\"))\n .sort();\n let batch_number = await db.runQuery({\n sql: \"select max(batch) as next_batch from migrations\",\n bindings: [],\n });\n batch_number = batch_number[0].next_batch || 0;\n batch_number++;\n\n const migrations = await db.runQuery({\n sql: \"select * from migrations order by created_at ASC\",\n bindings: [],\n });\n\n const completed_migrations = migrations.map((r: any) => r.filename);\n const pending_migrations = files.filter(\n (file) => !completed_migrations.includes(file),\n );\n\n let migrated_count = 0;\n for (const class_to_migrate of pending_migrations) {\n logger().info(`migrating up ${class_to_migrate}`);\n const ClassToMigrate = (\n await import(path.join(migrationsDir, class_to_migrate))\n ).default;\n const c: Migration = new ClassToMigrate();\n await c.up(db.getSchema());\n await db.runQuery({\n sql: \"insert into migrations (filename, batch) values ($1,$2)\",\n bindings: [class_to_migrate, batch_number],\n });\n migrated_count++;\n }\n\n if (migrated_count === 0) {\n logger().warn(\"no migrations to run!\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ACzB,cAAM,GAAG,SAAS;AAAA,UAChB,KAAK;AAAA,UACL,UAAU,CAAC,kBAAkB,YAAY;AAAA,QAC3C,CAAC;AACD;AAAA,MACF;AAEA,UAAI,mBAAmB,GAAG;AACxB,eAAO,EAAE,KAAK,uBAAuB;AACrC;AAAA,MACF;AAEA,aAAO,EAAE,KAAK,YAAY,cAAc,2BAA2B;AAAA,IACrE,CAAC;AAAA,EACH;AACF;AAEA,IAAI,EAAE,SAAS,cAAc;","names":["migrationsDir"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { cli, db as database } from "../../../facades.mjs";
|
|
3
|
+
import { cli, db as database, logger } from "../../../facades.mjs";
|
|
4
4
|
import { Command, Option } from "clipanion";
|
|
5
5
|
import { context_provider } from "@devbro/neko-context";
|
|
6
6
|
import path from "path";
|
|
@@ -11,13 +11,8 @@ class MigrateRollbackCommand extends Command {
|
|
|
11
11
|
static {
|
|
12
12
|
__name(this, "MigrateRollbackCommand");
|
|
13
13
|
}
|
|
14
|
-
static paths = [
|
|
15
|
-
|
|
16
|
-
`migrate`,
|
|
17
|
-
"rollback"
|
|
18
|
-
]
|
|
19
|
-
];
|
|
20
|
-
steps = Option.String(`--steps`, {
|
|
14
|
+
static paths = [[`migrate`, "rollback"]];
|
|
15
|
+
steps = Option.String(`--steps`, "1", {
|
|
21
16
|
description: `how many migrations to rollback`,
|
|
22
17
|
validator: t.isNumber()
|
|
23
18
|
});
|
|
@@ -30,21 +25,18 @@ class MigrateRollbackCommand extends Command {
|
|
|
30
25
|
const dirEntries = await fs.readdir(migrationsDir);
|
|
31
26
|
files = dirEntries.filter((entry) => entry.endsWith(".ts")).sort();
|
|
32
27
|
const migrations = await db.runQuery({
|
|
33
|
-
sql: "select * from migrations order by created_at DESC",
|
|
34
|
-
bindings: []
|
|
28
|
+
sql: "select * from migrations order by created_at DESC limit $1",
|
|
29
|
+
bindings: [this.steps]
|
|
35
30
|
});
|
|
36
|
-
const count = 0;
|
|
37
31
|
for (const migration of migrations) {
|
|
38
32
|
const class_to_migrate = migration.filename;
|
|
39
|
-
|
|
33
|
+
logger().info(`rolling back ${class_to_migrate}`);
|
|
40
34
|
const ClassToMigrate = (await import(path.join(migrationsDir, class_to_migrate))).default;
|
|
41
35
|
const c = new ClassToMigrate();
|
|
42
36
|
await c.down(db.getSchema());
|
|
43
37
|
await db.runQuery({
|
|
44
38
|
sql: "delete from migrations where id = $1",
|
|
45
|
-
bindings: [
|
|
46
|
-
migration.id
|
|
47
|
-
]
|
|
39
|
+
bindings: [migration.id]
|
|
48
40
|
});
|
|
49
41
|
}
|
|
50
42
|
});
|