diff --git a/packages/bsky/src/db/migrations/20230929T192920807Z-record-cursor-indexes.ts b/packages/bsky/src/db/migrations/20230929T192920807Z-record-cursor-indexes.ts new file mode 100644 index 00000000000..0b587fe0eaf --- /dev/null +++ b/packages/bsky/src/db/migrations/20230929T192920807Z-record-cursor-indexes.ts @@ -0,0 +1,40 @@ +import { Kysely } from 'kysely' + +export async function up(db: Kysely): Promise { + await db.schema + .createIndex('like_creator_cursor_idx') + .on('like') + .columns(['creator', 'sortAt', 'cid']) + .execute() + await db.schema + .createIndex('follow_creator_cursor_idx') + .on('follow') + .columns(['creator', 'sortAt', 'cid']) + .execute() + await db.schema + .createIndex('follow_subject_cursor_idx') + .on('follow') + .columns(['subjectDid', 'sortAt', 'cid']) + .execute() + + // drop old indices that are superceded by these + await db.schema.dropIndex('like_creator_idx').execute() + await db.schema.dropIndex('follow_subjectdid_idx').execute() +} + +export async function down(db: Kysely): Promise { + await db.schema + .createIndex('like_creator_idx') + .on('like') + .column('creator') + .execute() + await db.schema + .createIndex('follow_subjectdid_idx') + .on('follow') + .column('subjectDid') + .execute() + + await db.schema.dropIndex('like_creator_cursor_idx').execute() + await db.schema.dropIndex('follow_creator_cursor_idx').execute() + await db.schema.dropIndex('follow_subject_cursor_idx').execute() +} diff --git a/packages/bsky/src/db/migrations/index.ts b/packages/bsky/src/db/migrations/index.ts index 9e8bfe9cf7f..630d4385e1d 100644 --- a/packages/bsky/src/db/migrations/index.ts +++ b/packages/bsky/src/db/migrations/index.ts @@ -29,3 +29,4 @@ export * as _20230830T205507322Z from './20230830T205507322Z-suggested-feeds' export * as _20230904T211011773Z from './20230904T211011773Z-block-lists' export * as _20230906T222220386Z from './20230906T222220386Z-thread-gating' export * as _20230920T213858047Z from './20230920T213858047Z-add-tags-to-post' +export * as _20230929T192920807Z from './20230929T192920807Z-record-cursor-indexes'