@mikro-orm/migrations 6.6.7-dev.3 → 6.6.7-dev.5
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/Migrator.js +28 -3
- package/package.json +3 -3
package/Migrator.js
CHANGED
|
@@ -266,13 +266,38 @@ class Migrator {
|
|
|
266
266
|
async getSchemaDiff(blank, initial) {
|
|
267
267
|
const up = [];
|
|
268
268
|
const down = [];
|
|
269
|
+
// Split SQL by statement boundaries (semicolons followed by newline) rather than
|
|
270
|
+
// just newlines, to preserve multiline statements like view definitions.
|
|
271
|
+
// Blank lines (from double newlines) are preserved as empty strings for grouping.
|
|
272
|
+
// Splits inside single-quoted string literals are re-merged (GH #7185).
|
|
273
|
+
const splitStatements = (sql) => {
|
|
274
|
+
const result = [];
|
|
275
|
+
let buf = '';
|
|
276
|
+
for (const chunk of sql.split(/;\n/)) {
|
|
277
|
+
buf += (buf ? ';\n' : '') + chunk;
|
|
278
|
+
// odd number of single quotes means we're inside a string literal
|
|
279
|
+
if (buf.split(`'`).length % 2 === 0) {
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
// A chunk starting with \n indicates there was a blank line (grouping separator)
|
|
283
|
+
if (buf.startsWith('\n')) {
|
|
284
|
+
result.push('');
|
|
285
|
+
}
|
|
286
|
+
const trimmed = buf.trim();
|
|
287
|
+
if (trimmed) {
|
|
288
|
+
result.push(trimmed.endsWith(';') ? trimmed : trimmed + ';');
|
|
289
|
+
}
|
|
290
|
+
buf = '';
|
|
291
|
+
}
|
|
292
|
+
return result;
|
|
293
|
+
};
|
|
269
294
|
if (blank) {
|
|
270
295
|
up.push('select 1');
|
|
271
296
|
down.push('select 1');
|
|
272
297
|
}
|
|
273
298
|
else if (initial) {
|
|
274
299
|
const dump = await this.schemaGenerator.getCreateSchemaSQL({ wrap: false });
|
|
275
|
-
up.push(...dump
|
|
300
|
+
up.push(...splitStatements(dump));
|
|
276
301
|
}
|
|
277
302
|
else {
|
|
278
303
|
const diff = await this.schemaGenerator.getUpdateSchemaMigrationSQL({
|
|
@@ -281,8 +306,8 @@ class Migrator {
|
|
|
281
306
|
dropTables: this.options.dropTables,
|
|
282
307
|
fromSchema: this.getSchemaFromSnapshot(),
|
|
283
308
|
});
|
|
284
|
-
up.push(...diff.up
|
|
285
|
-
down.push(...diff.down
|
|
309
|
+
up.push(...splitStatements(diff.up));
|
|
310
|
+
down.push(...splitStatements(diff.down));
|
|
286
311
|
}
|
|
287
312
|
const cleanUp = (diff) => {
|
|
288
313
|
for (let i = diff.length - 1; i >= 0; i--) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/migrations",
|
|
3
|
-
"version": "6.6.7-dev.
|
|
3
|
+
"version": "6.6.7-dev.5",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@mikro-orm/knex": "6.6.7-dev.
|
|
61
|
+
"@mikro-orm/knex": "6.6.7-dev.5",
|
|
62
62
|
"fs-extra": "11.3.3",
|
|
63
63
|
"umzug": "3.8.2"
|
|
64
64
|
},
|
|
@@ -66,6 +66,6 @@
|
|
|
66
66
|
"@mikro-orm/core": "^6.6.6"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.6.7-dev.
|
|
69
|
+
"@mikro-orm/core": "6.6.7-dev.5"
|
|
70
70
|
}
|
|
71
71
|
}
|