diff --git a/db_scripts/diff/15062.down b/db_scripts/diff/15062.down new file mode 100644 index 00000000..4dd2416b --- /dev/null +++ b/db_scripts/diff/15062.down @@ -0,0 +1,30 @@ +USE billing; + +SET FOREIGN_KEY_CHECKS = 0; + +-- note that the vat information is lost, when this script is executed + +BEGIN WORK; + +ALTER TABLE billing_profiles + ADD COLUMN vat_rate TINYINT(3) UNSIGNED NOT NULL DEFAULT 0, + ADD COLUMN vat_included TINYINT(1) UNSIGNED NOT NULL DEFAULT 0; + +ALTER TABLE contracts + DROP COLUMN vat_rate, + DROP COLUMN add_vat; + +alter table contacts + DROP column bank_name, + DROP column gpp0, + DROP column gpp1, + DROP column gpp2, + DROP column gpp3, + DROP column gpp4, + DROP column gpp5, + DROP column gpp6, + DROP column gpp7, + DROP column gpp8, + DROP column gpp9; + +COMMIT; diff --git a/db_scripts/diff/15062.up b/db_scripts/diff/15062.up index 9658cdb5..61acfd49 100644 --- a/db_scripts/diff/15062.up +++ b/db_scripts/diff/15062.up @@ -2,14 +2,27 @@ USE billing; SET FOREIGN_KEY_CHECKS = 0; -ALTER TABLE billing_profiles - DROP COLUMN vat_rate, - DROP COLUMN vat_included; +BEGIN WORK; ALTER TABLE contracts ADD COLUMN vat_rate TINYINT(3) UNSIGNED NOT NULL DEFAULT 0, ADD COLUMN add_vat TINYINT(1) UNSIGNED NOT NULL DEFAULT 0; +-- preserve the vat information by copying it from billing_profiles to contracts +UPDATE contracts c + JOIN billing_mappings m ON c.id = m.contract_id AND + m.id = ( + SELECT mi.id FROM billing_mappings mi WHERE mi.contract_id = c.id + ORDER BY start_date DESC LIMIT 1) + JOIN billing_profiles p ON m.billing_profile_id = p.id +SET + c.vat_rate = p.vat_rate, + c.add_vat = p.vat_included; + +ALTER TABLE billing_profiles + DROP COLUMN vat_rate, + DROP COLUMN vat_included; + DROP TABLE IF EXISTS invoice_templates; CREATE TABLE `invoice_templates` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, @@ -54,3 +67,5 @@ alter table contacts add column gpp7 varchar(255) default null, add column gpp8 varchar(255) default null, add column gpp9 varchar(255) default null; + +COMMIT;