From 1977e9f2830c802e35f45960af74d7823d9a1bd2 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Fri, 26 Feb 2021 00:04:51 +1300 Subject: [PATCH] Update initial SQL to create usr_emails table. I much prefer running patches to update the schema, but ah well. --- dba/base-data.sql | 6 ++++-- dba/davical.sql | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/dba/base-data.sql b/dba/base-data.sql index f544bfe1..067c1122 100644 --- a/dba/base-data.sql +++ b/dba/base-data.sql @@ -14,8 +14,10 @@ INSERT INTO principal_type (principal_type_id, principal_type_desc) VALUES( 2, ' INSERT INTO principal_type (principal_type_id, principal_type_desc) VALUES( 3, 'Group' ); -- Create the administrator record. -INSERT INTO usr ( user_no, active, email_ok, updated, username, password, fullname, email ) - VALUES ( 1, TRUE, current_date, current_date, 'admin', '**nimda', 'DAViCal Administrator', 'calendars@example.net' ); +INSERT INTO usr ( user_no, active, email_ok, updated, username, password, fullname ) + VALUES ( 1, TRUE, current_date, current_date, 'admin', '**nimda', 'DAViCal Administrator' ); +INSERT INTO usr_emails ( user_no, email ) + VALUES ( 1, 'calendars@example.net' ); INSERT INTO principal ( principal_id, type_id, user_no, displayname, default_privileges ) VALUES ( 1, 1, 1, 'DAViCal Administrator', 0::BIT(24) ); diff --git a/dba/davical.sql b/dba/davical.sql index fa8280cc..88260185 100644 --- a/dba/davical.sql +++ b/dba/davical.sql @@ -439,6 +439,22 @@ CREATE TABLE calendar_attendee ( PRIMARY KEY ( dav_id, attendee ) ); +CREATE TABLE usr_emails ( + user_no INTEGER NOT NULL REFERENCES usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE, + email VARCHAR, + main boolean DEFAULT true, + UNIQUE (email) +); + +-- Ensure that a principal only has one primary email address. +CREATE UNIQUE INDEX usr_emails_primary + ON usr_emails + USING btree + (user_no) + WHERE main = true; + +ALTER TABLE usr + DROP COLUMN email CASCADE; CREATE or REPLACE FUNCTION real_path_exists( TEXT ) RETURNS BOOLEAN AS $$ DECLARE @@ -489,4 +505,4 @@ CREATE SEQUENCE metrics_count_delticket; CREATE SEQUENCE metrics_count_bind; CREATE SEQUENCE metrics_count_unknown; -SELECT new_db_revision(1,3,3, 'Marzec' ); +SELECT new_db_revision(1,3,4, 'Kwiecie<84>' );