From 73994bba5fa720e76bcae4504384bcc3059a6571 Mon Sep 17 00:00:00 2001 From: Gabo Esquivel Date: Wed, 7 Feb 2024 16:30:29 -0600 Subject: [PATCH] db(indexer): update auction_details pk --- .../20240207222748_update/migration.sql | 16 ++++++++++++++++ apps/indexer/prisma/schema.prisma | 7 +++---- apps/indexer/src/indexer.ts | 10 ++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 apps/indexer/prisma/migrations/20240207222748_update/migration.sql diff --git a/apps/indexer/prisma/migrations/20240207222748_update/migration.sql b/apps/indexer/prisma/migrations/20240207222748_update/migration.sql new file mode 100644 index 000000000..3f945b090 --- /dev/null +++ b/apps/indexer/prisma/migrations/20240207222748_update/migration.sql @@ -0,0 +1,16 @@ +/* + Warnings: + + - The primary key for the `auction_details` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to drop the column `id` on the `auction_details` table. All the data in the column will be lost. + - Made the column `exact_order_id` on table `auction_details` required. This step will fail if there are existing NULL values in that column. + - Added the required column `chain_id` to the `auction_details` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "auction_details" DROP CONSTRAINT "auction_details_pkey", +DROP COLUMN "id", +ALTER COLUMN "exact_order_id" SET NOT NULL, +DROP COLUMN "chain_id", +ADD COLUMN "chain_id" BIGINT NOT NULL, +ADD CONSTRAINT "auction_details_pkey" PRIMARY KEY ("exact_order_id", "chain_id"); diff --git a/apps/indexer/prisma/schema.prisma b/apps/indexer/prisma/schema.prisma index 3529e1f6d..b901a87f5 100644 --- a/apps/indexer/prisma/schema.prisma +++ b/apps/indexer/prisma/schema.prisma @@ -5,15 +5,14 @@ generator client { datasource db { provider = "postgresql" url = env("DIRECT_URL") - // directUrl = env("DIRECT_URL") } /// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info. model auction_details { - id BigInt @id @default(autoincrement()) + exact_order_id BigInt + chain_id BigInt + @@id([exact_order_id, chain_id]) created_at DateTime @default(now()) @db.Timestamptz(6) - exact_order_id BigInt? - chain_id String? symbol_auctioning_token String? symbol_bidding_token String? address_auctioning_token String? diff --git a/apps/indexer/src/indexer.ts b/apps/indexer/src/indexer.ts index 69b7dbfcb..8c7a40c57 100644 --- a/apps/indexer/src/indexer.ts +++ b/apps/indexer/src/indexer.ts @@ -31,7 +31,7 @@ export async function startIndexer() { client.watchEvent({ events, onLogs: (logs) => { - const filteredlogs = logs.filter((log) => log.eventName !== 'OwnershipTransferred') + // const filteredlogs = logs.filter((log) => log.eventName !== 'OwnershipTransferred') // console.log( // stringify(parseEventLogs({ abi: TestnetEasyAuction.abi, logs: filteredlogs }), null, 2), // ) @@ -127,7 +127,13 @@ async function handleNewAuction(log: NewAuctionEvent) { console.log('handleNewAuction:: data for postgres db', data) - // return prisma.auction_details.create({ data }) + return prisma.auction_details.upsert({ + where: { + exact_order_id: data.exact_order_id, + }, + update: data, + create: data, + }) } function handleNewSellOrder(log: any) {