The board would not start against any existing database, so Caddy had
nothing to proxy to and answered 502. Reproduced by rebuilding the
server's database from the previous schema and starting the app the way
gunicorn does.
The cause is one line of schema.sql:
CREATE INDEX IF NOT EXISTS attachments_message ON attachments(message_id)
IF NOT EXISTS guards the index NAME, not the column. On a database whose
attachments table predates message_id, executescript dies with "no such
column" — before any migration could add it, because init_db runs the
schema first by design. Every index on a column a migration introduces
belongs in the migration, after the column exists. It now lives there,
outside the rebuild branch so a freshly created database gets it too.
Second bug, latent and worse: the rebuild set PRAGMA foreign_keys = OFF
inside the transaction, where it is documented to be a no-op. It looked
applied and did nothing. Moved outside BEGIN. The test fixture had been
passing for the wrong reason — it left foreign keys at SQLite's default,
which is off — and now turns them on as connect() does.
Both are the same mistake in different clothes: the tests exercised
migrations.apply directly, so nothing ever ran init_db against a
database from before the change. That test exists now. It builds the
previous schema, inserts the row the server actually has, starts the
app, and asserts the photo survived and a restart is a no-op. Verified
by reinstating the bad line and watching it fail with the same error the
server gave.
230 tests.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
An inbox between two members — conversations, per-person unread marks,
photos, blocking. Not live chat: that needs a connection held open per
signed-in member, which the sync workers cannot do.
Membership of the conversation is the whole access rule and is checked on
every hit, answering 404 rather than 403 so a member cannot tell a
conversation that is not theirs from one that does not exist. A picture
in a private message is checked the same way: on the board being signed
in is enough, here it is nowhere near.
Blocking is symmetric. One row stops both directions, and you can only
lift your own. A block that silenced only the blocked person would leave
the blocker writing freely, which is a megaphone rather than a safety
feature. Enforced in the handlers, with a test that posts from a page
held open from before the block.
Erasing a member deletes their private messages, both sides, and their
pictures off disk. A thread outlives its author because other people
replied; a two-party exchange has no remainder, and keeping half of
erased correspondence is what erasure exists to prevent. The guard added
in c9c549e did its job: it failed the moment the new tables landed and
named all four columns.
The part that needed care: schema.sql is all CREATE TABLE IF NOT EXISTS,
so it can add a table and nothing else. Every change so far happened to
be a new table. Letting an attachment belong to a message is not — and
SQLite cannot do it in place, because the table carries a CHECK
constraint and there is no DROP CONSTRAINT. Verified before building on
it: ALTER TABLE ADD COLUMN succeeds and the next insert is refused.
So migrations.py, numbered steps recorded in PRAGMA user_version, run
after the schema so a fresh database finds its work already done. Step 1
rebuilds attachments the documented way. Tested against a database built
in the old shape with rows in it, because a migration tested only on a
fresh database is tested against the one case it was never needed for —
including that the rebuilt CHECK is as strict as the one it replaced.
229 tests.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn