SQL style clean-up

This commit is contained in:
swagg boi 2021-12-19 19:09:16 -05:00
parent b7bb80cbe0
commit 07353e7d7e
4 changed files with 33 additions and 8 deletions

View file

@ -58,7 +58,7 @@ get '/' => sub ($c) {
} => 'index';
any [qw{GET POST}], '/sign' => sub ($c) {
if ($c->req->method() eq 'POST') {
if ($c->param('name') && $c->param('message')) {
my $name = $c->param('name');
my $message = $c->param('message');
my $answer = $c->param('answer');
@ -77,6 +77,6 @@ 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(2);
app->pg->migrations->from_dir('migrations')->migrate(3);
app->start();

View file

@ -15,16 +15,19 @@ sub new($class, $pg, $pg_object) {
sub get_posts($self) {
$self->pg->db
->query('SELECT to_char(date, \'Dy Mon DD HH:MI:SS AM TZ YYYY\'),
name, msg
->query('SELECT to_char(
message_date,
\'Dy Mon DD HH:MI:SS AM TZ YYYY\'
),
visitor_name, message
FROM messages
ORDER BY date DESC;')->arrays()
ORDER BY message_date DESC;')->arrays()
}
sub create_post($self, $name, $msg) {
sub create_post($self, $name, $message) {
$self->pg->db->query(
'INSERT INTO messages (date, name, msg)
VALUES (NOW(), ?, ?);', $name, $msg
'INSERT INTO messages (message_date, visitor_name, message)
VALUES (NOW(), ?, ?);', $name, $message
)
}

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

@ -0,0 +1,11 @@
ALTER TABLE messages
RENAME COLUMN message_id TO id;
ALTER TABLE messages
RENAME COLUMN message_date TO date;
ALTER TABLE messages
RENAME COLUMN visitor_name TO name;
ALTER TABLE messages
RENAME COLUMN message TO msg;

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

@ -0,0 +1,11 @@
ALTER TABLE messages
RENAME COLUMN id TO message_id;
ALTER TABLE messages
RENAME COLUMN date TO message_date;
ALTER TABLE messages
RENAME COLUMN name TO visitor_name;
ALTER TABLE messages
RENAME COLUMN msg TO message;