From 0e04676298f6cc3d0e780d2ed8d401e84c4f7a73 Mon Sep 17 00:00:00 2001 From: inghamn Date: Fri, 8 Jan 2010 21:19:22 +0000 Subject: [PATCH] Updated the import script. It now assumes the new schema is already in place, and only needs to insert the old data git-svn-id: https://rosehill.googlecode.com/svn/trunk@51 100bd78a-fc82-11de-b5bc-ffd2847a4b57 --- scripts/migration/import.sql | 54 ++++++++---------------------------- 1 file changed, 11 insertions(+), 43 deletions(-) diff --git a/scripts/migration/import.sql b/scripts/migration/import.sql index 893a2b9..5faaa1c 100644 --- a/scripts/migration/import.sql +++ b/scripts/migration/import.sql @@ -2,7 +2,6 @@ insert cemeteries set id=1,name='White Oak'; insert cemeteries set id=2,name='Rose Hill'; - insert deeds (id,section,lot,lastname1,firstname1,middleInitial1, lastname2,firstname2,middleInitial2,issueDate,notes,lot2,cemetery_id) select r.ID,r.SEC,r.LOT,r.LNAME1,r.FNAME1,r.MI1, @@ -13,50 +12,19 @@ left join cemeteries c on r.whiteoak=substr(c.name,1,1); update rosehill.ROSEHILL set WHITEOAK='R' where WHITEOAK is null; -insert interments(id,section,lot,book,pageNumber,deceasedDate, +insert sections (code,cemetery_id) +select distinct SEC,1 from rosehill.ROSEHILL where WHITEOAK='W' and SEC is not null; + +insert sections (code,cemetery_id) +select distinct SEC,2 from rosehill.ROSEHILL where WHITEOAK='R' and SEC is not null; + + +insert interments(id,section_id,lot,book,pageNumber,deceasedDate, lastname,firstname,middleInitial, birthPlace,lastResidence,age,sex,cemetery_id,notes,lot2) -select r.ID,r.SEC,r.LOT,r.BOOK,r.PAGENUM,r.DEATH, +select r.ID,s.id,r.LOT,r.BOOK,r.PAGENUM,r.DEATH, r.LNAME,r.FNAME,r.MI, r.POB,r.LATE_RES,r.AGE,r.SEX,c.id,r.NOTES,r.lot2 from rosehill.ROSEHILL r -left join cemeteries c on r.whiteoak=substr(c.name,1,1); - - --- Migrate the interment sections into a section_id foreign key'd to a sections table --- A little bit of cleanup on the data -update interments set section='P.G.' where section='P.G'; -update interments set section=null where section='0'; - -insert sections (code,cemetery_id) -select distinct section,1 from interments -where cemetery_id=1 and section is not null; - -insert sections (code,cemetery_id) -select distinct section,2 from interments -where cemetery_id=2 and section is not null; - - -alter table interments add section_id int unsigned after section; -alter table interments add foreign key (section_id) references sections(id); - -update interments,sections -set section_id=sections.id -where interments.section=sections.code -and interments.cemetery_id=sections.cemetery_id; - -alter table interments drop section; - --- Migrate the deeds sections into a section_id foreign key'd to a sections table -update deeds set section='A' where section='A MA'; -update deeds set section='R.H.' where section='R.H'; -update deeds set cemetery_id=2 where section='R.H.'; - - --- R.H. is not a section. It was the way people were marking the Cemetery to be RoseHill --- In these cases, the lot field has the actual section code -update interments set section_id=33,lot=null where section_id=39; -delete from sections where id=39; --- A case where people put the lot number in the section field -update interments set section_id=34,lot=49,cemetery_id=2 where section_id=45; -delete from sections where id=45; +left join cemeteries c on r.WHITEOAK=substr(c.name,1,1) +left join sections s on r.SEC=s.code and c.id=s.cemetery_id;