biz-a-cli 2.3.75 → 2.3.76
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/bin/migrate.js +12 -10
- package/package.json +1 -1
package/bin/migrate.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { queryData, save as dbSave, executeBlock } from "../db/db.js";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
const migrationDir = path.resolve(__dirname, "migrations");
|
|
4
9
|
|
|
5
10
|
const flattenSql = (sqlString) => {
|
|
6
11
|
return sqlString
|
|
@@ -12,9 +17,8 @@ const flattenSql = (sqlString) => {
|
|
|
12
17
|
};
|
|
13
18
|
|
|
14
19
|
export const newMigration = (argv) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
20
|
+
if (!fs.existsSync(migrationDir)) {
|
|
21
|
+
fs.mkdirSync(migrationDir, { recursive: true });
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
const safeName = argv.name
|
|
@@ -37,16 +41,14 @@ export const newMigration = (argv) => {
|
|
|
37
41
|
"",
|
|
38
42
|
].join("\n");
|
|
39
43
|
|
|
40
|
-
fs.writeFileSync(path.join(
|
|
44
|
+
fs.writeFileSync(path.join(migrationDir, filename), template);
|
|
41
45
|
console.log(`[Success] Created new migration file: migrations/${filename}`);
|
|
42
46
|
};
|
|
43
47
|
|
|
44
48
|
export const runMigrations = async (argv) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (!fs.existsSync(migrationsDir)) {
|
|
49
|
+
if (!fs.existsSync(migrationDir)) {
|
|
48
50
|
console.log(
|
|
49
|
-
`[Migrate] No 'migrations' folder found at ${
|
|
51
|
+
`[Migrate] No 'migrations' folder found at ${migrationDir}`,
|
|
50
52
|
);
|
|
51
53
|
return { success: false, error: "Missing migrations folder" };
|
|
52
54
|
}
|
|
@@ -75,7 +77,7 @@ export const runMigrations = async (argv) => {
|
|
|
75
77
|
|
|
76
78
|
try {
|
|
77
79
|
const files = fs
|
|
78
|
-
.readdirSync(
|
|
80
|
+
.readdirSync(migrationDir)
|
|
79
81
|
.filter((f) => f.endsWith(".sql"))
|
|
80
82
|
.sort();
|
|
81
83
|
|
|
@@ -102,7 +104,7 @@ export const runMigrations = async (argv) => {
|
|
|
102
104
|
|
|
103
105
|
console.log(`[Migrate] Executing ${file}...`);
|
|
104
106
|
const sqlContent = fs.readFileSync(
|
|
105
|
-
path.join(
|
|
107
|
+
path.join(migrationDir, file),
|
|
106
108
|
"utf8",
|
|
107
109
|
);
|
|
108
110
|
|