Implemented migrations dir

This commit is contained in:
swagg boi 2021-12-04 22:33:53 -05:00
parent 807bdd155c
commit c6082e095b
4 changed files with 11 additions and 12 deletions

View file

@ -18,7 +18,9 @@ helper pg => sub {
app->config->{'pg_user'} .
':' .
app->config->{'pg_pw'} .
'@localhost/' .
'@' .
app->config->{'pg_host'} .
'/' .
app->config->{'pg_db'}
);
};

View file

@ -15,17 +15,7 @@ sub test_model($self, $string) {
}
sub create_table($self) {
$self->pg->migrations->from_string(
"-- 1 up
CREATE TABLE IF NOT EXISTS messages (
id int,
date timestamp with time zone,
name varchar(255),
msg varchar(255)
);
-- 1 down
DROP TABLE messages;"
)->migrate();
$self->pg->migrations->from_dir('migrations')->migrate(1);
}
sub now($self) {

1
migrations/1/down.sql Normal file
View file

@ -0,0 +1 @@
DROP TABLE messages;

6
migrations/1/up.sql Normal file
View file

@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS messages (
id SERIAL PRIMARY KEY,
date TIMESTAMPTZ,
name VARCHAR(64),
msg VARCHAR(255)
);