server: ensure uniqueness on post links
This commit is contained in:
parent
145d1c1787
commit
ffb210babb
@ -0,0 +1,3 @@
|
|||||||
|
-- Add down migration script here
|
||||||
|
ALTER TABLE
|
||||||
|
post DROP CONSTRAINT post_link_key;
|
||||||
28
server/migrations/20241225054216_post-link-unique.up.sql
Normal file
28
server/migrations/20241225054216_post-link-unique.up.sql
Normal 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);
|
||||||
Loading…
x
Reference in New Issue
Block a user