Skip to content

Commit

Permalink
Remove duplicates prior to adding unique index on contract API ID
Browse files Browse the repository at this point in the history
Also ensure ID is always unset when creating a new API.

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
  • Loading branch information
awrichar committed Apr 28, 2023
1 parent e239a5c commit c95e765
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
BEGIN;
DELETE FROM contractapis WHERE seq NOT IN (
SELECT MAX(seq) FROM contractapis GROUP BY namespace, id);
CREATE UNIQUE INDEX contractapis_id ON contractapis(namespace,id);
COMMIT;
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
DELETE FROM contractapis WHERE seq NOT IN (
SELECT MAX(seq) FROM contractapis GROUP BY namespace, id);
CREATE UNIQUE INDEX contractapis_id ON contractapis(namespace,id);
3 changes: 2 additions & 1 deletion internal/apiserver/route_post_new_contract_api.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -46,6 +46,7 @@ var postNewContractAPI = &ffapi.Route{
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
api := r.Input.(*core.ContractAPI)
api.ID = nil
err = cr.or.DefinitionSender().DefineContractAPI(cr.ctx, cr.apiBaseURL, api, waitConfirm)
return api, err
},
Expand Down

0 comments on commit c95e765

Please # to comment.