From 36b8f1ece3531e2f5fba5bc38932e450e57bb012 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 29 May 2015 15:26:58 +0200 Subject: [PATCH] Rechnungen: amount, netamount, paid NOT NULL DEFAULT 0 --- SL/DB/MetaSetup/Invoice.pm | 6 ++--- SL/DB/MetaSetup/PurchaseInvoice.pm | 6 ++--- .../invoices_amount_paid_not_null.sql | 24 +++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 sql/Pg-upgrade2/invoices_amount_paid_not_null.sql diff --git a/SL/DB/MetaSetup/Invoice.pm b/SL/DB/MetaSetup/Invoice.pm index 72aaa4505..ac7f6716f 100644 --- a/SL/DB/MetaSetup/Invoice.pm +++ b/SL/DB/MetaSetup/Invoice.pm @@ -9,7 +9,7 @@ use base qw(SL::DB::Object); __PACKAGE__->meta->table('ar'); __PACKAGE__->meta->columns( - amount => { type => 'numeric', precision => 15, scale => 5 }, + amount => { type => 'numeric', default => '0', not_null => 1, precision => 15, scale => 5 }, cp_id => { type => 'integer' }, currency_id => { type => 'integer', not_null => 1 }, cusordnumber => { type => 'text' }, @@ -37,11 +37,11 @@ __PACKAGE__->meta->columns( marge_percent => { type => 'numeric', precision => 15, scale => 5 }, marge_total => { type => 'numeric', precision => 15, scale => 5 }, mtime => { type => 'timestamp' }, - netamount => { type => 'numeric', precision => 15, scale => 5 }, + netamount => { type => 'numeric', default => '0', not_null => 1, precision => 15, scale => 5 }, notes => { type => 'text' }, orddate => { type => 'date' }, ordnumber => { type => 'text' }, - paid => { type => 'numeric', precision => 15, scale => 5 }, + paid => { type => 'numeric', default => '0', not_null => 1, precision => 15, scale => 5 }, payment_id => { type => 'integer' }, quodate => { type => 'date' }, quonumber => { type => 'text' }, diff --git a/SL/DB/MetaSetup/PurchaseInvoice.pm b/SL/DB/MetaSetup/PurchaseInvoice.pm index b3cb02970..cc5eb4d9e 100644 --- a/SL/DB/MetaSetup/PurchaseInvoice.pm +++ b/SL/DB/MetaSetup/PurchaseInvoice.pm @@ -9,7 +9,7 @@ use base qw(SL::DB::Object); __PACKAGE__->meta->table('ap'); __PACKAGE__->meta->columns( - amount => { type => 'numeric', precision => 15, scale => 5 }, + amount => { type => 'numeric', default => '0', not_null => 1, precision => 15, scale => 5 }, cp_id => { type => 'integer' }, currency_id => { type => 'integer', not_null => 1 }, datepaid => { type => 'date' }, @@ -28,11 +28,11 @@ __PACKAGE__->meta->columns( itime => { type => 'timestamp', default => 'now()' }, language_id => { type => 'integer' }, mtime => { type => 'timestamp' }, - netamount => { type => 'numeric', precision => 15, scale => 5 }, + netamount => { type => 'numeric', default => '0', not_null => 1, precision => 15, scale => 5 }, notes => { type => 'text' }, orddate => { type => 'date' }, ordnumber => { type => 'text' }, - paid => { type => 'numeric', precision => 15, scale => 5 }, + paid => { type => 'numeric', default => '0', not_null => 1, precision => 15, scale => 5 }, payment_id => { type => 'integer' }, quodate => { type => 'date' }, quonumber => { type => 'text' }, diff --git a/sql/Pg-upgrade2/invoices_amount_paid_not_null.sql b/sql/Pg-upgrade2/invoices_amount_paid_not_null.sql new file mode 100644 index 000000000..9add1418a --- /dev/null +++ b/sql/Pg-upgrade2/invoices_amount_paid_not_null.sql @@ -0,0 +1,24 @@ +-- @tag: invoices_amount_paid_not_null +-- @description: Bei Rechnungen die drei Spalten "amount", "netamount" und "paid" auf NOT NULL setzen +-- @depends: release_3_2_0 +-- @encoding: utf-8 + +UPDATE ar SET amount = 0 WHERE amount IS NULL; +ALTER TABLE ar ALTER COLUMN amount SET NOT NULL; +ALTER TABLE ar ALTER COLUMN amount SET DEFAULT 0; +UPDATE ar SET netamount = 0 WHERE netamount IS NULL; +ALTER TABLE ar ALTER COLUMN netamount SET NOT NULL; +ALTER TABLE ar ALTER COLUMN netamount SET DEFAULT 0; +UPDATE ar SET paid = 0 WHERE paid IS NULL; +ALTER TABLE ar ALTER COLUMN paid SET NOT NULL; +ALTER TABLE ar ALTER COLUMN paid SET DEFAULT 0; + +UPDATE ap SET amount = 0 WHERE amount IS NULL; +ALTER TABLE ap ALTER COLUMN amount SET NOT NULL; +ALTER TABLE ap ALTER COLUMN amount SET DEFAULT 0; +UPDATE ap SET netamount = 0 WHERE netamount IS NULL; +ALTER TABLE ap ALTER COLUMN netamount SET NOT NULL; +ALTER TABLE ap ALTER COLUMN netamount SET DEFAULT 0; +UPDATE ap SET paid = 0 WHERE paid IS NULL; +ALTER TABLE ap ALTER COLUMN paid SET NOT NULL; +ALTER TABLE ap ALTER COLUMN paid SET DEFAULT 0; -- 2.20.1