From: Moritz Bunkus Date: Thu, 27 Jun 2013 10:32:00 +0000 (+0200) Subject: DB-Upgrade cvar-configs: sortkey neu bauen, um mit NULLs klarzukommen X-Git-Tag: release-3.1.0beta1~254^2~4 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=beafcfad4e5a9d4f69a498a04ad3c10ff92fe7bf;p=kivitendo-erp.git DB-Upgrade cvar-configs: sortkey neu bauen, um mit NULLs klarzukommen --- diff --git a/sql/Pg-upgrade2/custom_variable_configs_column_type_text.pl b/sql/Pg-upgrade2/custom_variable_configs_column_type_text.pl new file mode 100644 index 000000000..2f75f88f6 --- /dev/null +++ b/sql/Pg-upgrade2/custom_variable_configs_column_type_text.pl @@ -0,0 +1,70 @@ +# @tag: custom_variable_configs_column_type_text +# @description: Spaltentypen in 'custom_varialbe_configs' anpassen & schärfere Restriktionen +# @depends: release_3_0_0 +package SL::DBUpgrade2::custom_variable_configs_column_type_text; + +use utf8; +use strict; + +use parent qw(SL::DBUpgrade2::Base); + +sub run { + my ($self) = @_; + + # Fix 'sortkey' column to not contain NULLs + my $q_update = qq|UPDATE custom_variable_configs SET sortkey = ? WHERE id = ?|; + my $h_update = $self->dbh->prepare($q_update) || die $self->dbh->errstr; + + my $q_select = <dbh->selectall_arrayref($q_select) }) { + $sortkey = $previous_module eq $entry->[1] ? $sortkey + 1 : 1; + $previous_module = $entry->[1]; + + $h_update->execute($sortkey, $entry->[0]) || die $self->dbh->errstr; + } + + $h_update->finish; + + # Apply structure upgrade + my @statements = ( + qq|ALTER TABLE custom_variable_configs ALTER COLUMN type TYPE TEXT|, + qq|ALTER TABLE custom_variable_configs ALTER COLUMN module TYPE TEXT|, + + qq|UPDATE custom_variable_configs SET searchable = FALSE WHERE searchable IS NULL|, + qq|UPDATE custom_variable_configs SET includeable = FALSE WHERE includeable IS NULL|, + qq|UPDATE custom_variable_configs SET included_by_default = FALSE WHERE included_by_default IS NULL|, + + qq|ALTER TABLE custom_variable_configs ALTER COLUMN searchable SET NOT NULL|, + qq|ALTER TABLE custom_variable_configs ALTER COLUMN includeable SET NOT NULL|, + qq|ALTER TABLE custom_variable_configs ALTER COLUMN included_by_default SET NOT NULL|, + qq|ALTER TABLE custom_variable_configs ALTER COLUMN name SET NOT NULL|, + qq|ALTER TABLE custom_variable_configs ALTER COLUMN description SET NOT NULL|, + qq|ALTER TABLE custom_variable_configs ALTER COLUMN type SET NOT NULL|, + qq|ALTER TABLE custom_variable_configs ALTER COLUMN module SET NOT NULL|, + qq|ALTER TABLE custom_variable_configs ALTER COLUMN sortkey SET NOT NULL|, + + qq|ALTER TABLE custom_variable_configs + ADD CONSTRAINT custom_variable_configs_name_description_type_module_not_empty + CHECK ( type <> '' + AND module <> '' + AND name <> '' + AND description <> '')|, + + qq|ALTER TABLE custom_variable_configs + ADD CONSTRAINT custom_variable_configs_options_not_empty_for_select + CHECK ((type <> 'select') OR (COALESCE(options, '') <> ''))|, + ); + + $self->db_query($_) for @statements; + + return 1; +} + +1; diff --git a/sql/Pg-upgrade2/custom_variable_configs_column_type_text.sql b/sql/Pg-upgrade2/custom_variable_configs_column_type_text.sql deleted file mode 100644 index 98ebbbc05..000000000 --- a/sql/Pg-upgrade2/custom_variable_configs_column_type_text.sql +++ /dev/null @@ -1,30 +0,0 @@ --- @tag: custom_variable_configs_column_type_text --- @description: Spaltentypen in 'custom_varialbe_configs' anpassen & schärfere Restriktionen --- @depends: release_3_0_0 --- @charset: utf-8 -ALTER TABLE custom_variable_configs ALTER COLUMN type TYPE TEXT; -ALTER TABLE custom_variable_configs ALTER COLUMN module TYPE TEXT; - -UPDATE custom_variable_configs SET searchable = FALSE WHERE searchable IS NULL; -UPDATE custom_variable_configs SET includeable = FALSE WHERE includeable IS NULL; -UPDATE custom_variable_configs SET included_by_default = FALSE WHERE included_by_default IS NULL; - -ALTER TABLE custom_variable_configs ALTER COLUMN searchable SET NOT NULL; -ALTER TABLE custom_variable_configs ALTER COLUMN includeable SET NOT NULL; -ALTER TABLE custom_variable_configs ALTER COLUMN included_by_default SET NOT NULL; -ALTER TABLE custom_variable_configs ALTER COLUMN name SET NOT NULL; -ALTER TABLE custom_variable_configs ALTER COLUMN description SET NOT NULL; -ALTER TABLE custom_variable_configs ALTER COLUMN type SET NOT NULL; -ALTER TABLE custom_variable_configs ALTER COLUMN module SET NOT NULL; -ALTER TABLE custom_variable_configs ALTER COLUMN sortkey SET NOT NULL; - -ALTER TABLE custom_variable_configs -ADD CONSTRAINT custom_variable_configs_name_description_type_module_not_empty -CHECK ( type <> '' - AND module <> '' - AND name <> '' - AND description <> ''); - -ALTER TABLE custom_variable_configs -ADD CONSTRAINT custom_variable_configs_options_not_empty_for_select -CHECK ((type <> 'select') OR (COALESCE(options, '') <> ''));