From 8a39aee79353c58383d4ee9a7df1c077ebf1337b Mon Sep 17 00:00:00 2001 From: Francisco Moura Date: Thu, 8 Aug 2024 16:36:07 -0300 Subject: [PATCH] fixup! feat(db): Add Epoch and Snapshot --- internal/repository/base_test.go | 13 +++++++++++++ ...tion_input_claim_output_report_nodeconfig.up.sql | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/repository/base_test.go b/internal/repository/base_test.go index d07a12e92..b92976577 100644 --- a/internal/repository/base_test.go +++ b/internal/repository/base_test.go @@ -469,6 +469,19 @@ func (s *RepositorySuite) TestGetSnapshot() { s.Require().Equal(&expectedSnapshot, actualSnapshot) } +func (s *RepositorySuite) TestInsertSnapshotFailsSameInputId() { + + snapshot := Snapshot{ + InputId: 1, + AppAddress: common.HexToAddress("feadbeef"), + URI: "/some/path", + } + + _, err := s.database.InsertSnapshot(s.ctx, &snapshot) + s.Require().ErrorContains(err, "violates unique constraint") + +} + func TestRepositorySuite(t *testing.T) { suite.Run(t, new(RepositorySuite)) } diff --git a/internal/repository/migrations/000001_create_application_input_claim_output_report_nodeconfig.up.sql b/internal/repository/migrations/000001_create_application_input_claim_output_report_nodeconfig.up.sql index 67b01eb75..51de4402d 100644 --- a/internal/repository/migrations/000001_create_application_input_claim_output_report_nodeconfig.up.sql +++ b/internal/repository/migrations/000001_create_application_input_claim_output_report_nodeconfig.up.sql @@ -93,7 +93,8 @@ CREATE TABLE "snapshot" "uri" VARCHAR(4096) NOT NULL, CONSTRAINT "snapshot_pkey" PRIMARY KEY ("id"), CONSTRAINT "snapshot_input_id_fkey" FOREIGN KEY ("input_id") REFERENCES "input"("id"), - CONSTRAINT "snapshot_application_address_fkey" FOREIGN KEY ("application_address") REFERENCES "application"("contract_address") + CONSTRAINT "snapshot_application_address_fkey" FOREIGN KEY ("application_address") REFERENCES "application"("contract_address"), + UNIQUE("input_id") ); CREATE TABLE "node_config"