minor changes to table/column comment code
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DBI / mysql.pm
index cb83e7a..50925aa 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 use base 'DBIx::Class::Schema::Loader::DBI';
 use mro 'c3';
 use List::Util 'first';
+use Try::Tiny;
 use namespace::clean;
 
 our $VERSION = '0.07010';
@@ -241,6 +242,47 @@ sub _dbh_column_info {
     $self->next::method(@_);
 }
 
+sub _table_comment {
+    my ( $self, $table ) = @_;
+    my $comment = $self->next::method($table);
+    if (not $comment) {
+        ($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.
+        }
+        elsif ($comment =~ /^InnoDB free:/) {
+            $comment = undef;
+        }
+        else {
+            $comment =~ s/; InnoDB.*//;
+        }
+    }
+    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) = 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;
+}
+
 =head1 SEE ALSO
 
 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,