Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in Parser::DBI::PostgreSQL data_type, size, and default_value #155

Merged
merged 3 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/SQL/Translator/Parser/DBI/PostgreSQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ ORDER BY 1;
elsif ($default =~ /^'(.*?)'(::\Q$type\E)?$/) {
my $str= $1;
$str =~ s/''/'/g;
$col->default_value($1)
$col->default_value($str);
}
else { $col->default_value(\$default) }
}
Expand Down
7 changes: 6 additions & 1 deletion t/66-postgres-dbi-parser.t
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ my $sql = q[

CREATE TABLE sqlt_products_1 (
product_no integer,
name text,
name text default '['''']',
price numeric(8,4) default 0.0,
created_at timestamp without time zone default now()
);
Expand Down Expand Up @@ -166,6 +166,11 @@ isa_ok( $fk_ref1, 'SQL::Translator::Schema::Constraint', 'FK' );
is( $fk_ref1->reference_table, 'sqlt_test1', 'FK is to "sqlt_test1" table' );

my $t3 = $schema->get_table("sqlt_products_1");

my $t3_f2= $t3->get_field('name');
is( $t3_f2->data_type, 'text', 'Second field, type "text"' );
is( $t3_f2->default_value, q{['']}, 'default value is json array of empty string' );

my $t3_f3= $t3->get_field('price');
is( $t3_f3->name, 'price', 'Third field is "price"' );
is( $t3_f3->data_type, 'numeric', 'Third field type "numeric"' );
Expand Down