1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/src/migrations/20230927172930-events-announced-index.js
Gastón Fournier f9c3259083
fix: partial index on events announced (#4856)
## About the changes
Add partial index on events by announced. This should help avoid `Seq
Scan on events` when the majority of events are announced=true

---
Co-authored-by: Ivar Østhus <ivar@getunleash.io>
Co-authored-by: Gard Rimestad <gard@getunleash.io>
2023-09-28 10:21:16 +02:00

18 lines
473 B
JavaScript

'use strict';
exports.up = function (db, callback) {
db.runSql(
`
UPDATE events set announced = false where announced IS NULL;
ALTER TABLE events ALTER COLUMN announced SET NOT NULL;
ALTER TABLE events ALTER COLUMN announced SET DEFAULT false;
CREATE INDEX events_unannounced_idx ON events(announced) WHERE announced = false;
`,
callback(),
);
};
exports.down = function (db, callback) {
callback();
};