issue: track messages in database
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 20 Oct 2019 03:47:19 +0000 (05:47 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 9 Nov 2019 06:08:13 +0000 (07:08 +0100)
commit7f191935501429b51d0b220ba32eda8b3a747655
tree019072d97f8a143714d49969a3a48f5019cce161
parentd33a85fd3d187d76fd86f891bba2d9fe17a035a0
issue: track messages in database

Replace file storage by PostgreSQL table, similar to comments in commit
v4.0-21-g0cc6251412 (2019-10-27) [nieuws/replies: read contents from database].

Existing files are imported similar to earlier comments:

ls melding/2*/*.html | perl -MFile::Slurp -lnE ' #/
my ($page, $date, $name) = split m{/};
$name =~ s/(\d+-\d+)-// and $date .= "-$1";
my $closed = qx(stat -c%y "$page/.tags/opgelost/$date-$name" 2>/dev/null);
chomp $closed;
$name =~ s/\.html$//;
my $html = read_file($_);
$html =~ s{<h2>(.*?)</h2>\n+}{}; my $title = $1;
chomp, s/\\\K/\\/g, s/\n/\\n/g, s/\t/\\t/g for $html;
say join "\t", $page, $date, $name, $title, $html, $closed || "\\N";
' | psql lijtweg -c 'COPY issues (page, created, link, subject, body, closed) FROM STDIN'

Afterwards, the following queries can be executed to convert and clean up
these imported rows further:

-- rename issue references to new page ids
UPDATE comments c SET page = (SELECT coalesce((SELECT page||'/'||id
FROM issues WHERE c.page LIKE page || '/%-' || link), c.page));

-- move authorship contents to dedicated column
SELECT id, regexp_matches(body, '<p class="right">(?:Ingediend door |<em>)?([^<]*)')
FROM issues WHERE body ~ 'right';
UPDATE issues SET author = 'cees' WHERE body ~ '<p class="right">.*Cees';
UPDATE issues SET author = '301' WHERE body ~ '<p class="right">.*de Roos';
UPDATE issues SET body = regexp_replace(body, E'\n+<p class="right">.*</p>$', '')
WHERE body ~ 'right';
issue/index.html [new file with mode: 0644]
issue/index.php [new file with mode: 0644]
widget/comments.sql
widget/reply.php