Updates Changes.
Mentions Oracle support in generate_pod POD in ::Loader::Base.
Adds checking for generic comments via ->next::method in ::DBI::Oracle
as well.
Wraps table/column comment queries for MySQL on information_schema in
try blocks, as not all versions of MySQL have information_schema (5.0+
do.)
Changes MySQL comment tests to use the new slurp_file util.
Makes the test messages in t/30_*.t more clear.
Revision history for Perl extension DBIx::Class::Schema::Loader
+ - generic table and column comments support
+ - MySQL table and column comments support
- support DOS line endings on *nix and *nix line ending on Win32
- add quiet option
- $schema->loader is now a public method
By default POD will be generated for columns and relationships, using database
metadata for the text if available and supported.
-Metadata can be stored in two ways.
+Comment metadata can be stored in two ways.
The first is that you can create two tables named C<table_comments> and
C<column_comments> respectively. They both need to have columns named
(If you wish you can change the name of these tables with the parameters
L</table_comments_table> and L</column_comments_table>.)
-As a fallback you can use built-in commenting mechanisms. Currently this
-is only supported for PostgreSQL and MySQL. To create comments in
-PostgreSQL you add statements of the form C<COMMENT ON TABLE some_table ...>.
-To create comments in MySQL you add C<COMMENT '...'> to the end of the
-column or table definition. Note that MySQL restricts the length of comments,
-and also does not handle complex Unicode characters properly.
+As a fallback you can use built-in commenting mechanisms. Currently this is
+only supported for PostgreSQL, Oracle and MySQL. To create comments in
+PostgreSQL you add statements of the form C<COMMENT ON TABLE some_table IS
+'...'>, the same syntax is used in Oracle. To create comments in MySQL you add
+C<COMMENT '...'> to the end of the column or table definition. Note that MySQL
+restricts the length of comments, and also does not handle complex Unicode
+characters properly.
Set this to C<0> to turn off all POD generation.
}
sub _table_comment {
- my ( $self, $table ) = @_;
- my ($table_comment) = $self->schema->storage->dbh->selectrow_array(
+ my $self = shift;
+ my ($table) = @_;
+
+ my $table_comment = $self->next::method(@_);
+
+ return $table_comment if $table_comment;
+
+ ($table_comment) = $self->schema->storage->dbh->selectrow_array(
q{
SELECT comments FROM all_tab_comments
WHERE owner = ?
}
sub _column_comment {
- my ( $self, $table, $column_number, $column_name ) = @_;
- my ($column_comment) = $self->schema->storage->dbh->selectrow_array(
+ my $self = shift;
+ my ($table, $column_number, $column_name) = @_;
+
+ my $column_comment = $self->next::method(@_);
+
+ return $column_comment if $column_comment;
+
+ ($column_comment) = $self->schema->storage->dbh->selectrow_array(
q{
SELECT comments FROM all_col_comments
WHERE owner = ?
use base 'DBIx::Class::Schema::Loader::DBI';
use mro 'c3';
use List::Util 'first';
+use Try::Tiny;
use namespace::clean;
our $VERSION = '0.07010';
my ( $self, $table ) = @_;
my $comment = $self->next::method($table);
if (not $comment) {
- ($comment) = $self->schema->storage->dbh->selectrow_array(
+ ($comment) = try { $self->schema->storage->dbh->selectrow_array(
qq{SELECT table_comment
FROM information_schema.tables
WHERE table_schema = schema()
AND table_name = ?
}, undef, $table);
+ };
# InnoDB likes to auto-append crap.
if (not $comment) {
# Do nothing.
$comment =~ s/; InnoDB.*//;
}
}
- return $comment || "Gotcha $table?";
+ return $comment;
}
sub _column_comment {
my ( $self, $table, $column_number, $column_name ) = @_;
my $comment = $self->next::method($table, $column_number, $column_name);
if (not $comment) {
- ($comment) = $self->schema->storage->dbh->selectrow_array(
+ ($comment) = try { $self->schema->storage->dbh->selectrow_array(
qq{SELECT column_comment
FROM information_schema.columns
WHERE table_schema = schema()
AND table_name = ?
AND column_name = ?
}, undef, $table, $column_name);
+ };
}
return $comment;
}
use strict;
-use File::Slurp qw(slurp);
+use DBIx::Class::Schema::Loader::Utils 'slurp_file';
use Test::More;
use lib qw(t/lib);
use dbixcsl_common_tests;
-use utf8;
-use Encode 'decode';
my $dsn = $ENV{DBICTEST_MYSQL_DSN} || '';
my $user = $ENV{DBICTEST_MYSQL_USER} || '';
'hairy enum introspected correctly';
my $class = $classes->{'mysql_loader-test1'};
- my $filename = $schema->_loader->get_dump_filename($class);
+ my $filename = $schema->loader->get_dump_filename($class);
- my $code = decode('UTF-8', scalar slurp $filename);
+ my $code = slurp_file $filename;
like $code, qr/^=head1 NAME\n\n^$class - The\nTable\n\n^=cut\n/m,
'table comment';
use File::Path;
use make_dbictest_db_bad_comment_tables;
use dbixcsl_test_dir qw/$tdir/;
+use Try::Tiny;
my $dump_path = "$tdir/dump";
);
}
-DBICTest::Schema::1->connect($make_dbictest_db_bad_comment_tables::dsn);
+try {
+ DBICTest::Schema::1->connect($make_dbictest_db_bad_comment_tables::dsn);
+};
plan tests => 1;
-my $foo = slurp("$dump_path/DBICTest/Schema/1/Result/Foo.pm");
-my $bar = slurp("$dump_path/DBICTest/Schema/1/Result/Bar.pm");
+my $foo = try { slurp("$dump_path/DBICTest/Schema/1/Result/Foo.pm") };
+my $bar = try { slurp("$dump_path/DBICTest/Schema/1/Result/Bar.pm") };
-like($foo, qr/Result::Foo\n/, 'No error from no comment table');
+like($foo, qr/Result::Foo\n/, 'No error from invalid comment tables');
END { rmtree($dump_path, 1, 1); }
my $foo = slurp("$dump_path/DBICTest/Schema/1/Result/Foo.pm");
my $bar = slurp("$dump_path/DBICTest/Schema/1/Result/Bar.pm");
-like($foo, qr/Result::Foo\n/, 'No error from no comments');
+like($foo, qr/Result::Foo\n/, 'No error from lack of comment tables');
END { rmtree($dump_path, 1, 1); }