You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cacert-boardvoting/internal/migrations/2022052702_add_emails_const...

19 lines
553 B
SQL

-- add constraints on votes table
CREATE TABLE emails_new
(
id INTEGER PRIMARY KEY,
voter INTEGER NOT NULL REFERENCES voters (id),
address VARCHAR(255) NOT NULL UNIQUE,
reminder bool NOT NULL DEFAULT FALSE
);
INSERT INTO emails_new (voter, address, reminder)
SELECT emails.voter,
emails.address,
EXISTS(SELECT * FROM voters WHERE voters.reminder = emails.address AND voters.id = emails.voter)
FROM emails;
ALTER TABLE emails
RENAME TO emails_backup;
ALTER TABLE emails_new
RENAME TO emails;