fragJulia
Changelog

2026-11-21 — Live database brought up to the repo migrations; is_admin hole closed

The live Supabase project had none of the repo migrations applied. Applied April + November migrations (except the consent and voice-bucket files), fixed the broken 0404 seed file, and closed client writes to the weekly post counter. Verified as a signed-in non-admin user.

Live state before

Live project: oxixxrzdrryfztfxlady (eu-central-1). No repo file names it; identified by schema (it has cms_*, forum_*, profiles; the other projects in the Supabase org belong to other apps). Migration history held only 20260223222935 add_sharing_columns. Missing: every file in supabase/migrations/ and apps/web/scripts/004–006. Any signed-in user could set their own is_admin (profiles_update_own had no column restriction).

Applied to live (2026-11-21, in this order)

MigrationNote
apps/web/scripts/004_documents_pipeline_v2.sqlas in repo
apps/web/scripts/005_document_llm_rate_limit.sqlas in repo
apps/web/scripts/006_feature_flags_column.sqlas in repo; needed by the hardening trigger
20260402_monetization_schema.sqlas in repo
20260403_content_tables.sqlas in repo
20260407_community_post_limit_2.sqlas in repo
20261119_post_limit_webhook_events.sqlsame end state; drop trigger if exists + create trigger sent as create or replace trigger
20261119_profiles_rls_hardening.sqlsame end state; create or replace trigger, and alter policy for the three existing policies instead of drop + create
20261119_yoga_meets.sqlsame end state; drop policy if exists lines omitted (tables were new)
20261121_post_count_client_lockdown.sqlnew, see below

The drop-free variants were used because the Supabase connector asks for an interactive confirmation on DROP statements, which could not be answered from the session. Repo files are unchanged; replaying them on a fresh database gives the same result.

Not applied

  • 20261119_user_consents.sql — on hold by owner decision until the trigger requires consents and sets the timestamp server-side (#715).
  • 20260405_voice_feedback_bucket.sql — allows unauthenticated uploads ("test mode"); left out pending a decision.
  • 20260404_seed_content.sql — was invalid as written (see below). Fixed in this PR but not yet applied live. Until it is, Lexikon and Magazin serve the built-in fallback content (apps/web/lib/content.ts), which is the same text.

Repo changes

  • 20260404_seed_content.sql: all six Magazin sections JSON literals were invalid JSON — German opening quotes „ were closed with an ASCII ", which ends the JSON string. 70 closing quotes replaced with “ (U+201C). No other character changed; all six literals now parse.
  • New 20261121_post_count_client_lockdown.sql: the two client insert/update policies on community_post_counts (from 0402) are set to false and renamed post_counts_no_client_insert / post_counts_no_client_update, so users can no longer reset their own weekly counter. increment_post_count(uid) now refuses API callers (anon, authenticated) whose uid is not their own. The forum insert trigger is unaffected.

Verification (live, inside a rolled-back transaction, as role authenticated with a non-admin user's JWT claims)

  • Own profile update setting is_admin = true, subscription_tier = 'premium', feature_flags = {...}: row updated, those three columns unchanged (false, free, {}); pseudonym changed as expected.
  • Update of another user's profile: 0 rows. Re-keying own row to another id: blocked by RLS.
  • Forum post or comment with another author_id: blocked by RLS.
  • Free tier: posts 1 and 2 succeed, post 3 blocked; counter = 2.
  • Resetting or inserting own counter row: 0 rows / blocked. increment_post_count(<other user>): blocked.
  • Afterwards: no test rows left, profile unchanged.

Follow-ups

  • Apply the fixed 20260404_seed_content.sql to live.
  • increment_document_llm_call(p_user_id, p_day) (script 005) has the same pattern as increment_post_count: SECURITY DEFINER, callable with any user id. Not changed here.
  • profiles_select_public_pseudonym (using (true)) still exposes every profile column, including share_password_hash, to every caller (noted in the hardening migration).
  • admin_update_all_profiles lets a user update their own row as a second permissive policy; the trigger still pins the privileged columns.
  • Decide on 20260405_voice_feedback_bucket.sql and fix 20261119_user_consents.sql.

On this page