Skip to content

Commit

Permalink
Add basic database indexing
Browse files Browse the repository at this point in the history
Co-Authored-By: Ahlström Kalle <[email protected]>
  • Loading branch information
PurkkaKoodari and kahlstrm committed Mar 7, 2024
1 parent f189fb8 commit d999a6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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');
},
});
2 changes: 2 additions & 0 deletions packages/ilmomasiina-backend/src/models/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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<Sequelize>[] = [
_0000_initial,
_0001_add_audit_logs,
_0002_add_event_endDate,
_0003_add_signup_language,
_0004_answers_to_json,
_0005_add_indexes,
];

export default migrations;

0 comments on commit d999a6c

Please sign in to comment.