chill-import-from-canvas/sql/import.sql

42 lines
1.7 KiB
MySQL
Raw Normal View History

2023-02-15 13:56:04 +00:00
--
-- CHILL REPRISE DE DONNEES
2023-02-15 16:54:26 +00:00
-- version v0.6 (== version canevas)
2023-02-15 13:56:04 +00:00
--
2023-02-15 16:54:26 +00:00
-- /!\ IMPORTANT
2023-02-15 13:56:04 +00:00
-- * Avant de migrer (UP), il faut d'abord importer les codes postaux !!!
--
2023-02-15 16:54:26 +00:00
-- 1. Adjust Type cast for id columns
ALTER TABLE import.personnes ALTER COLUMN id TYPE INTEGER USING (id::integer);
ALTER TABLE import.periodes ALTER COLUMN id TYPE INTEGER USING (id::integer);
2023-02-15 17:08:06 +00:00
-- 2. Copy date columns with right date type
ALTER TABLE import.personnes ADD column birthdate1 DATE; UPDATE import.personnes SET birthdate1 = to_date(birthdate,'DD/MM/YYYY') WHERE birthdate != '';
ALTER TABLE import.personnes ADD column deathdate1 DATE; UPDATE import.personnes SET deathdate1 = to_date(deathdate,'DD/MM/YYYY') WHERE deathdate != '';
ALTER TABLE import.personnes ADD column validfrom1 DATE; UPDATE import.personnes SET validfrom1 = to_date(validfrom,'DD/MM/YYYY') WHERE validfrom != '';
ALTER TABLE import.personnes ADD column household_startdate1 DATE; UPDATE import.personnes SET household_startdate1 = to_date(household_startdate,'DD/MM/YYYY') WHERE household_startdate != '';
ALTER TABLE import.periodes ADD column openingdate1 DATE; UPDATE import.periodes SET openingdate1 = to_date(openingdate::text,'DD/MM/YYYY') WHERE openingdate != '';
ALTER TABLE import.periodes ADD column closingdate1 DATE; UPDATE import.periodes SET closingdate1 = to_date(closingdate,'DD/MM/YYYY') WHERE closingdate != '';
2023-02-15 13:56:04 +00:00
--
-- UP
--
--
-- DOWN
--
2023-02-15 17:08:06 +00:00
-- Undo 2.
ALTER TABLE import.personnes DROP column birthdate1;
ALTER TABLE import.personnes DROP column deathdate1;
ALTER TABLE import.personnes DROP column validfrom1;
ALTER TABLE import.personnes DROP column household_startdate1;
ALTER TABLE import.periodes DROP column openingdate1;
ALTER TABLE import.periodes DROP column closingdate1;
2023-02-15 13:56:04 +00:00
--
-- SELECT
--