18 lines
553 B
SQL
18 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;
|