diff --git a/db_objects/roster_role_assignment.class.php b/db_objects/roster_role_assignment.class.php index 3cf9242d..198101f7 100644 --- a/db_objects/roster_role_assignment.class.php +++ b/db_objects/roster_role_assignment.class.php @@ -14,9 +14,9 @@ function getInitSql($table_name = NULL) assigner int(11) not null, assignedon timestamp, primary key (roster_role_id, assignment_date, personid), - constraint foreign key rra_assiger (assigner) references _person(id), - constraint foreign key rra_personid (personid) references _person(id) ON DELETE CASCADE, - constraint foreign key rra_roster_role_id (roster_role_id) references roster_role(id) + constraint `rra_assiger` foreign key (assigner) references _person(id), + constraint `rra_personid` foreign key (personid) references _person(id) ON DELETE CASCADE, + constraint `rra_roster_role_id` foreign key (roster_role_id) references roster_role(id) ) ENGINE=InnoDB ;'; } diff --git a/upgrades/2018-upgrade-to-2.24.sql b/upgrades/2018-upgrade-to-2.24.sql index 8bbd9a24..fc8afba1 100644 --- a/upgrades/2018-upgrade-to-2.24.sql +++ b/upgrades/2018-upgrade-to-2.24.sql @@ -13,11 +13,27 @@ ALTER TABLE age_bracket MODIFY COLUMN is_adult TINYINT(1) UNSIGNED NOT NULL DEFA UPDATE setting SET note = 'Can users with congregation restrictions add new persons and families?' where symbol = 'RESTRICTED_USERS_CAN_ADD'; /* issue #30 - delete people altogether */ -ALTER TABLE roster_role_assignment -DROP FOREIGN KEY rra_personid; +/* To make sure FKs are right on roster_role_assignment we recreate the table +since the FK names are historically inconsistent */ ALTER TABLE roster_role_assignment -ADD CONSTRAINT `rra_personid` FOREIGN KEY (personid) REFERENCES _person(id) ON DELETE CASCADE; +RENAME TO _disused_roster_role_assn; + +create table roster_role_assignment ( +assignment_date date not null, +roster_role_id int(11) not null, +personid int(11) not null, +rank int unsigned not null default 0, +assigner int(11) not null, +assignedon timestamp, +primary key (roster_role_id, assignment_date, personid), +constraint `rra_assiger` foreign key (assigner) references _person(id), +constraint `rra_personid` foreign key (personid) references _person(id) ON DELETE CASCADE, +constraint `rra_roster_role_id` foreign key (roster_role_id) references roster_role(id) +) ENGINE=InnoDB ; + +INSERT INTO roster_role_assignment +SELECT * FROM _disused_roster_role_assn; DELETE FROM attendance_record WHERE personid NOT IN (select id FROM _person); ALTER TABLE attendance_record