From: Peter Mottram Date: Sat, 23 Aug 2014 10:16:16 +0000 (+0200) Subject: test to demonstrate Pg diff failure with rename_table+rename_field X-Git-Tag: v0.11019~1^2~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=591b4fa98fe80c43ea4420539ca94ac1822b3315;p=dbsrgits%2FSQL-Translator.git test to demonstrate Pg diff failure with rename_table+rename_field --- diff --git a/t/postgresql-rename-table-and-field.t b/t/postgresql-rename-table-and-field.t new file mode 100644 index 0000000..48a81b1 --- /dev/null +++ b/t/postgresql-rename-table-and-field.t @@ -0,0 +1,71 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Test::More; +use Test::SQL::Translator; +use SQL::Translator; +use SQL::Translator::Diff; + +maybe_plan(10, 'DBD::Pg', 'Test::PostgreSQL'); + +my ( $pgsql, $dbh , $ddl, $ret ); + +no warnings "once"; +$pgsql = Test::PostgreSQL->new() or plan skip_all => $Test::PostgreSQL::errstr; +$dbh = DBI->connect($pgsql->dsn,'','', { RaiseError => 1 }) or plan skip_all => $DBI::errstr; +use warnings "once"; + +my $source_ddl = <do($source_ddl), "create table" ); + +ok( $ret = $dbh->do(q| INSERT INTO foo (bar) VALUES ('buzz') |), "insert data" ); + +cmp_ok( $ret, '==', 1, "one row inserted" ); + +my $target_ddl = <new( + no_comments => 1, + parser => 'SQL::Translator::Parser::PostgreSQL', +)->translate(\$source_ddl); + +my $target_sqlt = SQL::Translator->new( + no_comments => 1, + parser => 'SQL::Translator::Parser::PostgreSQL', +)->translate(\$target_ddl); + +my $table = $target_sqlt->get_table('fluff'); +$table->extra( renamed_from => 'foo' ); +my $field = $table->get_field('biff'); +$field->extra( renamed_from => 'bar' ); + +my @diff = SQL::Translator::Diff->new({ + output_db => 'PostgreSQL', + source_schema => $source_sqlt, + target_schema => $target_sqlt, +})->compute_differences->produce_diff_sql; + +foreach my $line (@diff) { + $line =~ s/\n//g; + next if $line =~ /^--/; + ok( $dbh->do($line), "$line" ); +} + +ok ( $ret = $dbh->selectall_arrayref(q(SELECT biff FROM fluff), { Slice => {} }), "query DB for data" ); + +cmp_ok( scalar(@$ret), '==', 1, "Got 1 row"); + +cmp_ok( $ret->[0]->{biff}, 'eq', 'buzz', "col biff has value buzz" );