Skip to content

Instantly share code, notes, and snippets.

@jberger

jberger/test.pl Secret

Created June 14, 2016 18:06
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 jberger/5d4cac7b03ce41d7eac0ee29559494a9 to your computer and use it in GitHub Desktop.
Save jberger/5d4cac7b03ce41d7eac0ee29559494a9 to your computer and use it in GitHub Desktop.
use Mojo::Base -strict;
use Mojo::Pg;
use Test::More;
# NB each run of this test has to be on a fresh database
my $url = 'postgresql://...';
my $pg = Mojo::Pg->new($url)->auto_migrate(0);
$pg->db->query('drop schema if exists my_test cascade');
$pg->db->query('create schema my_test');
# uncomment the following line for the test to pass
#$pg = Mojo::Pg->new($url)->auto_migrate(0);
$pg->search_path(['my_test']);
$pg->migrations->from_data->migrate(0)->migrate;
my $count = eval { $pg->db->query('select count(*) from my_test.my_table')->array->[0] };
is $count, 1, 'correct number of items';
$count = undef;
$count = eval { $pg->db->query('select count(*) from public.my_table')->array->[0] };
ok ! defined($count), 'items not in public schema';
done_testing;
__DATA__
@@ migrations
-- 1 up
CREATE TABLE my_table (id BIGSERIAL PRIMARY KEY);
INSERT INTO my_table DEFAULT VALUES;
-- 1 down
DROP TABLE IF EXISTS my_first_table;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment