Commit | Line | Data |
8c4efd11 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | use Test::Exception; |
8 | use Test::SQL::Translator qw(maybe_plan); |
9 | |
10 | use Data::Dumper; |
11 | use FindBin qw/$Bin/; |
12 | |
13 | # Testing 1,2,3,4... |
14 | #============================================================================= |
15 | |
16 | BEGIN { |
17 | maybe_plan(4, |
18 | 'SQL::Translator::Producer::PostgreSQL', |
19 | 'Test::Differences', |
20 | ) |
21 | } |
22 | use Test::Differences; |
23 | use SQL::Translator; |
24 | |
25 | |
26 | |
27 | my $table = SQL::Translator::Schema::Table->new( name => 'mytable'); |
28 | |
29 | my $field1 = SQL::Translator::Schema::Field->new( name => 'myfield', |
30 | table => $table, |
31 | data_type => 'VARCHAR', |
32 | size => 10, |
33 | default_value => undef, |
34 | is_auto_increment => 0, |
35 | is_nullable => 1, |
36 | is_foreign_key => 0, |
37 | is_unique => 0 ); |
38 | |
39 | my $field1_sql = SQL::Translator::Producer::PostgreSQL::create_field($field1); |
40 | |
41 | is($field1_sql, 'myfield character varying(10)', 'Create field works'); |
42 | |
43 | my $field2 = SQL::Translator::Schema::Field->new( name => 'myfield', |
44 | table => $table, |
45 | data_type => 'VARCHAR', |
46 | size => 25, |
47 | default_value => undef, |
48 | is_auto_increment => 0, |
49 | is_nullable => 0, |
50 | is_foreign_key => 0, |
51 | is_unique => 0 ); |
52 | |
53 | my $alter_field = SQL::Translator::Producer::PostgreSQL::alter_field($field1, |
54 | $field2); |
55 | is($alter_field, qq[ALTER TABLE mytable ALTER COLUMN myfield SET NOT NULL; |
56 | ALTER TABLE mytable ALTER COLUMN myfield TYPE character varying(25);], |
57 | 'Alter field works'); |
58 | |
59 | $field1->name('field3'); |
60 | my $add_field = SQL::Translator::Producer::PostgreSQL::add_field($field1); |
61 | |
62 | is($add_field, 'ALTER TABLE mytable ADD COLUMN field3 character varying(10);', 'Add field works'); |
63 | |
64 | my $drop_field = SQL::Translator::Producer::PostgreSQL::drop_field($field2); |
65 | is($drop_field, 'ALTER TABLE mytable DROP COLUMN myfield;', 'Drop field works'); |
66 | |
67 | |