From: Justin Hunter Date: Tue, 9 Feb 2010 06:36:12 +0000 (-0800) Subject: test at least runs now X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=783664978483415826341b5d40bcae0d6ac880a1;p=dbsrgits%2FSQL-Translator-2.0-ish.git test at least runs now --- diff --git a/t/47postgres-producer.t b/t/47postgres-producer.t index 60600e5..7c075d1 100644 --- a/t/47postgres-producer.t +++ b/t/47postgres-producer.t @@ -11,8 +11,10 @@ use Test::Differences; use SQL::Translator; use SQL::Translator::Object::Table; use SQL::Translator::Object::Column; +use SQL::Translator::Object::View; -my $PRODUCER = \&SQL::Translator::Producer::PostgreSQL::create_field; +my $sqlt = SQL::Translator->new( to => 'PostgreSQL' ); +my $producer = $sqlt->_producer; my $table = SQL::Translator::Object::Table->new( name => 'mytable'); @@ -26,7 +28,7 @@ my $field1 = SQL::Translator::Object::Column->new( name => 'myfield', is_foreign_key => 0, is_unique => 0 ); -my $field1_sql = SQL::Translator::Producer::PostgreSQL::create_field($field1); +my $field1_sql = $producer->create_field($field1); is($field1_sql, 'myfield character varying(10)', 'Create field works'); @@ -40,18 +42,18 @@ my $field2 = SQL::Translator::Object::Column->new( name => 'myfield', is_foreign_key => 0, is_unique => 0 ); -my $alter_field = SQL::Translator::Producer::PostgreSQL::alter_field($field1, +my $alter_field = $producer->alter_field($field1, $field2); is($alter_field, qq[ALTER TABLE mytable ALTER COLUMN myfield SET NOT NULL ALTER TABLE mytable ALTER COLUMN myfield TYPE character varying(25)], 'Alter field works'); $field1->name('field3'); -my $add_field = SQL::Translator::Producer::PostgreSQL::add_field($field1); +my $add_field = $producer->add_field($field1); is($add_field, 'ALTER TABLE mytable ADD COLUMN field3 character varying(10)', 'Add field works'); -my $drop_field = SQL::Translator::Producer::PostgreSQL::drop_field($field2); +my $drop_field = $producer->drop_field($field2); is($drop_field, 'ALTER TABLE mytable DROP COLUMN myfield', 'Drop field works'); my $field3 = SQL::Translator::Object::Column->new( name => 'time_field', @@ -63,7 +65,7 @@ my $field3 = SQL::Translator::Object::Column->new( name => 'time_field', is_foreign_key => 0, is_unique => 0 ); -my $field3_sql = SQL::Translator::Producer::PostgreSQL::create_field($field3); +my $field3_sql = $producer->create_field($field3); is($field3_sql, 'time_field time NOT NULL', 'Create time field works'); @@ -75,7 +77,7 @@ my $field3_datetime_with_TZ = SQL::Translator::Object::Column->new( ); my $field3_datetime_with_TZ_sql = - SQL::Translator::Producer::PostgreSQL::create_field( + $producer->create_field( $field3_datetime_with_TZ ); @@ -93,7 +95,7 @@ my $field3_time_without_TZ = SQL::Translator::Object::Column->new( ); my $field3_time_without_TZ_sql - = SQL::Translator::Producer::PostgreSQL::create_field( + = $producer->create_field( $field3_time_without_TZ ); @@ -113,7 +115,7 @@ my $field4 = SQL::Translator::Object::Column->new( name => 'bytea_field', is_foreign_key => 0, is_unique => 0 ); -my $field4_sql = SQL::Translator::Producer::PostgreSQL::create_field($field4); +my $field4_sql = $producer->create_field($field4); is($field4_sql, 'bytea_field bytea NOT NULL', 'Create bytea field works'); @@ -126,7 +128,7 @@ my $field5 = SQL::Translator::Object::Column->new( name => 'enum_field', is_foreign_key => 0, is_unique => 0 ); -my $field5_sql = SQL::Translator::Producer::PostgreSQL::create_field($field5,{ postgres_version => 8.3 }); +my $field5_sql = $producer->create_field($field5,{ postgres_version => 8.3 }); is($field5_sql, 'enum_field mytable_enum_field_type NOT NULL', 'Create real enum field works'); @@ -155,21 +157,21 @@ my $field7 = SQL::Translator::Object::Column->new( is_foreign_key => 0, is_unique => 0); -$alter_field = SQL::Translator::Producer::PostgreSQL::alter_field($field6, +$alter_field = $producer->alter_field($field6, $field7); is($alter_field, q(ALTER TABLE mytable ALTER COLUMN character DROP DEFAULT), 'DROP DEFAULT'); $field7->default_value(q(foo'bar')); -$alter_field = SQL::Translator::Producer::PostgreSQL::alter_field($field6, +$alter_field = $producer->alter_field($field6, $field7); is($alter_field, q(ALTER TABLE mytable ALTER COLUMN character SET DEFAULT 'foo''bar'''), 'DEFAULT with escaping'); $field7->default_value(\q(foobar)); -$alter_field = SQL::Translator::Producer::PostgreSQL::alter_field($field6, +$alter_field = $producer->alter_field($field6, $field7); is($alter_field, q(ALTER TABLE mytable ALTER COLUMN character SET DEFAULT foobar), 'DEFAULT unescaped if scalarref'); @@ -177,7 +179,7 @@ is($alter_field, q(ALTER TABLE mytable ALTER COLUMN character SET DEFAULT foobar $field7->is_nullable(1); $field7->default_value(q(foobar)); -$alter_field = SQL::Translator::Producer::PostgreSQL::alter_field($field6, +$alter_field = $producer->alter_field($field6, $field7); is($alter_field, q(ALTER TABLE mytable ALTER COLUMN character DROP NOT NULL), 'DROP NOT NULL'); @@ -191,7 +193,7 @@ my $field8 = SQL::Translator::Object::Column->new( name => 'ts_field', is_foreign_key => 0, is_unique => 0 ); -my $field8_sql = SQL::Translator::Producer::PostgreSQL::create_field($field8,{ postgres_version => 8.3 }); +my $field8_sql = $producer->create_field($field8,{ postgres_version => 8.3 }); is($field8_sql, 'ts_field timestamp(6) with time zone NOT NULL', 'timestamp with precision'); @@ -204,7 +206,7 @@ my $field9 = SQL::Translator::Object::Column->new( name => 'time_field', is_foreign_key => 0, is_unique => 0 ); -my $field9_sql = SQL::Translator::Producer::PostgreSQL::create_field($field9,{ postgres_version => 8.3 }); +my $field9_sql = $producer->create_field($field9,{ postgres_version => 8.3 }); is($field9_sql, 'time_field time(6) with time zone NOT NULL', 'time with precision'); @@ -217,7 +219,7 @@ my $field10 = SQL::Translator::Object::Column->new( name => 'interval_field', is_foreign_key => 0, is_unique => 0 ); -my $field10_sql = SQL::Translator::Producer::PostgreSQL::create_field($field10,{ postgres_version => 8.3 }); +my $field10_sql = $producer->create_field($field10,{ postgres_version => 8.3 }); is($field10_sql, 'interval_field interval(6) NOT NULL', 'time with precision'); @@ -231,7 +233,7 @@ my $field11 = SQL::Translator::Object::Column->new( name => 'time_field', is_foreign_key => 0, is_unique => 0 ); -my $field11_sql = SQL::Translator::Producer::PostgreSQL::create_field($field11,{ postgres_version => 8.3 }); +my $field11_sql = $producer->create_field($field11,{ postgres_version => 8.3 }); is($field11_sql, 'time_field time(6) without time zone NOT NULL', 'time with precision'); @@ -245,7 +247,7 @@ my $field12 = SQL::Translator::Object::Column->new( name => 'time_field', is_foreign_key => 0, is_unique => 0 ); -my $field12_sql = SQL::Translator::Producer::PostgreSQL::create_field($field12,{ postgres_version => 8.3 }); +my $field12_sql = $producer->create_field($field12,{ postgres_version => 8.3 }); is($field12_sql, 'time_field timestamp NOT NULL', 'time with precision'); @@ -270,7 +272,7 @@ is($field12_sql, 'time_field timestamp NOT NULL', 'time with precision'); ); is( - $PRODUCER->($simple_default), + $producer->create_field($simple_default), q{str_default character varying(10) DEFAULT 'foo'}, 'default str', ); @@ -284,7 +286,7 @@ is($field12_sql, 'time_field timestamp NOT NULL', 'time with precision'); ); is( - $PRODUCER->($null_default), + $producer->create_field($null_default), q{null_default character varying(10) DEFAULT NULL}, 'default null', ); @@ -298,7 +300,7 @@ is($field12_sql, 'time_field timestamp NOT NULL', 'time with precision'); ); is( - $PRODUCER->($null_default), + $producer->create_field($null_default), q{null_default_2 character varying(10) DEFAULT NULL}, 'default null from special cased string', ); @@ -312,7 +314,7 @@ is($field12_sql, 'time_field timestamp NOT NULL', 'time with precision'); ); is( - $PRODUCER->($func_default), + $producer->create_field($func_default), q{func_default character varying(10) DEFAULT func(funky)}, 'unquoted default from scalar ref', ); @@ -320,20 +322,20 @@ is($field12_sql, 'time_field timestamp NOT NULL', 'time with precision'); } -my $view1 = SQL::Translator::Schema::View->new( +my $view1 = SQL::Translator::Object::View->new( name => 'view_foo', fields => [qw/id name/], sql => 'SELECT id, name FROM thing', ); my $create_opts = { add_replace_view => 1, no_comments => 1 }; -my $view1_sql1 = SQL::Translator::Producer::PostgreSQL::create_view($view1, $create_opts); +my $view1_sql1 = $producer->create_view($view1, $create_opts); my $view_sql_replace = "CREATE VIEW view_foo ( id, name ) AS SELECT id, name FROM thing "; is($view1_sql1, $view_sql_replace, 'correct "CREATE OR REPLACE VIEW" SQL'); -my $view2 = SQL::Translator::Schema::View->new( +my $view2 = SQL::Translator::Object::View->new( name => 'view_foo2', sql => 'SELECT id, name FROM thing', extra => { @@ -342,7 +344,7 @@ my $view2 = SQL::Translator::Schema::View->new( }, ); my $create2_opts = { add_replace_view => 1, no_comments => 1 }; -my $view2_sql1 = SQL::Translator::Producer::PostgreSQL::create_view($view2, $create2_opts); +my $view2_sql1 = $producer->create_view($view2, $create2_opts); my $view2_sql_replace = "CREATE TEMPORARY VIEW view_foo2 AS SELECT id, name FROM thing