The v1.6.0 work (webmentions, reply contexts, rate limiter, migration 010) was built and deployed as git.thesatelliteoflove.com/phil/starpunk:v1.6.0-rc.2 but never committed. This restores the application code from /app in the running container so later work builds on what production runs. Tests and docs for v1.6.0 were not in the image and are not recovered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
80 lines
3.0 KiB
SQL
80 lines
3.0 KiB
SQL
-- Migration 010: Add Webmention support
|
|
-- Version: 1.6.0
|
|
-- Per ADR-063: Webmention Implementation
|
|
-- Per W3C Webmention Recommendation
|
|
|
|
-- Add reply-to support to notes table
|
|
ALTER TABLE notes ADD COLUMN in_reply_to TEXT;
|
|
|
|
-- Incoming webmentions storage
|
|
CREATE TABLE IF NOT EXISTS webmentions (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
source_url TEXT NOT NULL,
|
|
target_url TEXT NOT NULL,
|
|
target_note_id INTEGER,
|
|
mention_type TEXT NOT NULL DEFAULT 'mention'
|
|
CHECK (mention_type IN ('reply', 'like', 'repost', 'bookmark', 'mention')),
|
|
author_name TEXT,
|
|
author_url TEXT,
|
|
author_photo TEXT,
|
|
content_snippet TEXT,
|
|
validation_status TEXT NOT NULL DEFAULT 'pending'
|
|
CHECK (validation_status IN ('pending', 'valid', 'invalid', 'error')),
|
|
moderation_status TEXT NOT NULL DEFAULT 'pending'
|
|
CHECK (moderation_status IN ('pending', 'approved', 'hidden', 'deleted')),
|
|
validation_error TEXT,
|
|
validated_at TIMESTAMP,
|
|
received_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (target_note_id) REFERENCES notes(id) ON DELETE SET NULL,
|
|
UNIQUE(source_url, target_url)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_webmentions_target_note ON webmentions(target_note_id);
|
|
CREATE INDEX IF NOT EXISTS idx_webmentions_moderation ON webmentions(moderation_status);
|
|
CREATE INDEX IF NOT EXISTS idx_webmentions_validation ON webmentions(validation_status);
|
|
CREATE INDEX IF NOT EXISTS idx_webmentions_received ON webmentions(received_at DESC);
|
|
|
|
-- Outgoing webmention queue
|
|
CREATE TABLE IF NOT EXISTS webmention_queue (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
source_url TEXT NOT NULL,
|
|
target_url TEXT NOT NULL,
|
|
source_note_id INTEGER,
|
|
endpoint_url TEXT,
|
|
status TEXT NOT NULL DEFAULT 'pending'
|
|
CHECK (status IN ('pending', 'sending', 'sent', 'failed', 'no_endpoint')),
|
|
retry_count INTEGER NOT NULL DEFAULT 0,
|
|
next_retry_at TIMESTAMP,
|
|
last_error TEXT,
|
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
started_at TIMESTAMP,
|
|
sent_at TIMESTAMP,
|
|
FOREIGN KEY (source_note_id) REFERENCES notes(id) ON DELETE CASCADE,
|
|
UNIQUE(source_url, target_url)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_webmention_queue_status ON webmention_queue(status);
|
|
CREATE INDEX IF NOT EXISTS idx_webmention_queue_retry ON webmention_queue(next_retry_at);
|
|
CREATE INDEX IF NOT EXISTS idx_webmention_queue_note ON webmention_queue(source_note_id);
|
|
|
|
-- Cached reply contexts
|
|
CREATE TABLE IF NOT EXISTS reply_contexts (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
url TEXT UNIQUE NOT NULL,
|
|
title TEXT,
|
|
content_snippet TEXT,
|
|
published_at TIMESTAMP,
|
|
author_name TEXT,
|
|
author_url TEXT,
|
|
author_photo TEXT,
|
|
site_name TEXT,
|
|
fetch_status TEXT NOT NULL DEFAULT 'pending'
|
|
CHECK (fetch_status IN ('pending', 'fetched', 'error')),
|
|
fetch_error TEXT,
|
|
fetched_at TIMESTAMP,
|
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_reply_contexts_url ON reply_contexts(url);
|