Migration 000015 authenticates against Lemmy and blocks every migration behind it #150
Labels
No labels
bug
devops
duplicate
enhancement
good first issue
layout
next major release
next minor release
question
research
testing
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lvl0/fedi-feed-router#150
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
Production is broken on three fronts:
decided_at, which does not exist:UPDATE(
RouteArticle.php:107viaArticles.php:66)couldnt_find_community, because channel community idswere never resolved (#145)
Root cause
All three follow from the same thing: migrations have not run since v1.3.7.
migrate:statusshows nine pending,000015through000023. Everything isblocked behind the first one, which fails:
000015convertsplatform_channels.channel_idfrom a community slug toLemmy's numeric id. To do that it logs into the live instance and calls
getCommunityId()— once per channel.There are three channels, all on the same instance and account:
Lemmy rate-limits authentication, and three logins in immediate succession is
over the limit. Reproduced directly against production:
So the migration fails deterministically on the third channel. Credentials and
connectivity are both fine — a single login returns a valid JWT, and
curl https://belgae.social/api/v3/sitefrom inside the container returns 200.The actual problem
The rate limit is the trigger. The defect is that a schema migration performs
network calls against a third-party service at all.
Any outage, expired credential, rate limit, or DNS failure at deploy time then
blocks not just this migration but every migration behind it, indefinitely and
silently. That is what happened: eight unrelated schema changes have been stuck
for several releases because one of them wanted to talk to Lemmy.
Fix
Strip the authentication out of
000015entirely. The migration should changethe schema and nothing else:
channel_idto hold a numeric community idthe application has to represent
Wiping is deliberately chosen over resolving. A migration that cannot fail on a
network call cannot block a deploy. Unresolved channels are a visible,
repairable state; a stuck migration chain is neither.
channel_idcurrently ends upnullable(false)with a unique constraint on(platform_instance_id, channel_id). Nulls have to be permitted, and theconstraint reviewed accordingly.
Depends on
Wiping the ids leaves affected channels unable to publish until they are
repaired, so #145's repair action becomes required rather than optional. In
practice these two tickets ship together, or #145 ships first.
Without a repair path, the only recovery is deleting and recreating the channel,
which cascades away its routes, keywords, route articles and publications.
Principle to carry forward
No migration may depend on a remote service. Data that can only be obtained from
an external API belongs in a job or a user-triggered action, where failure is
visible and retryable, not in a migration where failure is silent and blocking.
Worth checking the other migrations for the same shape while this is open.
Acceptance criteria
000015performs no network calls and imports no API servicechannel_idvalues are nulled rather than resolvedmigrate --forcecompletes on production, applying all nine pendingmigrations
channel_idare visible as needing repair (#145)State of the database
Nothing is half-applied.
resolve()runs entirely before any DDL, which wasdeliberate, so each failed attempt left the schema untouched.
platform_channelsstill has its original columns.Related
follow-up
once per channel). That approach is superseded by this one and should be
closed or repurposed — it reduces the number of calls but keeps the migration
dependent on Lemmy being reachable.
Migration 000015 authenticates once per channel and trips Lemmy's rate limitto Migration 000015 authenticates against Lemmy and blocks every migration behind itVerified on production
Deployed with v1.4.1. All nine pending migrations applied as batch 5:
They ran automatically on container startup, so
migrate --forceafterwardsreported "Nothing to migrate".
route_articlesnow hasdecided_at, and the three channels holding slugs weredeleted along with their routes, as intended.
Channels and routes were recreated through the UI. A Dutch VRT article was then
approved and published to Lemmy successfully, with no duplicate — the full
fetch → approve → publish path works.
That covers the acceptance criteria: the migration performs no network calls,
unconvertible channels are deleted rather than resolved,
migratecompletes,and the login and approval 500s are gone.