aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/schema_0029-rename_contacts_area_id.sql6
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);