
-- Sort out accessing calendar entries.

BEGIN;
SELECT check_db_revision(1,2,2);

ALTER TABLE role_member DROP CONSTRAINT "$1";
ALTER TABLE role_member ADD CONSTRAINT "$1" (role_no) REFERENCES roles(role_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE role_member DROP CONSTRAINT "$2";
ALTER TABLE role_member ADD CONSTRAINT "$2" (user_no) REFERENCES usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
 
ALTER TABLE session DROP CONSTRAINT "$1";
ALTER TABLE session ADD CONSTRAINT "$1" FOREIGN KEY (user_no) REFERENCES usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;

ALTER TABLE relationship DROP CONSTRAINT "$1";
ALTER TABLE relationship ADD CONSTRAINT "$1" FOREIGN KEY (from_user) REFERENCES usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE relationship DROP CONSTRAINT "$2";
ALTER TABLE relationship ADD CONSTRAINT "$2" FOREIGN KEY (to_user) REFERENCES usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;

ALTER TABLE usr_setting DROP CONSTRAINT "$1";
ALTER TABLE usr_setting ADD CONSTRAINT "$1" FOREIGN KEY (user_no) REFERENCES usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;

ALTER TABLE tmp_password DROP CONSTRAINT "$1";
ALTER TABLE tmp_password ADD CONSTRAINT "$1" FOREIGN KEY (user_no) REFERENCES usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;

ALTER TABLE caldav_data DROP CONSTRAINT "$1";
ALTER TABLE caldav_data ADD CONSTRAINT "$1" FOREIGN KEY (user_no) REFERENCES usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE caldav_data DROP CONSTRAINT "$2";
ALTER TABLE caldav_data ADD CONSTRAINT "$2" FOREIGN KEY (logged_user) REFERENCES usr(user_no) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;

ALTER TABLE property DROP CONSTRAINT "$1";
ALTER TABLE property ADD CONSTRAINT "$1" FOREIGN KEY (changed_by) REFERENCES usr(user_no) ON UPDATE CASCADE;

SELECT new_db_revision(1,2,3, 'Mars' );
COMMIT;
ROLLBACK;


Add some more cascades for pre 8.0 databases.
Add some more cascades for pre 8.0 databases.
