Skip to content

Restore the auth.users trigger and storage policies lost in the dev2 move - #327

Merged
ralyodio merged 1 commit into
masterfrom
fix/restore-dev2-lost-auth-storage
Sep 26, 2026
Merged

ralyodio merged 1 commit into
masterfrom
fix/restore-dev2-lost-auth-storage

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

Cause

On 2026-09-25 the database moved from Supabase cloud to the self-hosted stack on dev2. Objects that live on auth.* and storage.* tables did not come across: the on_auth_user_created trigger ON auth.users and both RLS policies ON storage.objects. The public functions they call and the buckets (data) survived. Without the trigger, a signup gets no public.profiles row, so everything keyed on profiles (projects, audits, credit_purchases, organizations) fails its foreign key for that user. Without the policies, owners cannot read their audit artifacts / PDF reports through RLS and sp-images is not readable through the API. The cloud project is deleted, so the migrations are the only source of truth.

What this restores

supabase/migrations/20260926210000_restore_auth_storage_lost_in_dev2_move.sql, idempotent (DROP ... IF EXISTS then CREATE), final state after replaying every migration in order:

  • trigger on_auth_user_created AFTER INSERT ON auth.users → public.handle_new_user() (from 0001_init.sql; function last redefined in 0005_credits.sql, which still exists in public)
  • storage.objects policy "artifact owner read" (0002_storage.sql)
  • storage.objects policy "sp-images public read" (20260528210000_sp_project_social_config.sql)

Backfill

public.profiles for every auth.users row without one, mirroring the handle_new_user() INSERT exactly: (id, email, display_name, credits_balance) with display_name = coalesce(full_name, email) and the function's literal credits_balance = 3. ON CONFLICT (id) DO NOTHING; profiles has no other unique column, so no collision handling is needed. The function sends no email and calls no webhook.

Note: the function hardcodes 3 credits while the column default has been 20 since 20260608010000_signup_grant_20_credits.sql, so real signups have been getting 3 as well. This PR keeps that behaviour rather than changing it silently; worth a separate fix.

Not yet applied to dev2; will be dry-run and applied from the operator session.

🤖 Generated with Claude Code

…move

The 2026-09-25 move to the self-hosted stack on dev2 dumped DDL for the
app schemas only, so on_auth_user_created and both storage.objects
policies were dropped. This re-creates them idempotently and backfills
profiles for users who signed up while the trigger was missing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

ThreatCrush Security Scan

49 finding(s)

HIGH/CRITICAL: 2 | MEDIUM: 32 | LOW: 15

Severity Rule Location
HIGH tls-verification-disabled lib/onion.ts:48
HIGH secret-generic-credential lib/sp/platforms/facebook.ts:32
MEDIUM js-unescaped-html-sink app/(app)/dashboard/admin/email-broadcast/EmailBroadcastForm.tsx:125
MEDIUM js-unescaped-html-sink app/(app)/dashboard/projects/[id]/autoblog/articles/[articleId]/page.tsx:214
MEDIUM js-unescaped-html-sink app/(marketing)/blog/[slug]/page.tsx:67
MEDIUM js-unescaped-html-sink app/(marketing)/blog/[slug]/page.tsx:97
MEDIUM js-unescaped-html-sink app/(marketing)/blog/[slug]/page.tsx:104
MEDIUM js-unescaped-html-sink app/(marketing)/blog/[slug]/page.tsx:110
MEDIUM js-unescaped-html-sink app/(marketing)/recent/page.tsx:186
MEDIUM js-unescaped-html-sink app/(marketing)/recent/page.tsx:190
MEDIUM js-unescaped-html-sink app/c/[project]/[slug]/page.tsx:77
MEDIUM js-unescaped-html-sink app/c/[project]/page.tsx:57
MEDIUM js-unescaped-html-sink app/careers.js/route.ts:228
MEDIUM js-unescaped-html-sink app/careers.js/route.ts:285
MEDIUM js-unescaped-html-sink app/layout.tsx:129
MEDIUM js-open-redirect app/login/form.tsx:39
MEDIUM js-unescaped-html-sink app/r/[token]/page.tsx:176
MEDIUM js-open-redirect app/signup/form.tsx:43
MEDIUM js-open-redirect components/billing/buy-credits-modal.tsx:98
MEDIUM js-unescaped-html-sink components/json-ld.tsx:8
MEDIUM js-unescaped-html-sink components/report/markdown-view.tsx:15
MEDIUM js-unescaped-html-sink lib/careers/page-templates.ts:198
MEDIUM js-dynamic-code-execution lib/crawl-limits.ts:67
MEDIUM redos-nested-quantifier lib/emailMarkdown.ts:41
MEDIUM redos-nested-quantifier lib/emailMarkdown.ts:324
MEDIUM redos-nested-quantifier lib/lx/articleGen.ts:99
MEDIUM redos-nested-quantifier lib/tracker/agent-gate.ts:61
MEDIUM sh-predictable-temp-path ops/selfhost/server/setup-supabase.sh:201
MEDIUM sh-remote-script-execution prober/deploy/provision.sh:30
MEDIUM sql-template-interpolation scripts/detect-slot-themes.ts:31
MEDIUM sql-template-interpolation scripts/purge-constructed-keywords.ts:163
MEDIUM sql-template-interpolation scripts/purge-offniche-keywords.ts:124
MEDIUM js-dynamic-code-execution scripts/test-crawl-limits.mjs:14
MEDIUM js-dynamic-code-execution scripts/test-crawl-limits.mjs:24
LOW secret-generic-credential app/(marketing)/docs/autoblog-webhook/page.tsx:145
LOW secret-generic-credential lib/sp/platforms/linkedin.ts:25
LOW js-dynamic-code-execution tests/careers-page-templates.test.ts:21
LOW js-dynamic-code-execution tests/careers-widget-script.test.ts:19
LOW js-dynamic-code-execution tests/careers-widget-script.test.ts:69
LOW js-dynamic-code-execution tests/contract/ad-visitor-id.test.ts:51
LOW js-dynamic-code-execution tests/contract/ad-visitor-id.test.ts:52
LOW js-dynamic-code-execution tests/contract/ads-click-cooldown-redis.test.ts:20
LOW js-dynamic-code-execution tests/contract/ads-click-cooldown-redis.test.ts:24
LOW js-dynamic-code-execution tests/contract/ads-click-cooldown-redis.test.ts:25
LOW js-dynamic-code-execution tests/contract/ads-click-cooldown-redis.test.ts:26
LOW js-dynamic-code-execution tests/contract/ads-click-cooldown-redis.test.ts:31
LOW js-dynamic-code-execution tests/contract/ads-click-cooldown-redis.test.ts:35
LOW secret-generic-credential tests/contract/posthog-integration.test.ts:13
LOW secret-generic-credential tests/lead-campaign.test.ts:16

Snippets are redacted; ThreatCrush never prints matched credential material.

@ralyodio
ralyodio merged commit 9d3917c into master Sep 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant