aboutsummaryrefslogtreecommitdiffstats
path: root/internal/db/migrations
diff options
context:
space:
mode:
authorgrm <grm@eyesin.space>2026-09-15 23:12:51 +0300
committergrm <grm@eyesin.space>2026-09-15 23:12:51 +0300
commit2c85ca1a46ddf4652f8fffc53d6bcfbe32b2b4ff (patch)
treeecd5efd574b7d7463e4b2c4361c1994c4f28f561 /internal/db/migrations
parent55732bdfc25933bab26220ccd82fe5e172d9e673 (diff)
downloadblogspace-2c85ca1a46ddf4652f8fffc53d6bcfbe32b2b4ff.tar.gz
blogspace-2c85ca1a46ddf4652f8fffc53d6bcfbe32b2b4ff.tar.bz2
blogspace-2c85ca1a46ddf4652f8fffc53d6bcfbe32b2b4ff.zip
Add post tags, with a tag page and two side-column modules
Posts can now carry tags, set on the post form as a checklist of the blog's existing tags plus a comma-separated box for new ones (no JS). A tag is a name and a unique slug, so "Go" and "go" are one tag and Greek tags get readable URLs; tags no post uses any more are deleted. On the blog, tags appear under the post date and link to /tag/<slug>, which lists the published posts from every page, paginated like a page. Two new layout modules show them: a Tags list (with counts, by use) and a Tag cloud (alphabetical, sized by use). Both are only fetched when a visible module needs them. The article loop and pager move to a shared postlist partial; while there, the pager stops adding a trailing slash — /news/?p=2 was a 404 because a {page} wildcard never matches one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A
Diffstat (limited to 'internal/db/migrations')
-rw-r--r--internal/db/migrations/blog/00004_tags.sql26
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/db/migrations/blog/00004_tags.sql b/internal/db/migrations/blog/00004_tags.sql
new file mode 100644
index 0000000..a2ac86a
--- /dev/null
+++ b/internal/db/migrations/blog/00004_tags.sql
@@ -0,0 +1,26 @@
+-- +goose Up
+-- Tags are shared by posts. The slug is both the URL (/tag/<slug>) and the
+-- dedupe key, so "Go" and "go" are one tag (the first spelling is kept).
+CREATE TABLE tags (
+ id bigserial PRIMARY KEY,
+ name text NOT NULL,
+ slug text NOT NULL UNIQUE
+);
+CREATE TABLE post_tags (
+ post_id bigint NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
+ tag_id bigint NOT NULL REFERENCES tags(id) ON DELETE CASCADE,
+ PRIMARY KEY (post_id, tag_id)
+);
+CREATE INDEX post_tags_tag ON post_tags (tag_id);
+
+-- Two more layout modules: the tag list and the tag cloud.
+ALTER TABLE modules DROP CONSTRAINT modules_kind_check;
+ALTER TABLE modules ADD CONSTRAINT modules_kind_check
+ CHECK (kind IN ('title', 'logo', 'menu', 'archive', 'recent', 'html', 'rss', 'text', 'sitemap', 'tags', 'tagcloud'));
+
+-- +goose Down
+DELETE FROM modules WHERE kind IN ('tags', 'tagcloud');
+ALTER TABLE modules DROP CONSTRAINT modules_kind_check;
+ALTER TABLE modules ADD CONSTRAINT modules_kind_check
+ CHECK (kind IN ('title', 'logo', 'menu', 'archive', 'recent', 'html', 'rss', 'text', 'sitemap'));
+DROP TABLE post_tags, tags;