diff options
Diffstat (limited to 'internal/db/migrations/blog')
| -rw-r--r-- | internal/db/migrations/blog/00004_tags.sql | 26 |
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; |
