diff --git a/src/db/migrations/011_kind_author_index.ts b/src/db/migrations/011_kind_author_index.ts index 3e7d010..c41910b 100644 --- a/src/db/migrations/011_kind_author_index.ts +++ b/src/db/migrations/011_kind_author_index.ts @@ -4,7 +4,7 @@ export async function up(db: Kysely): Promise { await db.schema .createIndex('idx_events_kind_pubkey_created_at') .on('events') - .columns(['kind', 'pubkey', 'created_at']) + .columns(['kind', 'pubkey', 'created_at desc']) .execute(); } diff --git a/src/db/migrations/018_events_created_at_kind_index.ts b/src/db/migrations/018_events_created_at_kind_index.ts new file mode 100644 index 0000000..8e6c67c --- /dev/null +++ b/src/db/migrations/018_events_created_at_kind_index.ts @@ -0,0 +1,14 @@ +import { Kysely } from 'kysely'; + +export async function up(db: Kysely): Promise { + await db.schema + .createIndex('idx_events_created_at_kind') + .on('events') + .columns(['created_at desc', 'kind']) + .ifNotExists() + .execute(); +} + +export async function down(db: Kysely): Promise { + await db.schema.dropIndex('idx_events_created_at_kind').ifExists().execute(); +}