Skip to content

Commit 6706433

Browse files
Merge pull request #1376 from Peolite001/fix-1246-user-consent-indexes
fix(gdpr): add indexes to user-consent entity
2 parents 3dda001 + 3f6bf3e commit 6706433

10 files changed

Lines changed: 134 additions & 38 deletions

src/migrations/1685000001000-add-currency-and-location-fields-to-users.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class AddCurrencyAndLocationFieldsToUsers1685000001000 implements Migrati
1515
// Add country field
1616
if (!table.findColumnByName('country')) {
1717
await queryRunner.addColumn(
18-
'users',
18+
table,
1919
new TableColumn({
2020
name: 'country',
2121
type: 'varchar',
@@ -27,7 +27,7 @@ export class AddCurrencyAndLocationFieldsToUsers1685000001000 implements Migrati
2727
// Add countryCode field
2828
if (!table.findColumnByName('country_code')) {
2929
await queryRunner.addColumn(
30-
'users',
30+
table,
3131
new TableColumn({
3232
name: 'country_code',
3333
type: 'varchar',
@@ -37,7 +37,7 @@ export class AddCurrencyAndLocationFieldsToUsers1685000001000 implements Migrati
3737
);
3838
// Add index
3939
await queryRunner.createIndex(
40-
'users',
40+
table,
4141
new TableIndex({
4242
columnNames: ['country_code'],
4343
name: 'IDX_users_country_code',
@@ -48,7 +48,7 @@ export class AddCurrencyAndLocationFieldsToUsers1685000001000 implements Migrati
4848
// Add timezone field
4949
if (!table.findColumnByName('timezone')) {
5050
await queryRunner.addColumn(
51-
'users',
51+
table,
5252
new TableColumn({
5353
name: 'timezone',
5454
type: 'varchar',
@@ -60,7 +60,7 @@ export class AddCurrencyAndLocationFieldsToUsers1685000001000 implements Migrati
6060
// Add city field
6161
if (!table.findColumnByName('city')) {
6262
await queryRunner.addColumn(
63-
'users',
63+
table,
6464
new TableColumn({
6565
name: 'city',
6666
type: 'varchar',
@@ -72,7 +72,7 @@ export class AddCurrencyAndLocationFieldsToUsers1685000001000 implements Migrati
7272
// Add preferredCurrency field
7373
if (!table.findColumnByName('preferred_currency')) {
7474
await queryRunner.addColumn(
75-
'users',
75+
table,
7676
new TableColumn({
7777
name: 'preferred_currency',
7878
type: 'varchar',
@@ -83,7 +83,7 @@ export class AddCurrencyAndLocationFieldsToUsers1685000001000 implements Migrati
8383
);
8484
// Add index
8585
await queryRunner.createIndex(
86-
'users',
86+
table,
8787
new TableIndex({
8888
columnNames: ['preferred_currency'],
8989
name: 'IDX_users_preferred_currency',
@@ -102,35 +102,35 @@ export class AddCurrencyAndLocationFieldsToUsers1685000001000 implements Migrati
102102
// Drop indices first
103103
const countryCodeIndex = table.indices.find((i) => i.name === 'IDX_users_country_code');
104104
if (countryCodeIndex) {
105-
await queryRunner.dropIndex('users', countryCodeIndex);
105+
await queryRunner.dropIndex(table, countryCodeIndex);
106106
}
107107

108108
const preferredCurrencyIndex = table.indices.find(
109109
(i) => i.name === 'IDX_users_preferred_currency',
110110
);
111111
if (preferredCurrencyIndex) {
112-
await queryRunner.dropIndex('users', preferredCurrencyIndex);
112+
await queryRunner.dropIndex(table, preferredCurrencyIndex);
113113
}
114114

115115
// Drop columns
116116
if (table.findColumnByName('country')) {
117-
await queryRunner.dropColumn('users', 'country');
117+
await queryRunner.dropColumn(table, 'country');
118118
}
119119

120120
if (table.findColumnByName('country_code')) {
121-
await queryRunner.dropColumn('users', 'country_code');
121+
await queryRunner.dropColumn(table, 'country_code');
122122
}
123123

124124
if (table.findColumnByName('timezone')) {
125-
await queryRunner.dropColumn('users', 'timezone');
125+
await queryRunner.dropColumn(table, 'timezone');
126126
}
127127

128128
if (table.findColumnByName('city')) {
129-
await queryRunner.dropColumn('users', 'city');
129+
await queryRunner.dropColumn(table, 'city');
130130
}
131131

132132
if (table.findColumnByName('preferred_currency')) {
133-
await queryRunner.dropColumn('users', 'preferred_currency');
133+
await queryRunner.dropColumn(table, 'preferred_currency');
134134
}
135135
}
136136
}

src/migrations/1685000001001-add-currency-field-to-courses.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class AddCurrencyFieldToCourses1685000001001 implements MigrationInterfac
1515
// Add currency field
1616
if (!table.findColumnByName('currency')) {
1717
await queryRunner.addColumn(
18-
'course',
18+
table,
1919
new TableColumn({
2020
name: 'currency',
2121
type: 'varchar',
@@ -26,7 +26,7 @@ export class AddCurrencyFieldToCourses1685000001001 implements MigrationInterfac
2626
);
2727
// Add index
2828
await queryRunner.createIndex(
29-
'course',
29+
table,
3030
new TableIndex({
3131
columnNames: ['currency'],
3232
name: 'IDX_course_currency',
@@ -45,12 +45,12 @@ export class AddCurrencyFieldToCourses1685000001001 implements MigrationInterfac
4545
// Drop index first
4646
const currencyIndex = table.indices.find((i) => i.name === 'IDX_course_currency');
4747
if (currencyIndex) {
48-
await queryRunner.dropIndex('course', currencyIndex);
48+
await queryRunner.dropIndex(table, currencyIndex);
4949
}
5050

5151
// Drop column
5252
if (table.findColumnByName('currency')) {
53-
await queryRunner.dropColumn('course', 'currency');
53+
await queryRunner.dropColumn(table, 'currency');
5454
}
5555
}
5656
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export class AddCourseBulkOperations1748600000000 implements MigrationInterface
6767
true,
6868
);
6969

70-
await queryRunner.createIndices('course_bulk_operations', [
70+
const bulkOpsTable = (await queryRunner.getTable('course_bulk_operations'))!;
71+
await queryRunner.createIndices(bulkOpsTable, [
7172
new TableIndex({
7273
name: 'IDX_course_bulk_ops_initiator',
7374
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'],
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
2+
3+
export class AddUserConsentIndexes1802000000000 implements MigrationInterface {
4+
name = 'AddUserConsentIndexes1802000000000';
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.createTable(
8+
new Table({
9+
name: 'user_consents',
10+
columns: [
11+
{
12+
name: 'id',
13+
type: 'uuid',
14+
isPrimary: true,
15+
isGenerated: true,
16+
generationStrategy: 'uuid',
17+
default: 'uuid_generate_v4()',
18+
},
19+
{
20+
name: 'userId',
21+
type: 'varchar',
22+
},
23+
{
24+
name: 'consentType',
25+
type: 'varchar',
26+
},
27+
{
28+
name: 'granted',
29+
type: 'boolean',
30+
},
31+
{
32+
name: 'createdAt',
33+
type: 'timestamp',
34+
default: 'now()',
35+
},
36+
{
37+
name: 'revokedAt',
38+
type: 'timestamp',
39+
isNullable: true,
40+
},
41+
],
42+
indices: [
43+
{
44+
name: 'IDX_user_consents_userId',
45+
columnNames: ['userId'],
46+
},
47+
{
48+
name: 'IDX_user_consents_consentType',
49+
columnNames: ['consentType'],
50+
},
51+
],
52+
}),
53+
true,
54+
);
55+
}
56+
57+
public async down(queryRunner: QueryRunner): Promise<void> {
58+
await queryRunner.dropTable('user_consents');
59+
}
60+
}

0 commit comments

Comments
 (0)