Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Updated schema for emails.participant to refer to participants.id #3864

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALTER TABLE emails DROP CONSTRAINT emails_participant_fkey;

ALTER TABLE emails ALTER COLUMN participant TYPE bigint USING participant::bigint;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the effect of the participant::bigint cast? Does this properly convert the values in the emails.participant column?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The participants.id datatype is bigserial. So, the datatype of emails.participant need to match with this. In order to do so, we need to first convert it into bigint and then create a sequence for the column. We can read more about serial type from here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to the old data in the column with this statement?


CREATE SEQUENCE emails_participant_seq;
ALTER TABLE emails ALTER COLUMN participant SET DEFAULT nextval('emails_participant_seq');
ALTER SEQUENCE emails_participant_seq OWNED BY emails.participant;

ALTER TABLE emails ADD FOREIGN KEY (participant) REFERENCES participants(id) ON UPDATE CASCADE ON DELETE RESTRICT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ON UPDATE CASCADE ON DELETE RESTRICT

Since we never change participants.id, we don't need a special ON UPDATE clause. The default of RESTRICT is fine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, making the changes.