Steuerkram/migrations/034_leistungszeitraum_text.sql

23 lines
905 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Leistungszeitraum: von zwei DATE-Feldern zu einem freien Textfeld
ALTER TABLE invoices
ADD COLUMN leistungszeitraum VARCHAR(255) NULL AFTER leistungszeitraum_bis;
-- Bestehende Daten migrieren: Datumsfelder als lesbaren Text zusammenführen
UPDATE invoices
SET leistungszeitraum = CASE
WHEN leistungszeitraum_von IS NOT NULL AND leistungszeitraum_bis IS NOT NULL
AND leistungszeitraum_von != leistungszeitraum_bis
THEN CONCAT(
DATE_FORMAT(leistungszeitraum_von, '%d.%m.%Y'),
' – ',
DATE_FORMAT(leistungszeitraum_bis, '%d.%m.%Y')
)
WHEN leistungszeitraum_von IS NOT NULL
THEN DATE_FORMAT(leistungszeitraum_von, '%d.%m.%Y')
ELSE NULL
END
WHERE leistungszeitraum_von IS NOT NULL OR leistungszeitraum_bis IS NOT NULL;
ALTER TABLE invoices
DROP COLUMN leistungszeitraum_von,
DROP COLUMN leistungszeitraum_bis;