diff --git a/sql/import.sql b/sql/import.sql index 0e09ad1..40b5485 100644 --- a/sql/import.sql +++ b/sql/import.sql @@ -38,18 +38,27 @@ INSERT INTO chill_main_civility (id, name, abbreviation, active, ordering) ALTER TABLE import.choix_personnes ADD COLUMN country1 JSONB; UPDATE import.choix_personnes SET country1=json_build_object('fr', trim(country)) WHERE country!=''; INSERT INTO country (id, name, countrycode) -SELECT nextval('country_id_seq'), t.country1, 'ZZZ' + SELECT nextval('country_id_seq'), t.country1, 'ZZZ' FROM ( SELECT DISTINCT ON (country) country1 FROM import.choix_personnes WHERE country1 IS NOT NULL ) t WHERE NOT EXISTS ( SELECT 1 FROM country WHERE name::jsonb = t.country1 ); - - +-- 5. Complete table maritalstatus +ALTER TABLE import.choix_personnes ADD COLUMN maritalstatus1 JSONB; +UPDATE import.choix_personnes SET maritalstatus1=json_build_object('fr', trim(maritalstatus)) WHERE maritalstatus!=''; +INSERT INTO chill_person_marital_status (id, name) + SELECT substr(md5(random()::text), 1, 7), t.maritalstatus1 + FROM ( SELECT DISTINCT ON (maritalstatus) maritalstatus1 FROM import.choix_personnes WHERE maritalstatus1 IS NOT NULL ) t + WHERE NOT EXISTS ( SELECT 1 FROM chill_person_marital_status WHERE name::jsonb = t.maritalstatus1 ); -- -- DOWN -- +-- Undo 5. +DELETE FROM chill_person_marital_status cpms USING import.choix_personnes icp WHERE cpms.name::jsonb = icp.maritalstatus1::jsonb AND cpms.id <> 'célibat.' AND cpms.id <> 'marié'; -- existing marital status +ALTER TABLE import.choix_personnes DROP column maritalstatus1; + -- Undo 4. DELETE FROM country USING import.choix_personnes icp WHERE country.name::jsonb = icp.country1::jsonb AND country.id > 249; -- 249 existing countries SELECT setval('country_id_seq', (SELECT max(id) FROM country)); @@ -71,7 +80,7 @@ ALTER TABLE import.periodes DROP column closingdate1; -- ------------- --- personnes choices_list: gender maritalstatus household_composition_type household_position +-- personnes choices_list: gender household_composition_type household_position -- periodes choices_list: intensity referrer job acp_scopes acp_socialissues work_socialaction -- tiers choices_list: civility kind profession category