diff --git a/packages/ilmomasiina-backend/src/models/migrations/0005-add-indexes.ts b/packages/ilmomasiina-backend/src/models/migrations/0005-add-indexes.ts new file mode 100644 index 00000000..22938954 --- /dev/null +++ b/packages/ilmomasiina-backend/src/models/migrations/0005-add-indexes.ts @@ -0,0 +1,35 @@ +import { defineMigration } from './util'; + +export default defineMigration({ + name: '0005-add-indexes', + async up({ context: { sequelize } }) { + const query = sequelize.getQueryInterface(); + await query.addIndex( + 'quota', + { + name: 'idx_quota_main', + fields: ['eventId', 'deletedAt'], + }, + ); + await query.addIndex( + 'signup', + { + name: 'idx_signup_main', + fields: ['quotaId', 'deletedAt', 'confirmedAt', 'createdAt'], + }, + ); + await query.addIndex( + 'answer', + { + name: 'idx_answer_main', + fields: ['signupId', 'questionId', 'deletedAt'], + }, + ); + }, + async down({ context: { sequelize } }) { + const query = sequelize.getQueryInterface(); + await query.removeIndex('quota', 'idx_quota_main'); + await query.removeIndex('signup', 'idx_signup_main'); + await query.removeIndex('answer', 'idx_answer_main'); + }, +}); diff --git a/packages/ilmomasiina-backend/src/models/migrations/index.ts b/packages/ilmomasiina-backend/src/models/migrations/index.ts index 5260e94a..3fd4b66d 100644 --- a/packages/ilmomasiina-backend/src/models/migrations/index.ts +++ b/packages/ilmomasiina-backend/src/models/migrations/index.ts @@ -6,6 +6,7 @@ import _0001_add_audit_logs from './0001-add-audit-logs'; import _0002_add_event_endDate from './0002-add-event-endDate'; import _0003_add_signup_language from './0003-add-signup-language'; import _0004_answers_to_json from './0004-answers-to-json'; +import _0005_add_indexes from './0005-add-indexes'; const migrations: RunnableMigration[] = [ _0000_initial, @@ -13,6 +14,7 @@ const migrations: RunnableMigration[] = [ _0002_add_event_endDate, _0003_add_signup_language, _0004_answers_to_json, + _0005_add_indexes, ]; export default migrations;