2021-04-08 11:29:08 +00:00
|
|
|
-- Add the column back
|
2023-08-02 16:44:51 +00:00
|
|
|
ALTER TABLE community
|
|
|
|
ADD COLUMN creator_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE;
|
2021-04-08 11:29:08 +00:00
|
|
|
|
|
|
|
-- Recreate the index
|
2023-08-02 16:44:51 +00:00
|
|
|
CREATE INDEX idx_community_creator ON community (creator_id);
|
2021-04-08 11:29:08 +00:00
|
|
|
|
|
|
|
-- Add the data, selecting the highest mod
|
2023-08-02 16:44:51 +00:00
|
|
|
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;
|
2021-04-08 11:29:08 +00:00
|
|
|
|
|
|
|
-- Set to not null
|
2023-08-02 16:44:51 +00:00
|
|
|
ALTER TABLE community
|
|
|
|
ALTER COLUMN creator_id SET NOT NULL;
|
2021-04-08 11:29:08 +00:00
|
|
|
|