fix(migration): deduplicate active invites before creating unique index in V026
Dev databases that accumulated multiple pending invites before V026 was written would fail to create uq_household_invite_active. Added a cleanup UPDATE that marks all-but-the-latest invite per household as invalidated before the index is created. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
ALTER TABLE household_invite
|
||||
ADD COLUMN invalidated_at timestamptz;
|
||||
|
||||
-- Mark all but the most-recent invite per household as invalidated,
|
||||
-- so the unique partial index below can be created on dev databases
|
||||
-- that accumulated multiple pending invites before this migration was added.
|
||||
UPDATE household_invite
|
||||
SET invalidated_at = NOW()
|
||||
WHERE id NOT IN (
|
||||
SELECT DISTINCT ON (household_id) id
|
||||
FROM household_invite
|
||||
ORDER BY household_id, expires_at DESC
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX uq_household_invite_active
|
||||
ON household_invite (household_id)
|
||||
WHERE invalidated_at IS NULL;
|
||||
|
||||
Reference in New Issue
Block a user