Skip to content

Commit e479f3f

Browse files
committed
fix(migrations): use table object instead of string for indices and foreign keys
1 parent ff2eebe commit e479f3f

6 files changed

Lines changed: 31 additions & 21 deletions

src/migrations/1748600000000-add-course-bulk-operations.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export class AddCourseBulkOperations1748600000000 implements MigrationInterface
6363
true,
6464
);
6565

66-
await queryRunner.createIndices('course_bulk_operations', [
66+
const bulkOpsTable = (await queryRunner.getTable('course_bulk_operations'))!;
67+
await queryRunner.createIndices(bulkOpsTable, [
6768
new TableIndex({
6869
name: 'IDX_course_bulk_ops_initiator',
6970
columnNames: ['initiated_by_id'],
@@ -75,7 +76,7 @@ export class AddCourseBulkOperations1748600000000 implements MigrationInterface
7576
]);
7677

7778
await queryRunner.createForeignKey(
78-
'course_bulk_operations',
79+
bulkOpsTable,
7980
new TableForeignKey({
8081
name: 'FK_course_bulk_ops_initiator',
8182
columnNames: ['initiated_by_id'],

src/migrations/1748700000000-add-grading-system.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export class AddGradingSystem1748700000000 implements MigrationInterface {
6363
true,
6464
);
6565

66-
await queryRunner.createIndices('rubrics', [
66+
const rubricsTable = (await queryRunner.getTable('rubrics'))!;
67+
await queryRunner.createIndices(rubricsTable, [
6768
new TableIndex({ name: 'IDX_rubrics_name', columnNames: ['name'] }),
6869
new TableIndex({ name: 'IDX_rubrics_owner', columnNames: ['owner_id'] }),
6970
new TableIndex({
@@ -103,16 +104,17 @@ export class AddGradingSystem1748700000000 implements MigrationInterface {
103104
true,
104105
);
105106

107+
const rubricCriteriaTable = (await queryRunner.getTable('rubric_criteria'))!;
106108
await queryRunner.createIndex(
107-
'rubric_criteria',
109+
rubricCriteriaTable,
108110
new TableIndex({
109111
name: 'IDX_rubric_criteria_rubric',
110112
columnNames: ['rubric_id'],
111113
}),
112114
);
113115

114116
await queryRunner.createForeignKey(
115-
'rubric_criteria',
117+
rubricCriteriaTable,
116118
new TableForeignKey({
117119
name: 'FK_rubric_criteria_rubric',
118120
columnNames: ['rubric_id'],
@@ -152,16 +154,17 @@ export class AddGradingSystem1748700000000 implements MigrationInterface {
152154
true,
153155
);
154156

157+
const rubricLevelsTable = (await queryRunner.getTable('rubric_levels'))!;
155158
await queryRunner.createIndex(
156-
'rubric_levels',
159+
rubricLevelsTable,
157160
new TableIndex({
158161
name: 'IDX_rubric_levels_criterion',
159162
columnNames: ['criterion_id'],
160163
}),
161164
);
162165

163166
await queryRunner.createForeignKey(
164-
'rubric_levels',
167+
rubricLevelsTable,
165168
new TableForeignKey({
166169
name: 'FK_rubric_levels_criterion',
167170
columnNames: ['criterion_id'],
@@ -197,7 +200,8 @@ export class AddGradingSystem1748700000000 implements MigrationInterface {
197200
true,
198201
);
199202

200-
await queryRunner.createIndices('feedback_templates', [
203+
const feedbackTemplatesTable = (await queryRunner.getTable('feedback_templates'))!;
204+
await queryRunner.createIndices(feedbackTemplatesTable, [
201205
new TableIndex({
202206
name: 'IDX_feedback_templates_name',
203207
columnNames: ['name'],
@@ -260,7 +264,8 @@ export class AddGradingSystem1748700000000 implements MigrationInterface {
260264
true,
261265
);
262266

263-
await queryRunner.createIndices('submission_grades', [
267+
const submissionGradesTable = (await queryRunner.getTable('submission_grades'))!;
268+
await queryRunner.createIndices(submissionGradesTable, [
264269
new TableIndex({
265270
name: 'IDX_submission_grades_attempt',
266271
columnNames: ['attempt_id'],
@@ -272,15 +277,15 @@ export class AddGradingSystem1748700000000 implements MigrationInterface {
272277
]);
273278

274279
await queryRunner.createUniqueConstraint(
275-
'submission_grades',
280+
submissionGradesTable,
276281
new TableUnique({
277282
name: 'UQ_submission_grade_attempt',
278283
columnNames: ['attempt_id'],
279284
}),
280285
);
281286

282287
await queryRunner.createForeignKey(
283-
'submission_grades',
288+
submissionGradesTable,
284289
new TableForeignKey({
285290
name: 'FK_submission_grades_rubric',
286291
columnNames: ['rubric_id'],
@@ -320,7 +325,8 @@ export class AddGradingSystem1748700000000 implements MigrationInterface {
320325
true,
321326
);
322327

323-
await queryRunner.createIndices('criterion_grades', [
328+
const criterionGradesTable = (await queryRunner.getTable('criterion_grades'))!;
329+
await queryRunner.createIndices(criterionGradesTable, [
324330
new TableIndex({
325331
name: 'IDX_criterion_grades_grade',
326332
columnNames: ['grade_id'],
@@ -332,15 +338,15 @@ export class AddGradingSystem1748700000000 implements MigrationInterface {
332338
]);
333339

334340
await queryRunner.createUniqueConstraint(
335-
'criterion_grades',
341+
criterionGradesTable,
336342
new TableUnique({
337343
name: 'UQ_criterion_grade_per_grade',
338344
columnNames: ['grade_id', 'criterion_id'],
339345
}),
340346
);
341347

342348
await queryRunner.createForeignKey(
343-
'criterion_grades',
349+
criterionGradesTable,
344350
new TableForeignKey({
345351
name: 'FK_criterion_grades_grade',
346352
columnNames: ['grade_id'],

src/migrations/1748800000000-add-gamification-tiers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ export class AddGamificationTiers1748800000000 implements MigrationInterface {
5151
true,
5252
);
5353

54+
const tierRewardsTable = (await queryRunner.getTable('tier_rewards'))!;
5455
await queryRunner.createIndex(
55-
'tier_rewards',
56+
tierRewardsTable,
5657
new TableIndex({ name: 'IDX_tier_rewards_tier', columnNames: ['tier'] }),
5758
);
5859
}

src/migrations/1762000000000-create-audit-log-table.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ export class CreateAuditLogTable1762000000000 implements MigrationInterface {
140140
true,
141141
);
142142

143-
await queryRunner.createIndices('audit_logs', [
143+
const auditLogsTable = (await queryRunner.getTable('audit_logs'))!;
144+
await queryRunner.createIndices(auditLogsTable, [
144145
new TableIndex({
145146
name: 'IDX_audit_logs_user_timestamp',
146147
columnNames: ['user_id', 'timestamp'],

src/migrations/1796000000000-add-invoice-tax-columns.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class AddInvoiceTaxColumns1796000000000 implements MigrationInterface {
2121

2222
if (!table.findColumnByName('taxRate')) {
2323
await queryRunner.addColumn(
24-
'invoices',
24+
table,
2525
new TableColumn({
2626
name: 'taxRate',
2727
type: 'numeric',
@@ -34,7 +34,7 @@ export class AddInvoiceTaxColumns1796000000000 implements MigrationInterface {
3434

3535
if (!table.findColumnByName('taxJurisdiction')) {
3636
await queryRunner.addColumn(
37-
'invoices',
37+
table,
3838
new TableColumn({
3939
name: 'taxJurisdiction',
4040
type: 'varchar',
@@ -53,11 +53,11 @@ export class AddInvoiceTaxColumns1796000000000 implements MigrationInterface {
5353
}
5454

5555
if (table.findColumnByName('taxJurisdiction')) {
56-
await queryRunner.dropColumn('invoices', 'taxJurisdiction');
56+
await queryRunner.dropColumn(table, 'taxJurisdiction');
5757
}
5858

5959
if (table.findColumnByName('taxRate')) {
60-
await queryRunner.dropColumn('invoices', 'taxRate');
60+
await queryRunner.dropColumn(table, 'taxRate');
6161
}
6262
}
6363
}

src/migrations/1800000000000-add-notification-preferences-indexes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { MigrationInterface, QueryRunner, TableIndex } from 'typeorm';
22

33
export class AddNotificationPreferencesIndexes1800000000000 implements MigrationInterface {
44
public async up(queryRunner: QueryRunner): Promise<void> {
5-
await queryRunner.createIndices('notification_preferences', [
5+
const table = (await queryRunner.getTable('notification_preferences'))!;
6+
await queryRunner.createIndices(table, [
67
new TableIndex({
78
name: 'IDX_notification_preferences_user_id',
89
columnNames: ['userId'],

0 commit comments

Comments
 (0)