Add renamed_from to tables.
[dbsrgits/SQL-Translator.git] / t / 47postgres-producer.t
CommitLineData
8c4efd11 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7use Test::Exception;
8use Test::SQL::Translator qw(maybe_plan);
9
10use Data::Dumper;
11use FindBin qw/$Bin/;
12
13# Testing 1,2,3,4...
14#=============================================================================
15
16BEGIN {
17 maybe_plan(4,
18 'SQL::Translator::Producer::PostgreSQL',
19 'Test::Differences',
20 )
21}
22use Test::Differences;
23use SQL::Translator;
24
25
26
27my $table = SQL::Translator::Schema::Table->new( name => 'mytable');
28
29my $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
39my $field1_sql = SQL::Translator::Producer::PostgreSQL::create_field($field1);
40
41is($field1_sql, 'myfield character varying(10)', 'Create field works');
42
43my $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
53my $alter_field = SQL::Translator::Producer::PostgreSQL::alter_field($field1,
54 $field2);
55is($alter_field, qq[ALTER TABLE mytable ALTER COLUMN myfield SET NOT NULL;
56ALTER TABLE mytable ALTER COLUMN myfield TYPE character varying(25);],
57 'Alter field works');
58
59$field1->name('field3');
60my $add_field = SQL::Translator::Producer::PostgreSQL::add_field($field1);
61
62is($add_field, 'ALTER TABLE mytable ADD COLUMN field3 character varying(10);', 'Add field works');
63
64my $drop_field = SQL::Translator::Producer::PostgreSQL::drop_field($field2);
65is($drop_field, 'ALTER TABLE mytable DROP COLUMN myfield;', 'Drop field works');
66
67