Let admins reorder commitment groups and the cards within each group from the console Commitments tab using up/down buttons, driven by the existing rank-aware update mutations. Make the (parent, rank) unique constraints on the commitment tables DEFERRABLE INITIALLY DEFERRED. Reordering shifts several rows in one UPDATE, which transiently duplicates a rank and tripped the immediately enforced constraint with a 23505 error. This matches the other rank-ordered tables (references, compliance frameworks). Signed-off-by: Émile Ré <emile@probo.com>
41 lines
2.0 KiB
SQL
41 lines
2.0 KiB
SQL
-- Copyright (c) 2026 Probo Inc <hello@probo.com>.
|
|
--
|
|
-- Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
-- of this software and associated documentation files (the "Software"), to deal
|
|
-- in the Software without restriction, including without limitation the rights
|
|
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
-- copies of the Software, and to permit persons to whom the Software is
|
|
-- furnished to do so, subject to the following conditions:
|
|
--
|
|
-- The above copyright notice and this permission notice shall be included in
|
|
-- all copies or substantial portions of the Software.
|
|
--
|
|
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
-- SOFTWARE.
|
|
|
|
-- Rank reordering shifts several rows in a single UPDATE, which transiently
|
|
-- collides on the (parent, rank) unique constraint. Make both constraints
|
|
-- DEFERRABLE INITIALLY DEFERRED so uniqueness is only enforced at commit,
|
|
-- matching the other rank-ordered tables (references, compliance frameworks).
|
|
|
|
ALTER TABLE compliance_portal_commitment_groups
|
|
DROP CONSTRAINT compliance_portal_commitment_groups_trust_center_id_rank_key;
|
|
|
|
ALTER TABLE compliance_portal_commitment_groups
|
|
ADD CONSTRAINT compliance_portal_commitment_groups_trust_center_id_rank_key
|
|
UNIQUE (trust_center_id, rank)
|
|
DEFERRABLE INITIALLY DEFERRED;
|
|
|
|
ALTER TABLE compliance_portal_commitments
|
|
DROP CONSTRAINT compliance_portal_commitments_group_id_rank_key;
|
|
|
|
ALTER TABLE compliance_portal_commitments
|
|
ADD CONSTRAINT compliance_portal_commitments_group_id_rank_key
|
|
UNIQUE (group_id, rank)
|
|
DEFERRABLE INITIALLY DEFERRED;
|