-- Migration 012: Crossposting (POSSE) to syndication targets -- Version: 2.1.0 -- Per ADR-065: Direct syndication to GoToSocial / Mastodon-API servers -- -- One row per (note, target). The worker reconciles the remote post with the -- note: create, update, or delete as needed. note_id has no foreign key on -- purpose: a row must outlive a hard-deleted note so the remote post can be -- deleted too. CREATE TABLE IF NOT EXISTS syndications ( id INTEGER PRIMARY KEY AUTOINCREMENT, note_id INTEGER NOT NULL, target TEXT NOT NULL, enabled INTEGER NOT NULL DEFAULT 1, remote_id TEXT, remote_url TEXT, state TEXT NOT NULL DEFAULT 'pending' CHECK (state IN ('pending', 'synced', 'failed')), version INTEGER NOT NULL DEFAULT 1, attempts INTEGER NOT NULL DEFAULT 0, last_error TEXT, next_attempt_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, claimed_until TIMESTAMP, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE (note_id, target) ); CREATE INDEX IF NOT EXISTS idx_syndications_due ON syndications(state, next_attempt_at);