diff --git a/README.md b/README.md index 1179bdf..d6a674d 100644 --- a/README.md +++ b/README.md @@ -50,4 +50,3 @@ Add the `-v` option for more verbose output ## TODOs 1. Input validation -1. Set date in the DB rather than the model diff --git a/guestbook-ng.pl b/guestbook-ng.pl index 0373853..6abafb0 100755 --- a/guestbook-ng.pl +++ b/guestbook-ng.pl @@ -111,7 +111,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(5); +app->pg->migrations->from_dir('migrations')->migrate(6); 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 84c6d3d..e5f70d1 100644 --- a/lib/GuestbookNg/Model/Message.pm +++ b/lib/GuestbookNg/Model/Message.pm @@ -46,20 +46,14 @@ sub get_posts($self, $this_page = undef) { sub create_post($self, $name, $message, $url = undef, $spam = 1) { if ($url) { $self->pg->db->query(<<~'END_SQL', $name, $message, $url, $spam) - INSERT INTO messages ( - message_date, - visitor_name, - message, - homepage_url, - is_spam - ) - VALUES (NOW(), ?, ?, ?, ?); + INSERT INTO messages (visitor_name, message, homepage_url, is_spam) + VALUES (?, ?, ?, ?); END_SQL } else { $self->pg->db->query(<<~'END_SQL', $name, $message, $spam) - INSERT INTO messages (message_date, visitor_name, message, is_spam) - VALUES (NOW(), ?, ?, ?); + INSERT INTO messages (visitor_name, message, is_spam) + VALUES (?, ?, ?); END_SQL } diff --git a/migrations/6/down.sql b/migrations/6/down.sql new file mode 100644 index 0000000..5430d0c --- /dev/null +++ b/migrations/6/down.sql @@ -0,0 +1,3 @@ +ALTER TABLE messages +ALTER COLUMN message_date + DROP DEFAULT; diff --git a/migrations/6/up.sql b/migrations/6/up.sql new file mode 100644 index 0000000..9a785d4 --- /dev/null +++ b/migrations/6/up.sql @@ -0,0 +1,3 @@ +ALTER TABLE messages +ALTER COLUMN message_date + SET DEFAULT NOW();