mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-01-27 00:33:34 +00:00
Fix constraints so DELETE FROM usr; will work.
This commit is contained in:
parent
ba12d86fbb
commit
7df7da3132
@ -29,7 +29,7 @@ CREATE TABLE caldav_data (
|
||||
modified TIMESTAMP WITH TIME ZONE,
|
||||
caldav_data TEXT,
|
||||
caldav_type TEXT,
|
||||
logged_user INT references usr(user_no),
|
||||
logged_user INT references usr(user_no) ON UPDATE CASCADE ON DELETE SET DEFAULT DEFERRABLE,
|
||||
dav_id INT8 UNIQUE DEFAULT nextval('dav_id_seq'),
|
||||
collection_id INT8 REFERENCES collection(collection_id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE,
|
||||
|
||||
@ -48,7 +48,7 @@ CREATE TABLE time_zone (
|
||||
|
||||
-- The parsed calendar item. Here we have pulled those events/todos/journals apart somewhat.
|
||||
CREATE TABLE calendar_item (
|
||||
user_no INT references usr(user_no),
|
||||
user_no INT references usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE,
|
||||
dav_name TEXT,
|
||||
dav_etag TEXT,
|
||||
|
||||
@ -97,9 +97,9 @@ CREATE TABLE relationship_type (
|
||||
|
||||
|
||||
CREATE TABLE relationship (
|
||||
from_user INT REFERENCES usr (user_no) ON UPDATE CASCADE,
|
||||
to_user INT REFERENCES usr (user_no) ON UPDATE CASCADE,
|
||||
rt_id INT REFERENCES relationship_type (rt_id) ON UPDATE CASCADE,
|
||||
from_user INT REFERENCES usr (user_no) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
to_user INT REFERENCES usr (user_no) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
rt_id INT REFERENCES relationship_type (rt_id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
|
||||
PRIMARY KEY ( from_user, to_user, rt_id )
|
||||
);
|
||||
@ -123,7 +123,7 @@ CREATE TABLE property (
|
||||
property_name TEXT,
|
||||
property_value TEXT,
|
||||
changed_on TIMESTAMP DEFAULT current_timestamp,
|
||||
changed_by INT REFERENCES usr ( user_no ),
|
||||
changed_by INT REFERENCES usr ( user_no ) ON UPDATE CASCADE ON DELETE SET DEFAULT,
|
||||
PRIMARY KEY ( dav_name, property_name )
|
||||
);
|
||||
CREATE INDEX properties_dav_name_idx ON property(dav_name);
|
||||
@ -235,4 +235,4 @@ CREATE TABLE privilege (
|
||||
);
|
||||
|
||||
|
||||
SELECT new_db_revision(1,2,2, 'Fevrier' );
|
||||
SELECT new_db_revision(1,2,5, 'Mai' );
|
||||
|
||||
33
dba/patches/1.2.5.sql
Normal file
33
dba/patches/1.2.5.sql
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
-- This database update refines the constraint on usr in order to try and be
|
||||
-- able to actually DELETE FROM usr WHERE user_no = x; and have the database
|
||||
-- do the right thing...
|
||||
|
||||
BEGIN;
|
||||
SELECT check_db_revision(1,2,4);
|
||||
|
||||
ALTER TABLE calendar_item DROP CONSTRAINT "calendar_item_user_no_fkey";
|
||||
ALTER TABLE calendar_item ADD CONSTRAINT "calendar_item_user_no_fkey" FOREIGN KEY (user_no) REFERENCES usr(user_no)
|
||||
ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
|
||||
|
||||
ALTER TABLE caldav_data DROP CONSTRAINT "caldav_data_logged_user_fkey";
|
||||
ALTER TABLE caldav_data ADD CONSTRAINT "caldav_data_logged_user_fkey" FOREIGN KEY (logged_user) REFERENCES usr(user_no)
|
||||
ON UPDATE CASCADE ON DELETE SET DEFAULT DEFERRABLE;
|
||||
|
||||
ALTER TABLE relationship DROP CONSTRAINT "relationship_from_user_fkey";
|
||||
ALTER TABLE relationship ADD CONSTRAINT "relationship_from_user_fkey" FOREIGN KEY (from_user) REFERENCES usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
|
||||
ALTER TABLE relationship DROP CONSTRAINT "relationship_to_user_fkey";
|
||||
ALTER TABLE relationship ADD CONSTRAINT "relationship_to_user_fkey" FOREIGN KEY (to_user) REFERENCES usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
|
||||
ALTER TABLE relationship DROP CONSTRAINT "relationship_rt_id_fkey";
|
||||
ALTER TABLE relationship ADD CONSTRAINT "relationship_rt_id_fkey" FOREIGN KEY (rt_id) REFERENCES relationship_type(rt_id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
|
||||
|
||||
ALTER TABLE property DROP CONSTRAINT "property_changed_by_fkey";
|
||||
ALTER TABLE property ADD CONSTRAINT "property_changed_by_fkey" FOREIGN KEY (changed_by) REFERENCES usr(user_no)
|
||||
ON UPDATE CASCADE ON DELETE SET DEFAULT DEFERRABLE;
|
||||
|
||||
|
||||
SELECT new_db_revision(1,2,5, 'Mai' );
|
||||
|
||||
COMMIT;
|
||||
ROLLBACK;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user