From: Daniel Ruoso Date: Mon, 14 Apr 2008 17:29:23 +0000 (+0000) Subject: Fix ORA-01442: column to be modified to NOT NULL is already NOT NULL X-Git-Tag: v0.11008~318 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d888d4452e196f821764b5876a05037324f9581c;p=dbsrgits%2FSQL-Translator.git Fix ORA-01442: column to be modified to NOT NULL is already NOT NULL --- diff --git a/lib/SQL/Translator/Producer/Oracle.pm b/lib/SQL/Translator/Producer/Oracle.pm index 1d00b8d..98f78c9 100644 --- a/lib/SQL/Translator/Producer/Oracle.pm +++ b/lib/SQL/Translator/Producer/Oracle.pm @@ -433,6 +433,13 @@ sub alter_field { my ($field_create, $field_defs, $trigger_defs, $field_comments) = create_field($to_field, $options, {}); + # Fix ORA-01442 + if ($to_field->is_nullable && !$from_field->is_nullable) { + die 'Cannot remove NOT NULL from table field'; + } elsif (!$from_field->is_nullable && !$to_field->is_nullable) { + @$field_defs = map { s/ NOT NULL//; $_} @$field_defs; + } + my $table_name = $to_field->table->name; my $table_name_ur = unreserve( $table_name ); diff --git a/t/54-oracle-alter-field.t b/t/54-oracle-alter-field.t index c8cd4b9..c4f4584 100644 --- a/t/54-oracle-alter-field.t +++ b/t/54-oracle-alter-field.t @@ -9,7 +9,7 @@ use SQL::Translator; use SQL::Translator::Diff; BEGIN { - maybe_plan(2, 'SQL::Translator::Parser::YAML', + maybe_plan(3, 'SQL::Translator::Parser::YAML', 'SQL::Translator::Producer::Oracle'); } @@ -46,5 +46,7 @@ my $d = SQL::Translator::Diff->new my $diff = $d->compute_differences->produce_diff_sql || die $d->error; ok($diff, 'Diff generated.'); -like($diff, '/ALTER TABLE d_operator MODIFY \( name nvarchar2\(10\) NOT NULL \)/', +like($diff, '/ALTER TABLE d_operator MODIFY \( name nvarchar2\(10\) \)/', + 'Alter table generated.'); +like($diff, '/ALTER TABLE d_operator MODIFY \( other nvarchar2\(10\) NOT NULL \)/', 'Alter table generated.'); diff --git a/t/data/oracle/schema_diff_a.yaml b/t/data/oracle/schema_diff_a.yaml index ab0d955..9b66596 100644 --- a/t/data/oracle/schema_diff_a.yaml +++ b/t/data/oracle/schema_diff_a.yaml @@ -40,5 +40,16 @@ schema: order: 59 size: - 0 + other: + data_type: varchar2(10) + default_value: ~ + extra: {} + is_nullable: 1 + is_primary_key: 0 + is_unique: 0 + name: other + order: 59 + size: + - 0 name: d_operator order: 11 diff --git a/t/data/oracle/schema_diff_b.yaml b/t/data/oracle/schema_diff_b.yaml index 1fbbf90..9f050c5 100644 --- a/t/data/oracle/schema_diff_b.yaml +++ b/t/data/oracle/schema_diff_b.yaml @@ -40,5 +40,16 @@ schema: order: 59 size: - 0 + other: + data_type: nvarchar2(10) + default_value: ~ + extra: {} + is_nullable: 0 + is_primary_key: 0 + is_unique: 0 + name: other + order: 59 + size: + - 0 name: d_operator order: 11