@ad-sdk/bgd 0.0.8 → 0.0.9
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/package.json +1 -1
- package/sqlx/migrations.js +33 -29
package/package.json
CHANGED
package/sqlx/migrations.js
CHANGED
|
@@ -39,41 +39,45 @@ async function migrate(driver, directory, options) {
|
|
|
39
39
|
const tx = await driver.createTransaction({
|
|
40
40
|
allowQueryBatch: true
|
|
41
41
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
try {
|
|
43
|
+
for (let i = 0; i < contentsList.length; ++i) {
|
|
44
|
+
if (!_core.SQL_MIGRATION_FILE_PATTERN.test(contentsList[i].name)) continue;
|
|
45
|
+
const currPath = _nodePath.default.join(contentsList[i].parentPath, contentsList[i].name // eslint-disable-line comma-dangle
|
|
46
|
+
);
|
|
47
|
+
if (contentsList[i].isDirectory() && options?.recursive) {
|
|
48
|
+
const res = await migrate(driver, currPath, options);
|
|
49
|
+
if (res.isLeft()) {
|
|
50
|
+
throw res.value;
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
50
53
|
}
|
|
51
|
-
continue;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}, {
|
|
64
|
-
query: `INSERT INTO bgd_migrations (
|
|
54
|
+
if (!contentsList[i].isFile()) continue;
|
|
55
|
+
if (executed.some(item => {
|
|
56
|
+
return item.filename === contentsList[i].name;
|
|
57
|
+
})) {
|
|
58
|
+
options?.logger?.log("[@@migrate] Migration \"%s\" has already executed. Skipping...", contentsList[i].name);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const fc = await fs.promises.readFile(currPath, "utf8");
|
|
62
|
+
const res = await tx.execBatch([{
|
|
63
|
+
query: fc.trim()
|
|
64
|
+
}, {
|
|
65
|
+
query: `INSERT INTO bgd_migrations (
|
|
65
66
|
migration_id, filename, order
|
|
66
67
|
) VALUES ($1::TEXT, $2::TEXT, $3::VARCHAR)`,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
values: [(0, _uidlib.uuidv7)(), contentsList[0].name, contentsList[i].name.split("_")[0]]
|
|
69
|
+
}]);
|
|
70
|
+
for (let j = 0; j < res.length; ++j) {
|
|
71
|
+
if (res[j].isLeft()) {
|
|
72
|
+
throw res[j].value;
|
|
73
|
+
}
|
|
73
74
|
}
|
|
74
75
|
}
|
|
76
|
+
await tx.commit();
|
|
77
|
+
} catch (e) {
|
|
78
|
+
await tx.rollback();
|
|
79
|
+
throw e;
|
|
75
80
|
}
|
|
76
|
-
await tx.commit();
|
|
77
81
|
return (0, _either.right)(void 0);
|
|
78
82
|
} catch (err) {
|
|
79
83
|
let e = err;
|