From c6082e095b0bf6fef3bce0276330ea70f746ac20 Mon Sep 17 00:00:00 2001 From: swag Date: Sat, 4 Dec 2021 22:33:53 -0500 Subject: [PATCH] Implemented migrations dir --- guestbook-ng.pl | 4 +++- lib/GuestbookNg/Model/Test.pm | 12 +----------- migrations/1/down.sql | 1 + migrations/1/up.sql | 6 ++++++ 4 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 migrations/1/down.sql create mode 100644 migrations/1/up.sql diff --git a/guestbook-ng.pl b/guestbook-ng.pl index c466a2b..bb3200f 100755 --- a/guestbook-ng.pl +++ b/guestbook-ng.pl @@ -18,7 +18,9 @@ helper pg => sub { app->config->{'pg_user'} . ':' . app->config->{'pg_pw'} . - '@localhost/' . + '@' . + app->config->{'pg_host'} . + '/' . app->config->{'pg_db'} ); }; diff --git a/lib/GuestbookNg/Model/Test.pm b/lib/GuestbookNg/Model/Test.pm index da8dc0b..10075b3 100644 --- a/lib/GuestbookNg/Model/Test.pm +++ b/lib/GuestbookNg/Model/Test.pm @@ -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) { diff --git a/migrations/1/down.sql b/migrations/1/down.sql new file mode 100644 index 0000000..f8f44a8 --- /dev/null +++ b/migrations/1/down.sql @@ -0,0 +1 @@ +DROP TABLE messages; diff --git a/migrations/1/up.sql b/migrations/1/up.sql new file mode 100644 index 0000000..6d4e7e3 --- /dev/null +++ b/migrations/1/up.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS messages ( + id SERIAL PRIMARY KEY, + date TIMESTAMPTZ, + name VARCHAR(64), + msg VARCHAR(255) +);