13 lines
728 B
PL/PgSQL
13 lines
728 B
PL/PgSQL
BEGIN;
|
|
ALTER TABLE studio_designs ADD COLUMN IF NOT EXISTS post_id uuid REFERENCES posts(id) ON DELETE RESTRICT;
|
|
CREATE UNIQUE INDEX IF NOT EXISTS studio_designs_post ON studio_designs(post_id) WHERE post_id IS NOT NULL;
|
|
-- Adopt explicitly published entries, including the user's page repaired before deployment.
|
|
UPDATE studio_designs d SET post_id=p.id
|
|
FROM posts p
|
|
WHERE d.post_id IS NULL AND p.slug='studio-design-'||d.id::text
|
|
AND EXISTS(SELECT 1 FROM post_assets pa JOIN assets a ON a.id=pa.asset_id
|
|
WHERE pa.post_id=p.id AND a.kind='text'
|
|
AND strpos(a.body,'/studio/layouts/'||d.layout_id||'?id='||d.id::text)>0);
|
|
INSERT INTO schema_migrations(version) VALUES('010_studio_design_posts') ON CONFLICT DO NOTHING;
|
|
COMMIT;
|