From 25a149b6209d8e26dffc0d23aa40f92a58c2a7c5 Mon Sep 17 00:00:00 2001 From: dholms Date: Thu, 5 Dec 2024 14:41:49 -0600 Subject: [PATCH] add sort idx --- ...241205T203713695Z-subject-status-sort-idxs.ts | 16 ++++++++++++++++ packages/ozone/src/db/migrations/index.ts | 1 + 2 files changed, 17 insertions(+) create mode 100644 packages/ozone/src/db/migrations/20241205T203713695Z-subject-status-sort-idxs.ts diff --git a/packages/ozone/src/db/migrations/20241205T203713695Z-subject-status-sort-idxs.ts b/packages/ozone/src/db/migrations/20241205T203713695Z-subject-status-sort-idxs.ts new file mode 100644 index 00000000000..5cbf7d9fb5f --- /dev/null +++ b/packages/ozone/src/db/migrations/20241205T203713695Z-subject-status-sort-idxs.ts @@ -0,0 +1,16 @@ +import { Kysely, sql } from 'kysely' + +export async function up(db: Kysely): Promise { + const ref = db.dynamic.ref + sql`CREATE INDEX moderation_subject_status_sort_idx ON ${ref('moderation_subject_status')} (${ref('lastReportedAt')} DESC NULLS LAST, ${ref('id')} DESC NULLS LAST);`.execute( + db, + ) + sql`CREATE INDEX moderation_subject_status_unreviewed_sort_idx ON ${ref('moderation_subject_status')} (${ref('lastReportedAt')} DESC NULLS LAST, ${ref('id')} DESC NULLS LAST); WHERE ${ref('reviewState')} = 'tools.ozone.moderation.defs#reviewNone';`.execute( + db, + ) +} + +export async function down(db: Kysely): Promise { + db.schema.dropIndex('moderation_subject_status_sort_idx').execute() + db.schema.dropIndex('moderation_subject_status_unreviewed_sort_idx').execute() +} diff --git a/packages/ozone/src/db/migrations/index.ts b/packages/ozone/src/db/migrations/index.ts index be299b76edb..c36f7f237ed 100644 --- a/packages/ozone/src/db/migrations/index.ts +++ b/packages/ozone/src/db/migrations/index.ts @@ -17,3 +17,4 @@ export * as _20241001T205730722Z from './20241001T205730722Z-subject-status-revi export * as _20241008T205730722Z from './20241008T205730722Z-sets' export * as _20241018T205730722Z from './20241018T205730722Z-setting' export * as _20241026T205730722Z from './20241026T205730722Z-add-hosting-status-to-subject-status' +export * as _20241205T203713695Z from './20241205T203713695Z-subject-status-sort-idxs'