From d7613d8b0480772a9838a0dcc0a35414d00b69af Mon Sep 17 00:00:00 2001 From: swag Date: Thu, 30 Dec 2021 21:39:16 -0500 Subject: [PATCH] Rename table --- guestbook-ng.pl | 2 +- lib/GuestbookNg/Model/Message.pm | 8 ++++---- migrations/4/down.sql | 1 + migrations/4/up.sql | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 migrations/4/down.sql create mode 100644 migrations/4/up.sql diff --git a/guestbook-ng.pl b/guestbook-ng.pl index 019268d..ed49c66 100755 --- a/guestbook-ng.pl +++ b/guestbook-ng.pl @@ -77,7 +77,7 @@ app->secrets(app->config->{'secrets'}) || die $@; app->message->max_posts(app->config->{'max_posts'}) if app->config->{'max_posts'}; -app->pg->migrations->from_dir('migrations')->migrate(3); +app->pg->migrations->from_dir('migrations')->migrate(4); app->asset->store->paths(['assets']); app->asset->process('swagg.css', 'css/swagg.css'); diff --git a/lib/GuestbookNg/Model/Message.pm b/lib/GuestbookNg/Model/Message.pm index 1cca925..35a489b 100644 --- a/lib/GuestbookNg/Model/Message.pm +++ b/lib/GuestbookNg/Model/Message.pm @@ -22,7 +22,7 @@ sub get_posts($self, $this_page = undef) { SELECT to_char(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'), visitor_name, message - FROM messages + FROM guestbook ORDER BY message_date DESC LIMIT ? OFFSET ?; END_SQL @@ -32,7 +32,7 @@ sub get_posts($self, $this_page = undef) { SELECT to_char(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'), visitor_name, message - FROM messages + FROM guestbook ORDER BY message_date DESC; END_SQL } @@ -40,7 +40,7 @@ sub get_posts($self, $this_page = undef) { sub create_post($self, $name, $message) { $self->pg->db->query(<<~'END_SQL', $name, $message) - INSERT INTO messages (message_date, visitor_name, message) + INSERT INTO guestbook (message_date, visitor_name, message) VALUES (NOW(), ?, ?); END_SQL } @@ -58,7 +58,7 @@ sub get_last_page($self) { } sub get_post_count($self) { - $self->pg->db->query('SELECT count(*) FROM messages;')->text() + $self->pg->db->query('SELECT count(*) FROM guestbook;')->text() } 1; diff --git a/migrations/4/down.sql b/migrations/4/down.sql new file mode 100644 index 0000000..5cf0c5c --- /dev/null +++ b/migrations/4/down.sql @@ -0,0 +1 @@ +ALTER TABLE guestbook RENAME TO messages; diff --git a/migrations/4/up.sql b/migrations/4/up.sql new file mode 100644 index 0000000..0197a5e --- /dev/null +++ b/migrations/4/up.sql @@ -0,0 +1 @@ +ALTER TABLE messages RENAME TO guestbook;