diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20240304115004_create_fills_clob_pair_id_created_at_height_created_at_index.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20240304115004_create_fills_clob_pair_id_created_at_height_created_at_index.ts new file mode 100644 index 0000000000..b90bffb90d --- /dev/null +++ b/indexer/packages/postgres/src/db/migrations/migration_files/20240304115004_create_fills_clob_pair_id_created_at_height_created_at_index.ts @@ -0,0 +1,21 @@ +import * as Knex from 'knex'; + +export async function up(knex: Knex): Promise { + // Partial index only when `liquidity` is 'TAKER' as this index is meant to speed up the query to + // fetch all trades from the database, and we arbitrarily only use 'TAKER' fills for trades to + // avoid double counting. + // eslint-disable-next-line @typescript-eslint/quotes + await knex.raw(` + CREATE INDEX CONCURRENTLY IF NOT EXISTS "fills_clobPairId_createdAtHeight_createdAt_partial" ON "fills" ("clobPairId", "createdAtHeight", "createdAt") WHERE "liquidity" = 'TAKER'; + `); +} + +export async function down(knex: Knex): Promise { + await knex.raw(` + DROP INDEX CONCURRENTLY IF EXISTS "fills_clobPairId_createdAtHeight_createdAt_partial"; + `); +} + +export const config = { + transaction: false, +};