Do migration and add markdown_status to Models
This commit is contained in:
parent
2cbe24584b
commit
8c69bf31c0
@ -61,7 +61,7 @@ tests locally:
|
||||
|
||||
## TODOs
|
||||
|
||||
- Stop working on this and start the imageboard
|
||||
- Do I need `SUM` for `by_id()`?
|
||||
|
||||
## AGPL-3.0+ANTIFA compliance
|
||||
|
||||
|
@ -91,7 +91,7 @@ sub startup($self) {
|
||||
# Finish configuring some things
|
||||
$self->secrets($self->config->{'secrets'}) || die $@;
|
||||
|
||||
$self->pg->migrations->from_dir('migrations')->migrate(15);
|
||||
$self->pg->migrations->from_dir('migrations')->migrate(16);
|
||||
|
||||
if (my $threads_per_page = $self->config->{'threads_per_page'}) {
|
||||
$self->thread->per_page($threads_per_page)
|
||||
|
@ -18,7 +18,8 @@ sub by_page_for($self, $thread_id, $this_page = 1) {
|
||||
SELECT remark_id AS id,
|
||||
TO_CHAR(remark_date, ?) AS date,
|
||||
remark_author AS author,
|
||||
remark_body AS body
|
||||
remark_body AS body,
|
||||
markdown_status AS markdown
|
||||
FROM remarks
|
||||
WHERE thread_id = ?
|
||||
AND NOT hidden_status
|
||||
@ -27,7 +28,16 @@ sub by_page_for($self, $thread_id, $this_page = 1) {
|
||||
END_SQL
|
||||
}
|
||||
|
||||
sub create($self, $thread_id, $author, $body, $hidden = 0, $flagged = 0) {
|
||||
sub create(
|
||||
$self,
|
||||
$thread_id,
|
||||
$author,
|
||||
$body,
|
||||
$markdown = 0,
|
||||
$hidden = 0,
|
||||
$flagged = 0
|
||||
)
|
||||
{
|
||||
my $clean_body = $self->hr->process($body);
|
||||
my @data = ($thread_id, $author, $clean_body, $hidden, $flagged);
|
||||
|
||||
@ -37,9 +47,10 @@ sub create($self, $thread_id, $author, $body, $hidden = 0, $flagged = 0) {
|
||||
remark_author,
|
||||
remark_body,
|
||||
hidden_status,
|
||||
flagged_status
|
||||
flagged_status,
|
||||
markdown_status
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?);
|
||||
VALUES (?, ?, ?, ?, ?, ?);
|
||||
END_SQL
|
||||
}
|
||||
|
||||
@ -69,7 +80,8 @@ sub last_for($self, $thread_id) {
|
||||
SELECT remark_id AS id,
|
||||
TO_CHAR(remark_date, ?) AS date,
|
||||
remark_author AS author,
|
||||
remark_body AS body
|
||||
remark_body AS body,
|
||||
markdown_status AS markdown
|
||||
FROM remarks
|
||||
WHERE thread_id = ?
|
||||
ORDER BY remark_date
|
||||
@ -85,7 +97,8 @@ sub by_id($self, $remark_id) {
|
||||
TO_CHAR(remark_date, ?) AS date,
|
||||
remark_author AS author,
|
||||
remark_body AS body,
|
||||
thread_id
|
||||
thread_id,
|
||||
markdown_status AS markdown
|
||||
FROM remarks
|
||||
WHERE remark_id = ?
|
||||
AND NOT hidden_status;
|
||||
@ -122,7 +135,8 @@ sub feed($self) {
|
||||
$self->pg->db->query(<<~'END_SQL', $date_format)->hashes;
|
||||
SELECT remark_id AS id,
|
||||
TO_CHAR(remark_date, ?) AS date,
|
||||
remark_body AS body
|
||||
remark_body AS body,
|
||||
markdown_status AS markdown
|
||||
FROM remarks
|
||||
WHERE NOT hidden_status
|
||||
GROUP BY remark_id
|
||||
|
@ -8,9 +8,25 @@ has per_page => 5;
|
||||
|
||||
has date_format => 'Dy, FMDD Mon YYYY HH24:MI:SS TZHTZM';
|
||||
|
||||
sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
|
||||
sub create(
|
||||
$self,
|
||||
$author,
|
||||
$title,
|
||||
$body,
|
||||
$markdown = 0,
|
||||
$hidden = 0,
|
||||
$flagged = 0
|
||||
)
|
||||
{
|
||||
my $clean_body = $self->hr->process($body);
|
||||
my @data = ($author, $title, $clean_body, $hidden, $flagged);
|
||||
my @data = (
|
||||
$author,
|
||||
$title,
|
||||
$clean_body,
|
||||
$hidden,
|
||||
$flagged,
|
||||
$markdown
|
||||
);
|
||||
|
||||
$self->pg->db->query(<<~'END_SQL', @data)->hash->{'thread_id'};
|
||||
INSERT INTO threads (
|
||||
@ -18,9 +34,10 @@ sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
|
||||
thread_title,
|
||||
thread_body,
|
||||
hidden_status,
|
||||
flagged_status
|
||||
flagged_status,
|
||||
markdown_status
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
RETURNING thread_id;
|
||||
END_SQL
|
||||
# The indented heredoc got a little confused by this one...
|
||||
@ -43,7 +60,8 @@ sub by_page($self, $this_page = 1) {
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END) AS remark_tally,
|
||||
t.bump_tally AS bump_tally
|
||||
t.bump_tally AS bump_tally,
|
||||
t.markdown_status AS markdown
|
||||
FROM threads AS t
|
||||
LEFT JOIN remarks AS r
|
||||
ON t.thread_id = r.thread_id
|
||||
@ -87,7 +105,8 @@ sub by_id($self, $thread_id) {
|
||||
t.thread_title AS title,
|
||||
t.thread_body AS body,
|
||||
COUNT(r.*) AS remark_tally,
|
||||
t.bump_tally AS bump_tally
|
||||
t.bump_tally AS bump_tally,
|
||||
t.markdown_status AS markdown
|
||||
FROM threads AS t
|
||||
LEFT JOIN remarks AS r
|
||||
ON t.thread_id = r.thread_id
|
||||
@ -121,7 +140,8 @@ sub feed($self) {
|
||||
SELECT thread_id AS id,
|
||||
TO_CHAR(thread_date, ?) AS date,
|
||||
thread_title AS title,
|
||||
thread_body AS body
|
||||
thread_body AS body,
|
||||
markdown_status AS markdown
|
||||
FROM threads
|
||||
WHERE NOT hidden_status
|
||||
GROUP BY thread_id
|
||||
|
Loading…
x
Reference in New Issue
Block a user