Skip to content

Commit

Permalink
fix fkey constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik committed Oct 15, 2023
1 parent fb46129 commit 34d845c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions nexus/catalog/migrations/V9__mirror_stats_rels.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
-- For the cdc_batches, set batch_id as the primary key
ALTER TABLE peerdb_stats.cdc_batches
ADD CONSTRAINT pk_cdc_batches PRIMARY KEY (batch_id);
ADD COLUMN id SERIAL PRIMARY KEY;

-- add unique constraint on flow_name and batch_id
ALTER TABLE peerdb_stats.cdc_batches
ADD CONSTRAINT uq_cdc_batches_flow_batch UNIQUE (flow_name, batch_id);

-- add incrementing id column to cdc_batch_table, make this the primary key
ALTER TABLE peerdb_stats.cdc_batch_table
Expand All @@ -23,7 +27,7 @@ FOREIGN KEY (flow_name) REFERENCES peerdb_stats.cdc_flows(flow_name) ON DELETE C
-- Composite foreign key for flow_name and batch_id in cdc_batch_table
ALTER TABLE peerdb_stats.cdc_batch_table
ADD CONSTRAINT fk_cdc_batch_table_flow_batch
FOREIGN KEY (batch_id) REFERENCES peerdb_stats.cdc_batches(batch_id) ON DELETE CASCADE;
FOREIGN KEY (flow_name, batch_id) REFERENCES peerdb_stats.cdc_batches(flow_name, batch_id) ON DELETE CASCADE;

-- Foreign key for run_uuid in qrep_partitions
ALTER TABLE peerdb_stats.qrep_partitions
Expand Down
6 changes: 4 additions & 2 deletions ui/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,25 @@ model cdc_batch_table {
num_rows BigInt
metadata Json?
id Int @id @default(autoincrement())
cdc_batches cdc_batches @relation(fields: [batch_id], references: [batch_id], onDelete: Cascade, onUpdate: NoAction, map: "fk_cdc_batch_table_flow_batch")
cdc_batches cdc_batches @relation(fields: [flow_name, batch_id], references: [flow_name, batch_id], onDelete: Cascade, onUpdate: NoAction, map: "fk_cdc_batch_table_flow_batch")
@@schema("peerdb_stats")
}

model cdc_batches {
flow_name String
batch_id BigInt @id(map: "pk_cdc_batches")
batch_id BigInt
rows_in_batch Int
batch_start_lsn Decimal @db.Decimal
batch_end_lsn Decimal @db.Decimal
start_time DateTime @db.Timestamp(6)
end_time DateTime? @db.Timestamp(6)
metadata Json?
id Int @id @default(autoincrement())
cdc_batch_table cdc_batch_table[]
cdc_flows cdc_flows @relation(fields: [flow_name], references: [flow_name], onDelete: Cascade, onUpdate: NoAction, map: "fk_cdc_batches_flow_name")
@@unique([flow_name, batch_id], map: "uq_cdc_batches_flow_batch")
@@schema("peerdb_stats")
}

Expand Down

0 comments on commit 34d845c

Please sign in to comment.