Adding tests for Oracle->add_field
Daniel Ruoso [Wed, 23 Apr 2008 14:49:13 +0000 (14:49 +0000)]
t/55-oracle-add-field.t [new file with mode: 0644]
t/data/oracle/schema_diff_c.yaml [new file with mode: 0644]

diff --git a/t/55-oracle-add-field.t b/t/55-oracle-add-field.t
new file mode 100644 (file)
index 0000000..e4e2535
--- /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_b.yaml';
+my $schema2 = $Bin.'/data/oracle/schema_diff_c.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 ADD \( foo nvarchar2\(10\) NOT NULL \)/',
+     'Alter table generated.');
diff --git a/t/data/oracle/schema_diff_c.yaml b/t/data/oracle/schema_diff_c.yaml
new file mode 100644 (file)
index 0000000..78f2e5f
--- /dev/null
@@ -0,0 +1,66 @@
+---
+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
+        foo:
+          data_type: nvarchar2(10)
+          default_value: ~
+          extra: {}
+          is_nullable: 0
+          is_primary_key: 0
+          is_unique: 0
+          name: foo
+          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