Set default value for message_date column

This commit is contained in:
swagg boi 2022-01-02 02:30:10 -05:00
parent baca0cd515
commit da91154df7
5 changed files with 11 additions and 12 deletions

View file

@ -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

View file

@ -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');

View file

@ -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
}

3
migrations/6/down.sql Normal file
View file

@ -0,0 +1,3 @@
ALTER TABLE messages
ALTER COLUMN message_date
DROP DEFAULT;

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

@ -0,0 +1,3 @@
ALTER TABLE messages
ALTER COLUMN message_date
SET DEFAULT NOW();