Skip to content

Commit

Permalink
Change firmware uniqueness constraint (#221)
Browse files Browse the repository at this point in the history
* Change firmware uniqueness constraint

* Update test
  • Loading branch information
diogomatsubara authored Jun 29, 2023
1 parent d3ec552 commit 812608f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions db/migrations/00019_firmware_update_constraint.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- +goose Up
-- +goose StatementBegin

-- Not possible to drop unique constraint with ALTER TABLE
-- See https://github.com/cockroachdb/cockroach/issues/42840
DROP INDEX vendor_component_version_unique CASCADE;
ALTER TABLE component_firmware_version ADD CONSTRAINT vendor_component_version_filename_unique UNIQUE (vendor, component, version, filename);

-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin

DROP INDEX vendor_component_version_filename_unique CASCADE;
ALTER TABLE component_firmware_version ADD CONSTRAINT vendor_component_version_unique UNIQUE (vendor, component, version);

-- +goose StatementEnd
6 changes: 3 additions & 3 deletions pkg/api/v1/router_firmware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ func TestIntegrationServerComponentFirmwareCreate(t *testing.T) {
"",
},
{
"duplicate vendor/component/version not allowed",
"duplicate vendor/component/version/filename not allowed",
&serverservice.ComponentFirmwareVersion{
UUID: uuid.New(),
Vendor: "dell",
Model: []string{"r615"},
Filename: "foobar",
Filename: "fooBAR",
Version: "12345",
Component: "bios",
Checksum: "foobar",
Expand All @@ -220,7 +220,7 @@ func TestIntegrationServerComponentFirmwareCreate(t *testing.T) {
},
true,
"400",
"unable to insert into component_firmware_version: pq: duplicate key value violates unique constraint \"vendor_component_version_unique\"",
"unable to insert into component_firmware_version: pq: duplicate key value violates unique constraint \"vendor_component_version_filename_unique\"",
},
}

Expand Down

0 comments on commit 812608f

Please sign in to comment.