A bit of data-massaging
Posted by mholmes on 11 Feb 2011 in Activity log
The final requirement for implementing the one-to-many version of docPeriods
was to split composite docPeriods
into two separate individual entries. So where, before, there were these items:
- 1 AR Ancien Régime - 1789
- 2 FR French Revolution 1789-1799
- 3 c19 19th century : 1800 -
- 4 AR - FR Starting in the Old Regime and continuing on past ...
- 5 FR - c19 Starting in the Revolution and continuing on past ...
- 6 n/k Period not yet established
we need to convert all instances of the composite 4 and 5 into multiples of 1 and 2 or 2 and 3 respectively.
My test records for this were 305 (AR-FR) and 145 (FR - c19). This is the code:
INSERT INTO `docs_to_docPeriods` (`dtp_doc_id_fk`,`dtp_docPeriod_id_fk`) SELECT `doc_id`, "1" FROM `documents` WHERE `documents`.`doc_to_docPeriods_id` = "4" INSERT INTO `docs_to_docPeriods` (`dtp_doc_id_fk`,`dtp_docPeriod_id_fk`) SELECT `doc_id`, "2" FROM `documents` WHERE `documents`.`doc_to_docPeriods_id` = "4" DELETE FROM `docs_to_docPeriods` WHERE `dtp_docPeriod_id_fk` = "4" INSERT INTO `docs_to_docPeriods` (`dtp_doc_id_fk`,`dtp_docPeriod_id_fk`) SELECT `doc_id`, "2" FROM `documents` WHERE `documents`.`doc_to_docPeriods_id` = "5" INSERT INTO `docs_to_docPeriods` (`dtp_doc_id_fk`,`dtp_docPeriod_id_fk`) SELECT `doc_id`, "3" FROM `documents` WHERE `documents`.`doc_to_docPeriods_id` = "5" DELETE FROM `docs_to_docPeriods` WHERE `dtp_docPeriod_id_fk` = "5"
Tested first on the dev db, then run on the live db. I've left those composite periods in place in the docPeriods
table, just in case, and I've also left the old doc_to_docPeriods_id
field in the documents
table just in case. We can clean this stuff up later, once we're both sure everything's working well.