-
-
Save jberger/5d4cac7b03ce41d7eac0ee29559494a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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