server: ensure uniqueness on post links

This commit is contained in:
Bill Thiede 2024-12-25 08:02:36 -08:00
parent 145d1c1787
commit ffb210babb
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,3 @@
-- Add down migration script here
ALTER TABLE
post DROP CONSTRAINT post_link_key;

View File

@ -0,0 +1,28 @@
WITH dupes AS (
SELECT
uid,
link,
Row_number() over(
PARTITION by link
ORDER BY
link
) AS RowNumber
FROM
post
)
DELETE FROM
post
WHERE
uid IN (
SELECT
uid
FROM
dupes
WHERE
RowNumber > 1
);
ALTER TABLE
post
ADD
UNIQUE (link);