From c582b1c520f643b3072635670dc6cc19e964e93e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 20 Sep 2024 09:16:09 -0500 Subject: [PATCH] author_stats: add index on followers_count --- .../035_author_stats_followers_index.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/db/migrations/035_author_stats_followers_index.ts diff --git a/src/db/migrations/035_author_stats_followers_index.ts b/src/db/migrations/035_author_stats_followers_index.ts new file mode 100644 index 00000000..0509d403 --- /dev/null +++ b/src/db/migrations/035_author_stats_followers_index.ts @@ -0,0 +1,17 @@ +import { Kysely } from 'kysely'; + +export async function up(db: Kysely): Promise { + await db.schema + .createIndex('author_stats_followers_count_idx') + .ifNotExists() + .on('author_stats') + .column('followers_count desc') + .execute(); + + // This index should have never been added, because pubkey is the primary key. + await db.schema.dropIndex('idx_author_stats_pubkey').ifExists().execute(); +} + +export async function down(db: Kysely): Promise { + await db.schema.dropIndex('author_stats_followers_count_idx').ifExists().execute(); +}