numerus/revert/contact_tax_details.sql

65 lines
1.6 KiB
PL/PgSQL

-- Revert numerus:contact_tax_details from pg
begin;
set search_path to numerus, public;
alter table contact
drop constraint name_not_empty
, add column country_code country_code default 'ES'
, add column postal_code text default ''
, add column province text default ''
, add column city text default ''
, add column address text default ''
, add column vatin vatin default 'ES40404040D'
, add column business_name text default 'ACME' constraint business_name_not_empty check(length(trim(business_name)) > 1)
;
alter table contact
rename column name to trade_name
;
update contact
set business_name = trade_name
where true
;
update contact
set business_name = tax.business_name
, vatin = tax.vatin
, address = tax.address
, city = tax.city
, province = tax.province
, postal_code = tax.postal_code
, country_code = tax.country_code
from contact_tax_details as tax
where tax.contact_id = contact.contact_id
;
alter table contact
alter column business_name drop default
, alter column business_name set not null
, alter column vatin drop default
, alter column vatin set not null
, alter column vatin set not null
, alter column address drop default
, alter column address set not null
, alter column city drop default
, alter column city set not null
, alter column province drop default
, alter column province set not null
, alter column postal_code drop default
, alter column postal_code set not null
, alter column country_code drop default
, alter column country_code set not null
;
update contact
set trade_name = ''
where trade_name = business_name
;
drop table if exists contact_tax_details;
commit;