Skip to content

Instantly share code, notes, and snippets.

/dbdpg.diff Secret

Created February 13, 2016 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/847d0fdc118553c46730 to your computer and use it in GitHub Desktop.
Save anonymous/847d0fdc118553c46730 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Pg/Database.pm b/lib/Mojo/Pg/Database.pm
index 3f0f484..fe63cb3 100644
--- a/lib/Mojo/Pg/Database.pm
+++ b/lib/Mojo/Pg/Database.pm
@@ -89,10 +89,8 @@ sub query {
}
sub tables {
- shift->query(
- "select schemaname || '.' || tablename from pg_catalog.pg_tables
- where schemaname not in ('pg_catalog', 'information_schema')"
- )->arrays->map(sub { $_->[0] })->to_array;
+ [grep { $_ !~ /^(?:pg_catalog|information_schema)\./ }
+ shift->dbh->tables('', '', '', '', {})];
}
sub unlisten {
@@ -303,8 +301,8 @@ also append a callback to perform operation non-blocking.
my $tables = $db->tables;
-Return table names (that are not internal) for this database as an array
-reference.
+Return table and view names for this database, that are visible to the current
+user and not internal, as an array reference.
# Names of all tables
say for @{$db->tables};
diff --git a/t/migrations.t b/t/migrations.t
index 3a03fd8..3a12f43 100644
--- a/t/migrations.t
+++ b/t/migrations.t
@@ -69,6 +69,10 @@ EOF
is $pg->migrations->latest, 10, 'latest version is 10';
is $pg->migrations->active, 0, 'active version is 0';
is $pg->migrations->migrate->active, 10, 'active version is 10';
+ok !!(grep {/^mojo_migrations_test\.migration_test_one$/} @{$pg->db->tables}),
+ 'first table exists';
+ok !!(grep {/^mojo_migrations_test\.migration_test_two$/} @{$pg->db->tables}),
+ 'second table exists';
is_deeply $pg->db->query('select * from migration_test_one')->hash,
{foo => 'works ♥'}, 'right structure';
is $pg->migrations->migrate->active, 10, 'active version is 10';
diff --git a/t/results.t b/t/results.t
index c932b04..eae3a2f 100644
--- a/t/results.t
+++ b/t/results.t
@@ -28,6 +28,8 @@ ok !!(grep {/^mojo_results_test\.results.test$/} @{$db->tables}),
'results table exists';
ok !(grep {/^information_schema\.tables$/} @{$db->tables}),
'internal tables are hidden';
+ok !(grep {/^pg_catalog\.pg_tables$/} @{$db->tables}),
+ 'internal tables are hidden';
# Result methods
is_deeply $db->query('select * from results_test')->rows, 2, 'two rows';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment