@jskit-ai/database-runtime 0.1.131 → 0.1.132
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.descriptor.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default Object.freeze({
|
|
2
2
|
packageVersion: 1,
|
|
3
3
|
packageId: "@jskit-ai/database-runtime",
|
|
4
|
-
version: "0.1.
|
|
4
|
+
version: "0.1.132",
|
|
5
5
|
kind: "runtime",
|
|
6
6
|
dependsOn: [
|
|
7
7
|
"@jskit-ai/kernel"
|
|
@@ -70,7 +70,7 @@ export default Object.freeze({
|
|
|
70
70
|
mutations: {
|
|
71
71
|
dependencies: {
|
|
72
72
|
runtime: {
|
|
73
|
-
"@jskit-ai/kernel": "0.1.
|
|
73
|
+
"@jskit-ai/kernel": "0.1.133",
|
|
74
74
|
"dotenv": "^16.4.5",
|
|
75
75
|
"knex": "^3.1.0"
|
|
76
76
|
},
|
|
@@ -99,6 +99,13 @@ export default Object.freeze({
|
|
|
99
99
|
reason: "Ensure migrations directory exists so Knex migration commands can run before any module installs migrations.",
|
|
100
100
|
category: "database-runtime",
|
|
101
101
|
id: "database-runtime-migrations-dir"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
from: "templates/migrations/constraints/.gitkeep",
|
|
105
|
+
to: "migrations/constraints/.gitkeep",
|
|
106
|
+
reason: "Ensure the ordered deferred-constraint migration directory exists.",
|
|
107
|
+
category: "database-runtime",
|
|
108
|
+
id: "database-runtime-constraint-migrations-dir"
|
|
102
109
|
}
|
|
103
110
|
]
|
|
104
111
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/database-runtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.132",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test"
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"./shared/transactions": "./src/shared/transactions.js"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@jskit-ai/kernel": "0.1.
|
|
28
|
+
"@jskit-ai/kernel": "0.1.133"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/templates/knexfile.js
CHANGED
|
@@ -17,6 +17,7 @@ const dialectId = resolveDatabaseClientFromEnvironment(process.env);
|
|
|
17
17
|
const client = toKnexClientId(dialectId);
|
|
18
18
|
const defaultPort = dialectId === "pg" ? 5432 : 3306;
|
|
19
19
|
const migrationsDirectory = path.resolve(appRoot, normalizeText(process.env.DB_MIGRATIONS_DIR) || "migrations");
|
|
20
|
+
const deferredConstraintsDirectory = path.join(migrationsDirectory, "constraints");
|
|
20
21
|
|
|
21
22
|
export default {
|
|
22
23
|
client,
|
|
@@ -26,7 +27,10 @@ export default {
|
|
|
26
27
|
context: "knex migrations"
|
|
27
28
|
}),
|
|
28
29
|
migrations: {
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
// Run every table-creation migration before deferred constraints. This keeps
|
|
31
|
+
// valid mutual foreign keys rebuildable without disabling database checks.
|
|
32
|
+
directory: [migrationsDirectory, deferredConstraintsDirectory],
|
|
33
|
+
extension: "cjs",
|
|
34
|
+
sortDirsSeparately: true
|
|
31
35
|
}
|
|
32
36
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
2
4
|
import test from "node:test";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
3
6
|
import descriptor from "../package.descriptor.mjs";
|
|
4
7
|
|
|
8
|
+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
9
|
+
|
|
5
10
|
test("database-runtime db migrate scripts sync JSKIT-managed migrations before Knex reads them", () => {
|
|
6
11
|
const scripts = descriptor.mutations.packageJson.scripts;
|
|
7
12
|
|
|
@@ -27,3 +32,18 @@ test("database-runtime db migrate scripts sync JSKIT-managed migrations before K
|
|
|
27
32
|
}
|
|
28
33
|
]);
|
|
29
34
|
});
|
|
35
|
+
|
|
36
|
+
test("database-runtime runs deferred constraints after all ordinary migrations", async () => {
|
|
37
|
+
const knexfile = await readFile(path.join(PACKAGE_ROOT, "templates/knexfile.js"), "utf8");
|
|
38
|
+
const deferredDirectoryMutation = descriptor.mutations.files.find(
|
|
39
|
+
(mutation) => mutation.id === "database-runtime-constraint-migrations-dir"
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
assert.match(
|
|
43
|
+
knexfile,
|
|
44
|
+
/directory:\s*\[migrationsDirectory,\s*deferredConstraintsDirectory\]/
|
|
45
|
+
);
|
|
46
|
+
assert.match(knexfile, /sortDirsSeparately:\s*true/);
|
|
47
|
+
assert.match(knexfile, /path\.join\(migrationsDirectory,\s*"constraints"\)/);
|
|
48
|
+
assert.equal(deferredDirectoryMutation?.to, "migrations/constraints/.gitkeep");
|
|
49
|
+
});
|