Skip to content

Commit

Permalink
db(indexer): update auction_details pk
Browse files Browse the repository at this point in the history
  • Loading branch information
gaboesquivel committed Feb 7, 2024
1 parent c6f852c commit 73994bb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
16 changes: 16 additions & 0 deletions apps/indexer/prisma/migrations/20240207222748_update/migration.sql
Original file line number Diff line number Diff line change
@@ -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");
7 changes: 3 additions & 4 deletions apps/indexer/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
10 changes: 8 additions & 2 deletions apps/indexer/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
// )
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 73994bb

Please sign in to comment.