Skip to content

Commit

Permalink
Issue #30 - improve FK upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
tbar0970 committed Jul 21, 2018
1 parent bc40daa commit 6622ab7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions db_objects/roster_role_assignment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;';
}

Expand Down
22 changes: 19 additions & 3 deletions upgrades/2018-upgrade-to-2.24.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6622ab7

Please sign in to comment.