From a5599ce25905cdf69a059487bfb3a2a744a81d7c Mon Sep 17 00:00:00 2001 From: swaggboi Date: Fri, 19 Aug 2022 22:36:26 -0400 Subject: [PATCH] New migration for Replies --- PostText.pl | 5 +++-- README.md | 2 ++ lib/PostText/Model/Thread.pm | 2 +- migrations/4/down.sql | 1 + migrations/4/up.sql | 11 +++++++++++ 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 migrations/4/down.sql create mode 100644 migrations/4/up.sql diff --git a/PostText.pl b/PostText.pl index 98bd04e..d116c5e 100755 --- a/PostText.pl +++ b/PostText.pl @@ -91,10 +91,11 @@ any [qw{GET POST}], '/post', sub ($c) { # Configure things app->secrets(app->config->{'secrets'}) || die $@; -app->pg->migrations->from_dir('migrations')->migrate(3); +app->pg->migrations->from_dir('migrations')->migrate(4); if (my $threads_per_page = app->config->{'threads_per_page'}) { - app->thread->threads_per_page($threads_per_page) + say $threads_per_page; + app->thread->threads_per_page($threads_per_page); } app->asset->process('main.css', 'css/PostText.css'); diff --git a/README.md b/README.md index e4cbf68..21e703f 100644 --- a/README.md +++ b/README.md @@ -24,5 +24,7 @@ Run the tests locally (against development environment) ## TODOs +1. Default 'threads per page' is broken if config file isn't correct + (should pick up the default value wtf) 1. Pick a date format 1. Reply model diff --git a/lib/PostText/Model/Thread.pm b/lib/PostText/Model/Thread.pm index 85d5da0..5210862 100644 --- a/lib/PostText/Model/Thread.pm +++ b/lib/PostText/Model/Thread.pm @@ -59,7 +59,7 @@ sub get_threads_by_page($self, $this_page = 1) { } sub threads_per_page($self, $value = undef) { - $self->{'threads_per_page'} = $value // $self->{'threads_per_page'} + $self->{'threads_per_page'} = $value // $self->{'threads_per_page'}; } sub get_last_page($self) { diff --git a/migrations/4/down.sql b/migrations/4/down.sql new file mode 100644 index 0000000..9f2046e --- /dev/null +++ b/migrations/4/down.sql @@ -0,0 +1 @@ +DROP TABLE replies; diff --git a/migrations/4/up.sql b/migrations/4/up.sql new file mode 100644 index 0000000..561204b --- /dev/null +++ b/migrations/4/up.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS replies ( + reply_id SERIAL PRIMARY KEY, + thread_id INT, + reply_date TIMESTAMPTZ NOT NULL DEFAULT now(), + reply_author VARCHAR(64), + reply_body VARCHAR(4096), + hidden_status BOOLEAN NOT NULL, + flagged_status BOOLEAN NOT NULL, + FOREIGN KEY (thread_id) + REFERENCES threads(thread_id) +);