lemmy/migrations/2021-04-02-021422_remove_community_creator/down.sql
Dessalines be1389420b
Adding SQL format checking via pg_format / pgFormatter (#3740)
* SQL format checking, 1.

* SQL format checking, 2.

* SQL format checking, 3.

* SQL format checking, 4.

* SQL format checking, 5.

* Running pg_format

* Getting rid of comment.

* Upping pg_format version.

* Using git ls-files for sql format check.

* Fixing sql lints.

* Addressing PR comments.
2023-08-02 12:44:51 -04:00

27 lines
558 B
SQL

-- Add the column back
ALTER TABLE community
ADD COLUMN creator_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE;
-- Recreate the index
CREATE INDEX idx_community_creator ON community (creator_id);
-- Add the data, selecting the highest mod
UPDATE
community
SET
creator_id = sub.person_id
FROM (
SELECT
cm.community_id,
cm.person_id
FROM
community_moderator cm
LIMIT 1) AS sub
WHERE
id = sub.community_id;
-- Set to not null
ALTER TABLE community
ALTER COLUMN creator_id SET NOT NULL;