masterrecord 0.3.47 → 0.3.48
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/Migrations/migrationTemplate.js +12 -12
- package/Migrations/schema.js +63 -64
- package/context.js +1 -1
- package/package.json +1 -1
- package/readme.md +21 -0
|
@@ -39,10 +39,10 @@ module.exports = ${this.name};
|
|
|
39
39
|
|
|
40
40
|
alterColumn(type, name, parent){
|
|
41
41
|
if(type === "up"){
|
|
42
|
-
this.#up += os.EOL + ` this.alterColumn(table.${name});`
|
|
42
|
+
this.#up += os.EOL + ` await this.alterColumn(table.${name});`
|
|
43
43
|
}
|
|
44
44
|
else{
|
|
45
|
-
this.#down += os.EOL + ` this.alterColumn(table.${name});`
|
|
45
|
+
this.#down += os.EOL + ` await this.alterColumn(table.${name});`
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
createTable(type, name){
|
|
@@ -56,29 +56,29 @@ module.exports = ${this.name};
|
|
|
56
56
|
|
|
57
57
|
addColumn(type, name, parent){
|
|
58
58
|
if(type === "up"){
|
|
59
|
-
this.#up += os.EOL + ` this.addColumn(table.${name});`
|
|
59
|
+
this.#up += os.EOL + ` await this.addColumn(table.${name});`
|
|
60
60
|
}
|
|
61
61
|
else{
|
|
62
|
-
this.#down += os.EOL + ` this.addColumn(table.${name});`
|
|
62
|
+
this.#down += os.EOL + ` await this.addColumn(table.${name});`
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
//this.addColumn(table.${parent}.${name});`
|
|
66
66
|
|
|
67
67
|
dropTable(type, name){
|
|
68
68
|
if(type === "up"){
|
|
69
|
-
this.#down += os.EOL + ` this.dropTable(table.${name});`
|
|
69
|
+
this.#down += os.EOL + ` await this.dropTable(table.${name});`
|
|
70
70
|
}
|
|
71
71
|
else{
|
|
72
|
-
this.#down += os.EOL + ` this.dropTable(table.${name});`
|
|
72
|
+
this.#down += os.EOL + ` await this.dropTable(table.${name});`
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
dropColumn(type, name, parent){
|
|
77
77
|
if(type === "up"){
|
|
78
|
-
this.#up += os.EOL + ` this.dropColumn(table.${name});`
|
|
78
|
+
this.#up += os.EOL + ` await this.dropColumn(table.${name});`
|
|
79
79
|
}
|
|
80
80
|
else{
|
|
81
|
-
this.#down += os.EOL + ` this.dropColumn(table.${name});`
|
|
81
|
+
this.#down += os.EOL + ` await this.dropColumn(table.${name});`
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -187,7 +187,7 @@ module.exports = ${this.name};
|
|
|
187
187
|
|
|
188
188
|
this.#up += os.EOL + ` ];`;
|
|
189
189
|
this.#up += os.EOL + ` for (const record of factoryRecords) {`;
|
|
190
|
-
this.#up += os.EOL + ` this.seed('${tableName}', record);`;
|
|
190
|
+
this.#up += os.EOL + ` await this.seed('${tableName}', record);`;
|
|
191
191
|
this.#up += os.EOL + ` }`;
|
|
192
192
|
} else {
|
|
193
193
|
// Standard individual inserts for non-factory or small batches
|
|
@@ -214,10 +214,10 @@ module.exports = ${this.name};
|
|
|
214
214
|
const formattedRecord = JSON.stringify(cleanRecord, null, 12)
|
|
215
215
|
.split('\n')
|
|
216
216
|
.join(os.EOL + ' ');
|
|
217
|
-
this.#up += os.EOL + ` this.seed('${tableName}', ${formattedRecord});`;
|
|
217
|
+
this.#up += os.EOL + ` await this.seed('${tableName}', ${formattedRecord});`;
|
|
218
218
|
} else {
|
|
219
219
|
// Single-line format
|
|
220
|
-
this.#up += os.EOL + ` this.seed('${tableName}', ${recordStr});`;
|
|
220
|
+
this.#up += os.EOL + ` await this.seed('${tableName}', ${recordStr});`;
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
});
|
|
@@ -257,7 +257,7 @@ module.exports = ${this.name};
|
|
|
257
257
|
|
|
258
258
|
this.#up += os.EOL + ` await existing.save();`;
|
|
259
259
|
this.#up += os.EOL + ` } else {`;
|
|
260
|
-
this.#up += os.EOL + ` this.seed('${tableName}', ${JSON.stringify(cleanRecord)});`;
|
|
260
|
+
this.#up += os.EOL + ` await this.seed('${tableName}', ${JSON.stringify(cleanRecord)});`;
|
|
261
261
|
this.#up += os.EOL + ` }`;
|
|
262
262
|
this.#up += os.EOL + ` }`;
|
|
263
263
|
}
|
package/Migrations/schema.js
CHANGED
|
@@ -158,7 +158,7 @@ class schema{
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
// create obj to convert into create sql
|
|
161
|
-
addColumn(table){
|
|
161
|
+
async addColumn(table){
|
|
162
162
|
// todo need to work on add column for mysql
|
|
163
163
|
if(table){
|
|
164
164
|
if(this.context.isSQLite){
|
|
@@ -168,7 +168,7 @@ class schema{
|
|
|
168
168
|
// This allows explicit column definitions to work, not just CLI-generated migrations
|
|
169
169
|
// Note: No need to set table.realDataType - columnMapping handles type conversion internally
|
|
170
170
|
var query = queryBuilder.addColum(table);
|
|
171
|
-
this.context._execute(query);
|
|
171
|
+
await this.context._execute(query);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
if(this.context.isMySQL){
|
|
@@ -176,7 +176,7 @@ class schema{
|
|
|
176
176
|
var queryBuilder = new sqlquery();
|
|
177
177
|
// Note: No need to set table.realDataType - columnMapping handles type conversion internally
|
|
178
178
|
var query = queryBuilder.addColum(table);
|
|
179
|
-
this.context._execute(query);
|
|
179
|
+
await this.context._execute(query);
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
if(this.context.isPostgres){
|
|
@@ -184,14 +184,14 @@ class schema{
|
|
|
184
184
|
var queryBuilder = new postgresQuery();
|
|
185
185
|
// Note: No need to set table.realDataType - columnMapping handles type conversion internally
|
|
186
186
|
var query = queryBuilder.addColum(table);
|
|
187
|
-
this.context._execute(query);
|
|
187
|
+
await this.context._execute(query);
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
// add column to database
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
dropColumn(table){
|
|
194
|
+
async dropColumn(table){
|
|
195
195
|
if(table){
|
|
196
196
|
if(this.fullTable){
|
|
197
197
|
// drop column
|
|
@@ -199,21 +199,21 @@ class schema{
|
|
|
199
199
|
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
200
200
|
var queryBuilder = new sqliteQuery();
|
|
201
201
|
var query = queryBuilder.dropColumn(table);
|
|
202
|
-
this.context._execute(query);
|
|
202
|
+
await this.context._execute(query);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
if(this.context.isMySQL){
|
|
206
206
|
var sqlquery = require("./migrationMySQLQuery");
|
|
207
207
|
var queryBuilder = new sqlquery();
|
|
208
208
|
var query = queryBuilder.dropColumn(table);
|
|
209
|
-
this.context._execute(query);
|
|
209
|
+
await this.context._execute(query);
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
if(this.context.isPostgres){
|
|
213
213
|
var postgresQuery = require("./migrationPostgresQuery");
|
|
214
214
|
var queryBuilder = new postgresQuery();
|
|
215
215
|
var query = queryBuilder.dropColumn(table);
|
|
216
|
-
this.context._execute(query);
|
|
216
|
+
await this.context._execute(query);
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
}else{
|
|
@@ -237,50 +237,49 @@ class schema{
|
|
|
237
237
|
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
238
238
|
var queryBuilder = new sqliteQuery();
|
|
239
239
|
var query = queryBuilder.createTable(table);
|
|
240
|
-
this.context._execute(query);
|
|
240
|
+
await this.context._execute(query);
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
if(this.context.isMySQL){
|
|
244
244
|
var sqlquery = require("./migrationMySQLQuery");
|
|
245
245
|
var queryBuilder = new sqlquery();
|
|
246
246
|
var query = queryBuilder.createTable(table);
|
|
247
|
-
this.context._execute(query);
|
|
247
|
+
await this.context._execute(query);
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
if(this.context.isPostgres){
|
|
251
251
|
var postgresQuery = require("./migrationPostgresQuery");
|
|
252
252
|
var queryBuilder = new postgresQuery();
|
|
253
253
|
var query = queryBuilder.createTable(table);
|
|
254
|
-
this.context._execute(query);
|
|
254
|
+
await this.context._execute(query);
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
// Create indexes for columns that have .index() defined
|
|
258
|
-
const
|
|
259
|
-
Object.keys(table).forEach(function(key){
|
|
258
|
+
for(const key of Object.keys(table)){
|
|
260
259
|
if(typeof table[key] === "object" && table[key].indexes && !key.startsWith('__')){
|
|
261
260
|
const columnName = table[key].name;
|
|
262
|
-
table[key].indexes
|
|
261
|
+
for(const indexName of table[key].indexes){
|
|
263
262
|
const indexInfo = {
|
|
264
263
|
tableName: tableName,
|
|
265
264
|
columnName: columnName,
|
|
266
265
|
indexName: indexName
|
|
267
266
|
};
|
|
268
|
-
|
|
269
|
-
}
|
|
267
|
+
await this.createIndex(indexInfo);
|
|
268
|
+
}
|
|
270
269
|
}
|
|
271
|
-
}
|
|
270
|
+
}
|
|
272
271
|
|
|
273
272
|
// Create composite indexes
|
|
274
273
|
if (table.__compositeIndexes) {
|
|
275
|
-
table.__compositeIndexes
|
|
274
|
+
for(const compositeIdx of table.__compositeIndexes){
|
|
276
275
|
const indexInfo = {
|
|
277
276
|
tableName: tableName,
|
|
278
277
|
columns: compositeIdx.columns,
|
|
279
278
|
indexName: compositeIdx.name,
|
|
280
279
|
unique: compositeIdx.unique
|
|
281
280
|
};
|
|
282
|
-
|
|
283
|
-
}
|
|
281
|
+
await this.createCompositeIndex(indexInfo);
|
|
282
|
+
}
|
|
284
283
|
}
|
|
285
284
|
}
|
|
286
285
|
}else{
|
|
@@ -319,21 +318,21 @@ class schema{
|
|
|
319
318
|
var queryBuilder = new sqliteQuery();
|
|
320
319
|
// Build a conservative column add (no NOT NULL without default)
|
|
321
320
|
const add = queryBuilder.addColum({ tableName, name: colName });
|
|
322
|
-
this.context._execute(add);
|
|
321
|
+
await this.context._execute(add);
|
|
323
322
|
}
|
|
324
323
|
if(this.context.isMySQL){
|
|
325
324
|
var sqlquery = require("./migrationMySQLQuery");
|
|
326
325
|
var queryBuilder = new sqlquery();
|
|
327
326
|
newCol.realDataType = queryBuilder.typeManager(col.type);
|
|
328
327
|
const query = queryBuilder.addColum(newCol);
|
|
329
|
-
this.context._execute(query);
|
|
328
|
+
await this.context._execute(query);
|
|
330
329
|
}
|
|
331
330
|
if(this.context.isPostgres){
|
|
332
331
|
var postgresQuery = require("./migrationPostgresQuery");
|
|
333
332
|
var queryBuilder = new postgresQuery();
|
|
334
333
|
newCol.realDataType = queryBuilder.typeManager(col.type);
|
|
335
334
|
const query = queryBuilder.addColum(newCol);
|
|
336
|
-
this.context._execute(query);
|
|
335
|
+
await this.context._execute(query);
|
|
337
336
|
}
|
|
338
337
|
}
|
|
339
338
|
}
|
|
@@ -417,7 +416,7 @@ class schema{
|
|
|
417
416
|
defPart = ' DEFAULT NULL';
|
|
418
417
|
}
|
|
419
418
|
const alter = `ALTER TABLE ${tableName} MODIFY COLUMN ${d.name} ${type} ${nullPart}${defPart}`;
|
|
420
|
-
this.context._execute(alter);
|
|
419
|
+
await this.context._execute(alter);
|
|
421
420
|
}
|
|
422
421
|
}
|
|
423
422
|
}
|
|
@@ -427,10 +426,10 @@ class schema{
|
|
|
427
426
|
var queryBuilder = new sqliteQuery();
|
|
428
427
|
// rename old table
|
|
429
428
|
const rename = queryBuilder.renameTable({ tableName, newName: "_temp_alter_column_update" });
|
|
430
|
-
this.context._execute(rename);
|
|
429
|
+
await this.context._execute(rename);
|
|
431
430
|
// create new with desired schema
|
|
432
431
|
const create = queryBuilder.createTable(table);
|
|
433
|
-
this.context._execute(create);
|
|
432
|
+
await this.context._execute(create);
|
|
434
433
|
// compute common columns
|
|
435
434
|
const oldInfo = await engine.getTableInfo(tableName.replace(/.*/, '_temp_alter_column_update')) || await engine.getTableInfo("_temp_alter_column_update");
|
|
436
435
|
const oldNames = new Set((oldInfo || existing).map(r => r.name));
|
|
@@ -439,35 +438,35 @@ class schema{
|
|
|
439
438
|
if(common.length > 0){
|
|
440
439
|
const cols = common.join(',');
|
|
441
440
|
const insert = `INSERT INTO ${tableName} (${cols}) SELECT ${cols} FROM _temp_alter_column_update`;
|
|
442
|
-
this.context._execute(insert);
|
|
441
|
+
await this.context._execute(insert);
|
|
443
442
|
}
|
|
444
443
|
const drop = queryBuilder.dropTable("_temp_alter_column_update");
|
|
445
|
-
this.context._execute(drop);
|
|
444
|
+
await this.context._execute(drop);
|
|
446
445
|
}
|
|
447
446
|
}
|
|
448
447
|
|
|
449
448
|
|
|
450
|
-
dropTable(table){
|
|
449
|
+
async dropTable(table){
|
|
451
450
|
if(table){
|
|
452
451
|
if(this.context.isSQLite){
|
|
453
452
|
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
454
453
|
var queryBuilder = new sqliteQuery();
|
|
455
454
|
var query = queryBuilder.dropTable(table.__name);
|
|
456
|
-
this.context._execute(query);
|
|
455
|
+
await this.context._execute(query);
|
|
457
456
|
}
|
|
458
457
|
|
|
459
458
|
if(this.context.isMySQL){
|
|
460
459
|
var sqlquery = require("./migrationMySQLQuery");
|
|
461
460
|
var queryBuilder = new sqlquery();
|
|
462
461
|
var query = queryBuilder.dropTable(table.__name);
|
|
463
|
-
this.context._execute(query);
|
|
462
|
+
await this.context._execute(query);
|
|
464
463
|
}
|
|
465
464
|
|
|
466
465
|
if(this.context.isPostgres){
|
|
467
466
|
var postgresQuery = require("./migrationPostgresQuery");
|
|
468
467
|
var queryBuilder = new postgresQuery();
|
|
469
468
|
var query = queryBuilder.dropTable(table.__name);
|
|
470
|
-
this.context._execute(query);
|
|
469
|
+
await this.context._execute(query);
|
|
471
470
|
}
|
|
472
471
|
}
|
|
473
472
|
}
|
|
@@ -485,7 +484,7 @@ class schema{
|
|
|
485
484
|
|
|
486
485
|
|
|
487
486
|
//"dbo.People", "Location"
|
|
488
|
-
alterColumn(table){
|
|
487
|
+
async alterColumn(table){
|
|
489
488
|
if(table){
|
|
490
489
|
if(this.fullTable){
|
|
491
490
|
if(this.context.isSQLite){
|
|
@@ -494,7 +493,7 @@ class schema{
|
|
|
494
493
|
var queryObj = queryBuilder.alterColumn(this.fullTable.new, table);
|
|
495
494
|
for (var key in queryObj) {
|
|
496
495
|
var query = queryObj[key];
|
|
497
|
-
this.context._execute(query);
|
|
496
|
+
await this.context._execute(query);
|
|
498
497
|
}
|
|
499
498
|
}
|
|
500
499
|
|
|
@@ -502,14 +501,14 @@ class schema{
|
|
|
502
501
|
var sqlquery = require("./migrationMySQLQuery");
|
|
503
502
|
var queryBuilder = new sqlquery();
|
|
504
503
|
var query = queryBuilder.alterColumn(table);
|
|
505
|
-
this.context._execute(query);
|
|
504
|
+
await this.context._execute(query);
|
|
506
505
|
}
|
|
507
506
|
|
|
508
507
|
if(this.context.isPostgres){
|
|
509
508
|
var postgresQuery = require("./migrationPostgresQuery");
|
|
510
509
|
var queryBuilder = new postgresQuery();
|
|
511
510
|
var query = queryBuilder.alterColumn(table);
|
|
512
|
-
this.context._execute(query);
|
|
511
|
+
await this.context._execute(query);
|
|
513
512
|
}
|
|
514
513
|
|
|
515
514
|
}else{
|
|
@@ -518,132 +517,132 @@ class schema{
|
|
|
518
517
|
}
|
|
519
518
|
}
|
|
520
519
|
|
|
521
|
-
renameColumn(table){
|
|
520
|
+
async renameColumn(table){
|
|
522
521
|
if(table){
|
|
523
522
|
if(this.context.isSQLite){
|
|
524
523
|
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
525
524
|
var queryBuilder = new sqliteQuery();
|
|
526
525
|
var query = queryBuilder.renameColumn(table);
|
|
527
|
-
this.context._execute(query);
|
|
526
|
+
await this.context._execute(query);
|
|
528
527
|
}
|
|
529
528
|
|
|
530
529
|
if(this.context.isMySQL){
|
|
531
530
|
var sqlquery = require("./migrationMySQLQuery");
|
|
532
531
|
var queryBuilder = new sqlquery();
|
|
533
532
|
var query = queryBuilder.renameColumn(table);
|
|
534
|
-
this.context._execute(query);
|
|
533
|
+
await this.context._execute(query);
|
|
535
534
|
}
|
|
536
535
|
|
|
537
536
|
if(this.context.isPostgres){
|
|
538
537
|
var postgresQuery = require("./migrationPostgresQuery");
|
|
539
538
|
var queryBuilder = new postgresQuery();
|
|
540
539
|
var query = queryBuilder.renameColumn(table);
|
|
541
|
-
this.context._execute(query);
|
|
540
|
+
await this.context._execute(query);
|
|
542
541
|
}
|
|
543
542
|
}
|
|
544
543
|
}
|
|
545
544
|
|
|
546
|
-
createIndex(indexInfo){
|
|
545
|
+
async createIndex(indexInfo){
|
|
547
546
|
if(indexInfo){
|
|
548
547
|
if(this.context.isSQLite){
|
|
549
548
|
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
550
549
|
var queryBuilder = new sqliteQuery();
|
|
551
550
|
var query = queryBuilder.createIndex(indexInfo);
|
|
552
|
-
this.context._execute(query);
|
|
551
|
+
await this.context._execute(query);
|
|
553
552
|
}
|
|
554
553
|
|
|
555
554
|
if(this.context.isMySQL){
|
|
556
555
|
var sqlquery = require("./migrationMySQLQuery");
|
|
557
556
|
var queryBuilder = new sqlquery();
|
|
558
557
|
var query = queryBuilder.createIndex(indexInfo);
|
|
559
|
-
this.context._execute(query);
|
|
558
|
+
await this.context._execute(query);
|
|
560
559
|
}
|
|
561
560
|
|
|
562
561
|
if(this.context.isPostgres){
|
|
563
562
|
var postgresQuery = require("./migrationPostgresQuery");
|
|
564
563
|
var queryBuilder = new postgresQuery();
|
|
565
564
|
var query = queryBuilder.createIndex(indexInfo);
|
|
566
|
-
this.context._execute(query);
|
|
565
|
+
await this.context._execute(query);
|
|
567
566
|
}
|
|
568
567
|
}
|
|
569
568
|
}
|
|
570
569
|
|
|
571
|
-
dropIndex(indexInfo){
|
|
570
|
+
async dropIndex(indexInfo){
|
|
572
571
|
if(indexInfo){
|
|
573
572
|
if(this.context.isSQLite){
|
|
574
573
|
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
575
574
|
var queryBuilder = new sqliteQuery();
|
|
576
575
|
var query = queryBuilder.dropIndex(indexInfo);
|
|
577
|
-
this.context._execute(query);
|
|
576
|
+
await this.context._execute(query);
|
|
578
577
|
}
|
|
579
578
|
|
|
580
579
|
if(this.context.isMySQL){
|
|
581
580
|
var sqlquery = require("./migrationMySQLQuery");
|
|
582
581
|
var queryBuilder = new sqlquery();
|
|
583
582
|
var query = queryBuilder.dropIndex(indexInfo);
|
|
584
|
-
this.context._execute(query);
|
|
583
|
+
await this.context._execute(query);
|
|
585
584
|
}
|
|
586
585
|
|
|
587
586
|
if(this.context.isPostgres){
|
|
588
587
|
var postgresQuery = require("./migrationPostgresQuery");
|
|
589
588
|
var queryBuilder = new postgresQuery();
|
|
590
589
|
var query = queryBuilder.dropIndex(indexInfo);
|
|
591
|
-
this.context._execute(query);
|
|
590
|
+
await this.context._execute(query);
|
|
592
591
|
}
|
|
593
592
|
}
|
|
594
593
|
}
|
|
595
594
|
|
|
596
|
-
createCompositeIndex(indexInfo){
|
|
595
|
+
async createCompositeIndex(indexInfo){
|
|
597
596
|
if(indexInfo){
|
|
598
597
|
if(this.context.isSQLite){
|
|
599
598
|
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
600
599
|
var queryBuilder = new sqliteQuery();
|
|
601
600
|
var query = queryBuilder.createCompositeIndex(indexInfo);
|
|
602
|
-
this.context._execute(query);
|
|
601
|
+
await this.context._execute(query);
|
|
603
602
|
}
|
|
604
603
|
|
|
605
604
|
if(this.context.isMySQL){
|
|
606
605
|
var sqlquery = require("./migrationMySQLQuery");
|
|
607
606
|
var queryBuilder = new sqlquery();
|
|
608
607
|
var query = queryBuilder.createCompositeIndex(indexInfo);
|
|
609
|
-
this.context._execute(query);
|
|
608
|
+
await this.context._execute(query);
|
|
610
609
|
}
|
|
611
610
|
|
|
612
611
|
if(this.context.isPostgres){
|
|
613
612
|
var postgresQuery = require("./migrationPostgresQuery");
|
|
614
613
|
var queryBuilder = new postgresQuery();
|
|
615
614
|
var query = queryBuilder.createCompositeIndex(indexInfo);
|
|
616
|
-
this.context._execute(query);
|
|
615
|
+
await this.context._execute(query);
|
|
617
616
|
}
|
|
618
617
|
}
|
|
619
618
|
}
|
|
620
619
|
|
|
621
|
-
dropCompositeIndex(indexInfo){
|
|
620
|
+
async dropCompositeIndex(indexInfo){
|
|
622
621
|
if(indexInfo){
|
|
623
622
|
if(this.context.isSQLite){
|
|
624
623
|
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
625
624
|
var queryBuilder = new sqliteQuery();
|
|
626
625
|
var query = queryBuilder.dropCompositeIndex(indexInfo);
|
|
627
|
-
this.context._execute(query);
|
|
626
|
+
await this.context._execute(query);
|
|
628
627
|
}
|
|
629
628
|
|
|
630
629
|
if(this.context.isMySQL){
|
|
631
630
|
var sqlquery = require("./migrationMySQLQuery");
|
|
632
631
|
var queryBuilder = new sqlquery();
|
|
633
632
|
var query = queryBuilder.dropCompositeIndex(indexInfo);
|
|
634
|
-
this.context._execute(query);
|
|
633
|
+
await this.context._execute(query);
|
|
635
634
|
}
|
|
636
635
|
|
|
637
636
|
if(this.context.isPostgres){
|
|
638
637
|
var postgresQuery = require("./migrationPostgresQuery");
|
|
639
638
|
var queryBuilder = new postgresQuery();
|
|
640
639
|
var query = queryBuilder.dropCompositeIndex(indexInfo);
|
|
641
|
-
this.context._execute(query);
|
|
640
|
+
await this.context._execute(query);
|
|
642
641
|
}
|
|
643
642
|
}
|
|
644
643
|
}
|
|
645
644
|
|
|
646
|
-
seed(tableName, rows){
|
|
645
|
+
async seed(tableName, rows){
|
|
647
646
|
if(!tableName || !rows){ return; }
|
|
648
647
|
const items = Array.isArray(rows) ? rows : [rows];
|
|
649
648
|
|
|
@@ -655,7 +654,7 @@ class schema{
|
|
|
655
654
|
// SQLite: Use INSERT OR IGNORE for idempotency
|
|
656
655
|
const query = queryBuilder.insertSeedData(tableName, row);
|
|
657
656
|
const idempotentQuery = query.replace(/^INSERT INTO/, 'INSERT OR IGNORE INTO');
|
|
658
|
-
this.context._execute(idempotentQuery);
|
|
657
|
+
await this.context._execute(idempotentQuery);
|
|
659
658
|
}
|
|
660
659
|
}
|
|
661
660
|
|
|
@@ -666,7 +665,7 @@ class schema{
|
|
|
666
665
|
// MySQL: Use INSERT IGNORE for idempotency
|
|
667
666
|
const query = queryBuilder.insertSeedData(tableName, row);
|
|
668
667
|
const idempotentQuery = query.replace(/^INSERT INTO/, 'INSERT IGNORE INTO');
|
|
669
|
-
this.context._execute(idempotentQuery);
|
|
668
|
+
await this.context._execute(idempotentQuery);
|
|
670
669
|
}
|
|
671
670
|
}
|
|
672
671
|
|
|
@@ -678,7 +677,7 @@ class schema{
|
|
|
678
677
|
// Note: This requires a unique constraint or primary key
|
|
679
678
|
const query = queryBuilder.insertSeedData(tableName, row);
|
|
680
679
|
const idempotentQuery = query + ' ON CONFLICT DO NOTHING';
|
|
681
|
-
this.context._execute(idempotentQuery);
|
|
680
|
+
await this.context._execute(idempotentQuery);
|
|
682
681
|
}
|
|
683
682
|
}
|
|
684
683
|
}
|
|
@@ -688,7 +687,7 @@ class schema{
|
|
|
688
687
|
* @param {string} tableName - Name of the table
|
|
689
688
|
* @param {Array} rows - Array of data objects
|
|
690
689
|
*/
|
|
691
|
-
bulkSeed(tableName, rows){
|
|
690
|
+
async bulkSeed(tableName, rows){
|
|
692
691
|
if(!tableName || !rows || rows.length === 0){ return; }
|
|
693
692
|
|
|
694
693
|
if(this.context.isSQLite){
|
|
@@ -697,7 +696,7 @@ class schema{
|
|
|
697
696
|
const query = queryBuilder.bulkInsertSeedData(tableName, rows);
|
|
698
697
|
if(query){
|
|
699
698
|
const idempotentQuery = query.replace(/^INSERT INTO/, 'INSERT OR IGNORE INTO');
|
|
700
|
-
this.context._execute(idempotentQuery);
|
|
699
|
+
await this.context._execute(idempotentQuery);
|
|
701
700
|
}
|
|
702
701
|
}
|
|
703
702
|
|
|
@@ -707,7 +706,7 @@ class schema{
|
|
|
707
706
|
const query = queryBuilder.bulkInsertSeedData(tableName, rows);
|
|
708
707
|
if(query){
|
|
709
708
|
const idempotentQuery = query.replace(/^INSERT INTO/, 'INSERT IGNORE INTO');
|
|
710
|
-
this.context._execute(idempotentQuery);
|
|
709
|
+
await this.context._execute(idempotentQuery);
|
|
711
710
|
}
|
|
712
711
|
}
|
|
713
712
|
|
|
@@ -717,7 +716,7 @@ class schema{
|
|
|
717
716
|
const query = queryBuilder.bulkInsertSeedData(tableName, rows);
|
|
718
717
|
if(query){
|
|
719
718
|
const idempotentQuery = query + ' ON CONFLICT DO NOTHING';
|
|
720
|
-
this.context._execute(idempotentQuery);
|
|
719
|
+
await this.context._execute(idempotentQuery);
|
|
721
720
|
}
|
|
722
721
|
}
|
|
723
722
|
}
|
package/context.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masterrecord",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.48",
|
|
4
4
|
"description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
|
|
5
5
|
"main": "MasterRecord.js",
|
|
6
6
|
"bin": {
|
package/readme.md
CHANGED
|
@@ -3369,6 +3369,27 @@ user.name = null; // Error if name is { nullable: false }
|
|
|
3369
3369
|
|
|
3370
3370
|
## Changelog
|
|
3371
3371
|
|
|
3372
|
+
### Version 0.3.48 (2026-02-20) - FIX: Complete Async Migration Pipeline for MySQL/PostgreSQL
|
|
3373
|
+
|
|
3374
|
+
#### Bug Fixed: Migration methods not properly awaiting async database operations
|
|
3375
|
+
- **FIXED**: All migration schema methods (`createTable`, `addColumn`, `dropColumn`, `dropTable`, `alterColumn`, `renameColumn`, `createIndex`, `dropIndex`, `createCompositeIndex`, `dropCompositeIndex`, `seed`, `bulkSeed`) are now fully `async` and properly `await` all database operations
|
|
3376
|
+
- **Root Cause**: SQLite's `_execute()` is synchronous, but MySQL/PostgreSQL return Promises. Migration methods were calling `this.context._execute()` without `await`, causing operations to run out of order (e.g., CREATE INDEX running before CREATE TABLE finished)
|
|
3377
|
+
- **Solution**: Made all schema methods async, added `await` to every `_execute()` call, converted `forEach` loops to `for...of` for proper async iteration
|
|
3378
|
+
- **FIXED**: `context._execute()` now properly returns the engine's Promise (`return this._SQLEngine._execute(query)`)
|
|
3379
|
+
- **FIXED**: Added `_execute()` method to MySQL and PostgreSQL engines (previously only existed on SQLite)
|
|
3380
|
+
- **FIXED**: `syncTable()` no longer crashes on metadata properties (`indexes`, `__compositeIndexes`) — now filters them out before column iteration
|
|
3381
|
+
- **FIXED**: Migration template now generates `await` for all method calls in migration files
|
|
3382
|
+
- **FIXED**: Unhandled promise rejection crash — MySQL/PostgreSQL `_initPromise` now has `.catch(() => {})` to prevent Node.js crash before `_ensureReady()` can handle errors
|
|
3383
|
+
- **FIXED**: Added `_ready` flag to prevent duplicate `_ensureReady()` execution
|
|
3384
|
+
|
|
3385
|
+
#### Files Modified
|
|
3386
|
+
1. **`Migrations/schema.js`** - All methods async, all `_execute` calls awaited, forEach→for...of, syncTable metadata filtering, `_ready` flag
|
|
3387
|
+
2. **`Migrations/migrationTemplate.js`** - All generated method calls now include `await`
|
|
3388
|
+
3. **`mySQLEngine.js`** - Added `_execute()` method
|
|
3389
|
+
4. **`postgresEngine.js`** - Added `_execute()` method
|
|
3390
|
+
5. **`context.js`** - `_execute()` returns engine result, `.catch()` on `_initPromise`
|
|
3391
|
+
6. **`package.json`** - Updated to v0.3.48
|
|
3392
|
+
|
|
3372
3393
|
### Version 0.3.44 (2026-02-20) - FIX: MySQL/PostgreSQL Auto-Create Database During Migrations
|
|
3373
3394
|
|
|
3374
3395
|
#### Bug Fixed: `update-database` failing when database doesn't exist yet (MySQL & PostgreSQL)
|