masterrecord 0.3.47 ā 0.3.49
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/migrations.js +6 -11
- package/Migrations/schema.js +63 -64
- package/context.js +1 -1
- package/package.json +1 -1
- package/readme.md +9 -728
- package/test/v0.3.34-bug-fixes-test.js +50 -8
|
@@ -116,7 +116,7 @@ test('Query builders correctly skip indexes property', () => {
|
|
|
116
116
|
// =============================================================================
|
|
117
117
|
console.log("\nš Test Suite 2: Index Creation with Await Keywords\n");
|
|
118
118
|
|
|
119
|
-
test('createIndex
|
|
119
|
+
test('New tables do NOT generate separate createIndex calls (createTable handles them)', () => {
|
|
120
120
|
const migrations = new Migrations();
|
|
121
121
|
const oldSchema = [];
|
|
122
122
|
const newSchema = [{
|
|
@@ -127,12 +127,12 @@ test('createIndex generates code with await keyword', () => {
|
|
|
127
127
|
|
|
128
128
|
const migrationCode = migrations.template('TestMigration', oldSchema, newSchema);
|
|
129
129
|
|
|
130
|
+
// For new tables, createTable() in schema.js handles indexes - no separate calls needed
|
|
130
131
|
const createIndexMatches = migrationCode.match(/await this\.createIndex/g);
|
|
131
|
-
assert(createIndexMatches
|
|
132
|
-
assert(!migrationCode.match(/\n\s+this\.createIndex\(/), 'Should not have createIndex without await');
|
|
132
|
+
assert(!createIndexMatches, 'New tables should NOT have separate createIndex calls');
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
-
test('createCompositeIndex
|
|
135
|
+
test('New tables do NOT generate separate createCompositeIndex calls (createTable handles them)', () => {
|
|
136
136
|
const migrations = new Migrations();
|
|
137
137
|
const oldSchema = [];
|
|
138
138
|
const newSchema = [{
|
|
@@ -147,8 +147,50 @@ test('createCompositeIndex generates code with await keyword', () => {
|
|
|
147
147
|
|
|
148
148
|
const migrationCode = migrations.template('TestMigration', oldSchema, newSchema);
|
|
149
149
|
|
|
150
|
+
// For new tables, createTable() in schema.js handles composite indexes
|
|
150
151
|
const compositeMatches = migrationCode.match(/await this\.createCompositeIndex/g);
|
|
151
|
-
assert(compositeMatches
|
|
152
|
+
assert(!compositeMatches, 'New tables should NOT have separate createCompositeIndex calls');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('Adding index to EXISTING table generates createIndex with await', () => {
|
|
156
|
+
const migrations = new Migrations();
|
|
157
|
+
const oldSchema = [{
|
|
158
|
+
__name: 'User',
|
|
159
|
+
id: { name: 'id', type: 'integer', primaryKey: true },
|
|
160
|
+
email: { name: 'email', type: 'text' }
|
|
161
|
+
}];
|
|
162
|
+
const newSchema = [{
|
|
163
|
+
__name: 'User',
|
|
164
|
+
id: { name: 'id', type: 'integer', primaryKey: true },
|
|
165
|
+
email: { name: 'email', type: 'text', indexes: ['idx_user_email'] }
|
|
166
|
+
}];
|
|
167
|
+
|
|
168
|
+
const migrationCode = migrations.template('TestMigration', oldSchema, newSchema);
|
|
169
|
+
|
|
170
|
+
const createIndexMatches = migrationCode.match(/await this\.createIndex/g);
|
|
171
|
+
assert(createIndexMatches && createIndexMatches.length > 0, 'Existing table with new index should have createIndex with await');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('Adding composite index to EXISTING table generates createCompositeIndex with await', () => {
|
|
175
|
+
const migrations = new Migrations();
|
|
176
|
+
const oldSchema = [{
|
|
177
|
+
__name: 'User',
|
|
178
|
+
id: { name: 'id', type: 'integer', primaryKey: true }
|
|
179
|
+
}];
|
|
180
|
+
const newSchema = [{
|
|
181
|
+
__name: 'User',
|
|
182
|
+
id: { name: 'id', type: 'integer', primaryKey: true },
|
|
183
|
+
__compositeIndexes: [{
|
|
184
|
+
name: 'idx_composite',
|
|
185
|
+
columns: ['col1', 'col2'],
|
|
186
|
+
unique: false
|
|
187
|
+
}]
|
|
188
|
+
}];
|
|
189
|
+
|
|
190
|
+
const migrationCode = migrations.template('TestMigration', oldSchema, newSchema);
|
|
191
|
+
|
|
192
|
+
const compositeMatches = migrationCode.match(/await this\.createCompositeIndex/g);
|
|
193
|
+
assert(compositeMatches && compositeMatches.length > 0, 'Existing table with new composite index should have createCompositeIndex with await');
|
|
152
194
|
});
|
|
153
195
|
|
|
154
196
|
// =============================================================================
|
|
@@ -286,9 +328,9 @@ test('Complex scenario: Multiple tables with seed data, indexes, and composite i
|
|
|
286
328
|
assert(migrationCode.includes("this.seed('Settings'"), 'Should use this.seed() for Settings');
|
|
287
329
|
assert(!migrationCode.includes('table.Settings.create'), 'Should NOT use table.Settings.create');
|
|
288
330
|
|
|
289
|
-
//
|
|
290
|
-
assert(migrationCode.includes('await this.createIndex'), '
|
|
291
|
-
assert(migrationCode.includes('await this.createCompositeIndex'), '
|
|
331
|
+
// For new tables, createTable() handles indexes ā no separate calls in template
|
|
332
|
+
assert(!migrationCode.includes('await this.createIndex'), 'New tables should not have separate createIndex calls');
|
|
333
|
+
assert(!migrationCode.includes('await this.createCompositeIndex'), 'New tables should not have separate createCompositeIndex calls');
|
|
292
334
|
});
|
|
293
335
|
|
|
294
336
|
// =============================================================================
|