Test for oracle alter_field
Daniel Ruoso [Mon, 14 Apr 2008 17:06:41 +0000 (17:06 +0000)]
t/54-oracle-alter-field.t [new file with mode: 0644]
t/data/oracle/schema_diff_a.yaml [new file with mode: 0644]
t/data/oracle/schema_diff_b.yaml [new file with mode: 0644]

diff --git a/t/54-oracle-alter-field.t b/t/54-oracle-alter-field.t
new file mode 100644 (file)
index 0000000..8619fc3
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+
+use FindBin qw/$Bin/;
+use Test::More;
+use Test::SQL::Translator;
+use Test::Exception;
+use Data::Dumper;
+use SQL::Translator;
+use SQL::Translator::Diff;
+
+BEGIN {
+    maybe_plan(2, 'SQL::Translator::Parser::YAML',
+                  'SQL::Translator::Producer::Oracle');
+}
+
+my $schema1 = $Bin.'/data/oracle/schema_diff_a.yaml';
+my $schema2 = $Bin.'/data/oracle/schema_diff_b.yaml';
+
+open my $io1, '<', $schema1 or die $!;
+open my $io2, '<', $schema2 or die $!;
+
+my ($yaml1, $yaml2);
+{
+    local $/ = undef;
+    $yaml1 = <$io1>;
+    $yaml2 = <$io2>;
+};
+
+close $io1;
+close $io2;
+
+my $s = SQL::Translator->new(from => 'YAML');
+$s->parser->($s,$yaml1);
+
+my $t = SQL::Translator->new(from => 'YAML');
+$t->parser->($t,$yaml2);
+
+my $d = SQL::Translator::Diff->new
+  ({
+    output_db => 'Oracle',
+    source_schema => $s->schema,
+    target_schema => $t->schema,
+   });
+
+
+my $diff = $d->compute_differences->produce_diff_sql || die $d->error;
+
+ok($diff, 'Diff generated.');
+like($diff, '/ALTER TABLE d_operator CHANGE COLUMN \( name nvarchar2\(10\) \)/',
+     'Alter table generated.');
diff --git a/t/data/oracle/schema_diff_a.yaml b/t/data/oracle/schema_diff_a.yaml
new file mode 100644 (file)
index 0000000..ab0d955
--- /dev/null
@@ -0,0 +1,44 @@
+---
+schema:
+  procedures: {}
+  tables:
+    d_operator:
+      constraints:
+        - deferrable: 1
+          expression: ''
+          fields:
+            - id_operator
+          match_type: ''
+          name: ''
+          on_delete: ''
+          on_update: ''
+          options: []
+          reference_fields: []
+          reference_table: ''
+          type: PRIMARY KEY
+      fields:
+        id_operator:
+          data_type: integer
+          default_value: ~
+          extra: {}
+          is_auto_increment: 1
+          is_nullable: 0
+          is_primary_key: 1
+          is_unique: 0
+          name: id_operator
+          order: 58
+          size:
+            - 0
+        name:
+          data_type: varchar2(10)
+          default_value: ~
+          extra: {}
+          is_nullable: 0
+          is_primary_key: 0
+          is_unique: 0
+          name: name
+          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
new file mode 100644 (file)
index 0000000..1fbbf90
--- /dev/null
@@ -0,0 +1,44 @@
+---
+schema:
+  procedures: {}
+  tables:
+    d_operator:
+      constraints:
+        - deferrable: 1
+          expression: ''
+          fields:
+            - id_operator
+          match_type: ''
+          name: ''
+          on_delete: ''
+          on_update: ''
+          options: []
+          reference_fields: []
+          reference_table: ''
+          type: PRIMARY KEY
+      fields:
+        id_operator:
+          data_type: integer
+          default_value: ~
+          extra: {}
+          is_auto_increment: 1
+          is_nullable: 0
+          is_primary_key: 1
+          is_unique: 0
+          name: id_operator
+          order: 58
+          size:
+            - 0
+        name:
+          data_type: nvarchar2(10)
+          default_value: ~
+          extra: {}
+          is_nullable: 0
+          is_primary_key: 0
+          is_unique: 0
+          name: name
+          order: 59
+          size:
+            - 0
+      name: d_operator
+      order: 11