amber-backend/pb_migrations/1797000000_drop_nsfw_enabled.js

58 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

Drop the 18+ account flag, its rule clause and the web page's 18+ field Nothing read `users.nsfwEnabled` any more. `/api/amber/whoami` stopped returning it, `GET /api/update/manifest` always answers `clean`, and the `releases` read rule stopped mentioning it in migration 1793000000, when the nine 18+ rows (437 MB) were deleted. What was left was a per-account flag nobody writes and nobody reads, sitting on the family's accounts and showing up in every schema dump and access-rule review as if it still gated something. A flag that looks like a protection but protects nothing costs the next reader the work of proving it dead. One live reader did remain: pb_public/index.html showed a "Zdroj 18+" source field and wrote `adultAddonUrl` into the encrypted addon config for a flagged account, and picked a different child-profile label for one. Both are gone, so the page offers the same three sources to everyone. Migration 1797000000 drops the field, rewrites users.updateRule to `id = @request.auth.id` (the clause it loses guarded a field that no longer exists), and removes `adult` from releases.variant's allowed values. Checked before writing it: 15 release rows, every one `clean`; three accounts carried the flag (the owner's, one family member's, the retired test account); the separate 18+ app has no accounts and no PocketBase, so nothing outside Amber reads it. `variant` itself stays and stays required: every installed Amber compares it against its own build and refuses a mismatch SILENTLY, so dropping the field would strand those installs with no error to see. publish-release.sh now accepts only `clean`. The status dashboard stops listing `adult-stremio-addon` and `stripchat-proxy`. Both still run on the VPS; they are the owner's, not Amber's, and Amber never reached them. scripts/verify.py asserts the flag stays gone (field absent, no rule mentions it, updateRule own-record-only). Run against a local PocketBase built from origin/main it failed on exactly those three checks; with this migration applied, ALL CHECKS PASSED. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 18:32:02 +00:00
/// <reference path="../pb_data/types.d.ts" />
// Remove the last of the 18+ scaffolding: the `nsfwEnabled` flag on `users`, the
// rule clause that guarded it, and `adult` as a publishable release variant.
//
// WHY NOW: nothing reads the flag any more. `/api/amber/whoami` stopped
// returning it, `GET /api/update/manifest` always serves `clean`, the `releases`
// read rule stopped mentioning it in migration 1793000000 (the nine 18+ rows,
// 437 MB, were deleted then), and the web settings page stopped showing an 18+
// source field in this same change. What was left was a per-account flag nobody
// writes and nobody reads, sitting on the family's accounts and appearing in
// every schema dump, README table and access-rule review as if it still gated
// something. A flag that looks like a protection but protects nothing is worse
// than no flag: the next person to read the schema has to prove it is dead.
//
// `users.updateRule` loses `@request.body.nsfwEnabled:isset = false`. The clause
// was the structural guarantee that a signed-in person could not flip their own
// flag. With the field gone there is nothing to flip, and PocketBase rejects an
// unknown field on write anyway. `createRule` is already superuser-only (null,
// migration 1789000000), so it needs no change.
//
// `releases.variant` KEEPS EXISTING and keeps being required -- only `adult`
// leaves its allowed values. Every installed Amber compares the manifest's
// variant against its own and refuses a mismatch **silently**, so removing the
// field would strand every install with no error to see. Publishing stays
// exactly as it is, minus a choice nobody can make any more.
//
// The down migration restores all three, so an instance can be rolled back. It
// cannot restore the per-account VALUES of the flag: dropping a field drops its
// data. That is intended -- the owner asked for the 18+ leftovers to be gone,
// and the only account that had it set was a test account being retired with it.
migrate(
(app) => {
const users = app.findCollectionByNameOrId("users")
users.updateRule = "id = @request.auth.id"
users.fields.removeByName("nsfwEnabled")
app.save(users)
const releases = app.findCollectionByNameOrId("releases")
const variant = releases.fields.getByName("variant")
variant.values = ["clean"]
app.save(releases)
},
(app) => {
const users = app.findCollectionByNameOrId("users")
users.fields.add(new BoolField({ name: "nsfwEnabled" }))
users.updateRule =
"id = @request.auth.id && @request.body.nsfwEnabled:isset = false"
app.save(users)
const releases = app.findCollectionByNameOrId("releases")
const variant = releases.fields.getByName("variant")
variant.values = ["clean", "adult"]
app.save(releases)
},
)