Skip to content

Instantly share code, notes, and snippets.

@jhass
Last active December 4, 2020 13:03
Show Gist options
  • Save jhass/2472c263e0afa6dc210f3fdb7d996c8d to your computer and use it in GitHub Desktop.
Save jhass/2472c263e0afa6dc210f3fdb7d996c8d to your computer and use it in GitHub Desktop.
Fix missing on delete cascade on foreign key constraints after migrating Diaspora to PostgreSQL
ALTER TABLE aspect_memberships
DROP CONSTRAINT aspect_memberships_aspect_id_fkey,
ADD CONSTRAINT aspect_memberships_aspect_id_fkey FOREIGN KEY (aspect_id) REFERENCES aspects(id) ON DELETE CASCADE;
ALTER TABLE aspect_memberships
DROP CONSTRAINT aspect_memberships_contact_id_fkey,
ADD CONSTRAINT aspect_memberships_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES contacts(id) ON DELETE CASCADE;
ALTER TABLE aspect_visibilities
DROP CONSTRAINT aspect_visibilities_aspect_id_fkey,
ADD CONSTRAINT aspect_visibilities_aspect_id_fkey FOREIGN KEY (aspect_id) REFERENCES aspects(id) ON DELETE CASCADE;
ALTER TABLE comment_signatures
DROP CONSTRAINT comment_signatures_comment_id_fkey,
ADD CONSTRAINT comment_signatures_comment_id_fkey FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE;
ALTER TABLE comments
DROP CONSTRAINT comments_author_id_fkey,
ADD CONSTRAINT comments_author_id_fk FOREIGN KEY (author_id) REFERENCES people(id) ON DELETE CASCADE;
ALTER TABLE contacts
DROP CONSTRAINT contacts_person_id_fkey,
ADD CONSTRAINT contacts_person_id_fkey FOREIGN KEY (person_id) REFERENCES people(id) ON DELETE CASCADE;
ALTER TABLE conversation_visibilities
DROP CONSTRAINT conversation_visibilities_conversation_id_fkey,
ADD CONSTRAINT conversation_visibilities_conversation_id_fkey FOREIGN KEY (conversation_id) REFERENCES conversations(id) ON DELETE CASCADE;
ALTER TABLE conversation_visibilities
DROP CONSTRAINT conversation_visibilities_person_id_fkey,
ADD CONSTRAINT conversation_visibilities_person_id_fkey FOREIGN KEY (person_id) REFERENCES people(id) ON DELETE CASCADE;
ALTER TABLE conversations
DROP CONSTRAINT conversations_author_id_fkey,
ADD CONSTRAINT conversations_author_id_fkey FOREIGN KEY (author_id) REFERENCES people(id) ON DELETE CASCADE;
ALTER TABLE like_signatures
DROP CONSTRAINT like_signatures_like_id_fkey,
ADD CONSTRAINT like_signatures_like_id_fkey FOREIGN KEY (like_id) REFERENCES likes(id) ON DELETE CASCADE;
ALTER TABLE likes
DROP CONSTRAINT likes_author_id_fkey,
ADD CONSTRAINT likes_author_id_fkey FOREIGN KEY (author_id) REFERENCES people(id) ON DELETE CASCADE;
ALTER TABLE messages
DROP CONSTRAINT messages_conversation_id_fkey,
ADD CONSTRAINT messages_conversation_id_fkey FOREIGN KEY (conversation_id) REFERENCES conversations(id) ON DELETE CASCADE;
ALTER TABLE messages
DROP CONSTRAINT messages_author_id_fkey,
ADD CONSTRAINT messages_author_id_fkey FOREIGN KEY (author_id) REFERENCES people(id) ON DELETE CASCADE;
ALTER TABLE notification_actors
DROP CONSTRAINT notification_actors_notification_id_fkey,
ADD CONSTRAINT notification_actors_notification_id_fkey FOREIGN KEY (notification_id) REFERENCES notifications(id) ON DELETE CASCADE;
ALTER TABLE people
DROP CONSTRAINT people_pod_id_fkey,
ADD CONSTRAINT people_pod_id_fkey FOREIGN KEY (pod_id) REFERENCES pods(id) ON DELETE CASCADE;
ALTER TABLE poll_participation_signatures
DROP CONSTRAINT poll_participation_signatures_poll_participation_id_fkey,
ADD CONSTRAINT poll_participation_signatures_poll_participation_id_fkey FOREIGN KEY (poll_participation_id) REFERENCES poll_participations(id) ON DELETE CASCADE;
ALTER TABLE posts
DROP CONSTRAINT posts_author_id_fkey,
ADD CONSTRAINT posts_author_id_fkey FOREIGN KEY (author_id) REFERENCES people(id) ON DELETE CASCADE;
ALTER TABLE profiles
DROP CONSTRAINT profiles_person_id_fkey,
ADD CONSTRAINT profiles_person_id_fkey FOREIGN KEY (person_id) REFERENCES people(id) ON DELETE CASCADE;
ALTER TABLE services
DROP CONSTRAINT services_user_id_fkey,
ADD CONSTRAINT services_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE share_visibilities
DROP CONSTRAINT share_visibilities_user_id_fkey,
ADD CONSTRAINT share_visibilities_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment