db-model-router 1.0.20 → 1.0.22
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/src/cli/diff-engine.js +5 -1
- package/src/cli/init/generators.js +9 -1
- package/src/mysql/db.js +8 -2
package/package.json
CHANGED
package/src/cli/diff-engine.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const { generateModelFile } = require("./generate-model.js");
|
|
5
|
+
const { generateModelFile, generateIndexFile } = require("./generate-model.js");
|
|
6
6
|
const {
|
|
7
7
|
generateRouteFile,
|
|
8
8
|
generateParentRouteFile,
|
|
@@ -87,6 +87,10 @@ function buildExpectedFiles(meta, relationships, options = {}) {
|
|
|
87
87
|
expected.set(`models/${m.table}.js`, generateModelFile(m));
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
// Model barrel. SaaS mode overwrites this with the combined SaaS+dbmr
|
|
91
|
+
// barrel when saasFiles are merged below.
|
|
92
|
+
expected.set("models/index.js", generateIndexFile(meta));
|
|
93
|
+
|
|
90
94
|
// Route files: exactly one per table at its correct nested path
|
|
91
95
|
for (const m of meta) {
|
|
92
96
|
const tableName = m.table;
|
|
@@ -703,9 +703,17 @@ function generateInitialMigration(answers, date) {
|
|
|
703
703
|
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
704
704
|
checksum VARCHAR2(64) NOT NULL
|
|
705
705
|
);
|
|
706
|
+
`;
|
|
707
|
+
} else if (answers.database === "mysql" || answers.database === "mariadb") {
|
|
708
|
+
content = `CREATE TABLE IF NOT EXISTS _migrations (
|
|
709
|
+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
710
|
+
filename VARCHAR(255) NOT NULL UNIQUE,
|
|
711
|
+
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
712
|
+
checksum VARCHAR(64) NOT NULL
|
|
713
|
+
);
|
|
706
714
|
`;
|
|
707
715
|
} else {
|
|
708
|
-
//
|
|
716
|
+
// sqlite3
|
|
709
717
|
content = `CREATE TABLE IF NOT EXISTS _migrations (
|
|
710
718
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
711
719
|
filename VARCHAR(255) NOT NULL UNIQUE,
|
package/src/mysql/db.js
CHANGED
|
@@ -7,6 +7,12 @@ function connect(credentails) {
|
|
|
7
7
|
// Force UTC timezone so timestamps are consistent
|
|
8
8
|
// dateStrings: true returns raw strings without JS Date conversion
|
|
9
9
|
credentails.timezone = "+00:00";
|
|
10
|
+
// Enable multiple statements by default so multi-query migration files
|
|
11
|
+
// (e.g. a single .sql with many CREATE TABLE statements) run in one call.
|
|
12
|
+
// Applied to mysql and mariadb (both use this adapter).
|
|
13
|
+
if (credentails.multipleStatements === undefined) {
|
|
14
|
+
credentails.multipleStatements = true;
|
|
15
|
+
}
|
|
10
16
|
pool = mysql.createPool(credentails);
|
|
11
17
|
return pool;
|
|
12
18
|
}
|
|
@@ -327,7 +333,7 @@ function getChangeParameter(row, uniqueKeys, onDuplicate = true) {
|
|
|
327
333
|
if (queryEnd !== " ON DUPLICATE KEY UPDATE ") {
|
|
328
334
|
queryEnd += ",";
|
|
329
335
|
}
|
|
330
|
-
queryEnd += "??=
|
|
336
|
+
queryEnd += "??=VALUES(??)";
|
|
331
337
|
updateColumn.push(column);
|
|
332
338
|
updateColumn.push(column);
|
|
333
339
|
}
|
|
@@ -335,7 +341,7 @@ function getChangeParameter(row, uniqueKeys, onDuplicate = true) {
|
|
|
335
341
|
}
|
|
336
342
|
queryEnd += ";";
|
|
337
343
|
return [
|
|
338
|
-
`${queryStart} VALUES ?
|
|
344
|
+
`${queryStart} VALUES ? ${queryEnd}`,
|
|
339
345
|
insertColumn,
|
|
340
346
|
updateColumn,
|
|
341
347
|
];
|