CI / extension-version (push) Successful in 3s
CI / lint (push) Successful in 3s
Build images / sign-extension (push) Successful in 4s
Build images / build-agent (push) Successful in 8s
CI / frontend-build (push) Successful in 23s
CI / backend-lint-and-test (push) Successful in 39s
Build images / build-web (push) Successful in 1m14s
Build images / smoke-web (push) Skipped
Build images / build-ml (push) Successful in 2m18s
Build images / promote (push) Skipped
CI / integration (push) Successful in 2m21s
FC knows which creators it was TOLD to follow and nothing about which ones the operator is subscribed to. Those two sets drift both ways and neither drift is currently visible: a subscription FC doesn't track is content the operator believes they're archiving and aren't, and a source walked after the subscription lapsed is requests spent on a wall reported as a creator gone quiet. Sibling of service_seen (milestone 365) and the same insight — an absence is only observable against a record of presence. touch_membership reuses the recorded touch_service shape (snippet 3447): upsert rather than read-modify-write, first_seen_at deliberately outside the update set because it's the one field that makes a later DISAPPEARANCE readable as a lapse rather than as a creator we never knew. Nothing populates it yet, and that's the intended intermediate state. The sweep (C3) needs a client seam (C2) that needs Patreon's real response characterised from a captured sample (C0), which needs the operator's browser session. The table's SHAPE doesn't wait on that, because it's deliberately free-form exactly where C0's findings would otherwise dictate a column. status is an unconstrained String holding the PLATFORM's own word, not a normalised FC value. Rule 36 considered and declined, same reasoning service_seen.kind records: the vocabulary isn't ours to invent, and picking a lowest-common-denominator enum before any platform has been characterised would bake a guess into the schema. The service owns the whitelist and the mapping; the column owns the evidence. MEMBERSHIP_STATUS ships EMPTY, guarded by a test that fails if anyone adds an entry — every one must come from a characterised response, not from API docs. That's rule 130 at the one place it's easiest to break, and the failure message says so. has_paid_access returns None, never False, for a word it hasn't been taught. The difference is load-bearing: False means the operator lost access, which C4 turns into an offer to disable the source, so asserting it from an unrecognised word would tell them to cancel a subscription they're still paying for. Retention decided here rather than deferred (rule 89): a membership that stops appearing is aged out on time, never deleted on absence — deleting would destroy the signal at the moment it became interesting. Rule 90 check, done on the right thing this time: the per-test TRUNCATE teardown derives its table list from Base.metadata.sorted_tables, so the new table is picked up automatically; test_models asserts a subset, so it doesn't break. 0091 follows 0090 on the collapsed baseline. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LNXXULQDjVZmbuNa2G9mD9
131 lines
6.2 KiB
Python
131 lines
6.2 KiB
Python
"""platform_membership — the learned roster of what the account actually pays for.
|
|
|
|
Milestone 387, phase C. FabledCurator knows which creators it has been TOLD to
|
|
follow (`source`), and nothing about which ones the operator is actually
|
|
subscribed to. Those two sets drift in both directions and the app cannot
|
|
currently see either drift:
|
|
|
|
* A subscription the operator pays for that FC does not track is content they
|
|
believe they are archiving and are not.
|
|
* A source FC keeps walking after the subscription lapsed is requests spent on
|
|
a wall, reported as a creator who has gone quiet.
|
|
|
|
This table is the memory that makes both visible — every membership the account
|
|
has been observed to hold, and when it was last seen.
|
|
|
|
## Why a learned roster rather than a live lookup
|
|
|
|
Same reasoning as `service_seen` (milestone 365), and the same shape: an
|
|
absence is only observable against a record of presence. A membership that
|
|
stops appearing in a sweep is the signal — "you were subscribed to this, now
|
|
you aren't" — and there is nowhere to read that from a live call, because a
|
|
live call returns what IS, never what stopped being.
|
|
|
|
It also means the reconciliation surface keeps working when Patreon is
|
|
unreachable, degraded to a stale roster with a visible age rather than an empty
|
|
page (rule 164).
|
|
|
|
## Roster truth, NOT per-post truth
|
|
|
|
The single most important thing about this table: `tier_names` says which tiers
|
|
the account holds. It does **not** say which posts those tiers unlock. A
|
|
creator can gate a post behind an access rule that maps onto no tier name at
|
|
all.
|
|
|
|
`current_user_can_view` — read per post by `patreon_client.post_is_gated` — is
|
|
the authoritative signal, and phase A already turned it into a durable
|
|
per-source state. This roster EXPLAINS that state ("you are no longer a patron"
|
|
vs "your tier doesn't cover these posts"). It must never be used to decide
|
|
whether to fetch something. Getting that backwards would make FC silently stop
|
|
fetching content the operator is paying for, which is the worst failure
|
|
available in this milestone.
|
|
|
|
## status is a plain String, and deliberately the platform's own word
|
|
|
|
Not a Postgres ENUM, not CHECK-gated — matching `service_seen.kind`,
|
|
`gpu_job.status` and `source.error_type`. Two reasons, and the first is the
|
|
real one:
|
|
|
|
1. **The vocabulary is not ours to invent.** Patreon says `active_patron` /
|
|
`former_patron` / `declined_patron`; SubscribeStar and FANBOX will say
|
|
something else. Storing each platform's own word verbatim and mapping to
|
|
FC's meaning at the READ site keeps this table a record of what was
|
|
observed rather than a lossy translation of it. A lowest-common-denominator
|
|
enum picked before any platform has been characterised (step C0) would be a
|
|
guess baked into the schema.
|
|
2. A constraint swap per new value (rule 36) would be cost with no invariant
|
|
behind it, exactly as `service_seen.kind` records.
|
|
|
|
The service layer owns the whitelist and the mapping; the column owns the
|
|
evidence.
|
|
|
|
## Retention: aged out, never deleted on disappearance
|
|
|
|
A membership that stops appearing in a sweep is NOT removed. Its disappearance
|
|
is the fact the reconciliation surface reads, and deleting the row would
|
|
destroy the signal at the moment it became interesting. `last_seen_at` is what
|
|
makes "gone" decidable, and a retention policy ages rows out on time rather
|
|
than on absence.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import JSON, DateTime, Integer, String, Text, UniqueConstraint, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from .base import Base
|
|
|
|
|
|
class PlatformMembership(Base):
|
|
__tablename__ = "platform_membership"
|
|
__table_args__ = (
|
|
# The natural key the sweep's upsert conflicts on. Named explicitly
|
|
# because `touch_membership` references it by name in ON CONFLICT.
|
|
UniqueConstraint(
|
|
"platform", "external_campaign_id",
|
|
name="uq_platform_membership_platform_campaign",
|
|
),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
|
|
platform: Mapped[str] = mapped_column(String(64), nullable=False)
|
|
# The platform's own id for the thing subscribed to — a Patreon campaign
|
|
# id, whatever SubscribeStar and FANBOX call theirs. Text rather than a
|
|
# bounded String: these are opaque upstream identifiers and guessing a
|
|
# ceiling for a value we do not mint is how a walk dies on a truncation.
|
|
external_campaign_id: Mapped[str] = mapped_column(Text, nullable=False)
|
|
|
|
# For the reconciliation UI, and for matching against Source.url — the
|
|
# vanity/URL is what the two sides actually have in common.
|
|
display_name: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
url: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
# The platform's own word. See the module docstring — this is evidence,
|
|
# not a normalised FC status.
|
|
status: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
|
|
|
# Nullable throughout: a free follow has no tier and no money attached, and
|
|
# a platform may not expose an amount at all. Absent must stay
|
|
# distinguishable from zero — "free" and "we don't know" are different
|
|
# answers to "what is this costing".
|
|
tier_names: Mapped[list | None] = mapped_column(JSON, nullable=True)
|
|
amount_cents: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
currency: Mapped[str | None] = mapped_column(String(8), nullable=True)
|
|
|
|
# NEVER updated after insert. The one field that answers "has this ever
|
|
# been true", which is what makes a disappearance readable rather than
|
|
# indistinguishable from never having existed. `touch_membership`
|
|
# deliberately excludes it from the ON CONFLICT update set.
|
|
first_seen_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), nullable=False, server_default=func.now(),
|
|
)
|
|
last_seen_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), nullable=False, server_default=func.now(),
|
|
)
|
|
|
|
# The raw membership as the platform returned it, so a later question can
|
|
# be answered without re-fetching — and so a field we did not think to
|
|
# model is not lost. Displayed and never queried, like service_seen.details.
|
|
details: Mapped[dict] = mapped_column(JSON, nullable=False, default=dict)
|