diff options
author | Matthew Somerville <matthew@mysociety.org> | 2013-02-01 12:49:41 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2013-02-01 12:49:41 +0000 |
commit | 28aa1dd7fb1c9bc93aa204afae67cf68fe36ee6b (patch) | |
tree | c670826441c4861023c128faef5904600a5858c1 | |
parent | 46d078d170adba70ff256af66256ee01a3d31125 (diff) |
Get schema to make sure the body table has the right things in it for the move.
-rw-r--r-- | db/schema_0029-rename_contacts_area_id.sql | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/db/schema_0029-rename_contacts_area_id.sql b/db/schema_0029-rename_contacts_area_id.sql index e28f73802..861ace5c5 100644 --- a/db/schema_0029-rename_contacts_area_id.sql +++ b/db/schema_0029-rename_contacts_area_id.sql @@ -4,6 +4,12 @@ ALTER TABLE contacts RENAME area_id TO body_id; ALTER TABLE contacts_history RENAME area_id TO body_id; ALTER INDEX contacts_area_id_category_idx RENAME TO contacts_body_id_category_idx; +-- Data migration +UPDATE body SET id = area_id; +INSERT INTO body (id, area_id) + SELECT DISTINCT body_id, body_id FROM contacts WHERE body_id not in (SELECT id FROM body); +SELECT setval('body_id_seq', (SELECT MAX(id) FROM body) ); + ALTER TABLE contacts ADD CONSTRAINT contacts_body_id_fkey FOREIGN KEY (body_id) REFERENCES body(id); |