@@ -29,7 +29,6 @@ def ensure_schema!
2929 Rails . logger . debug "Auth schema already exists"
3030 @created = true
3131 else
32- # Re-raise if it's a different error (permissions, etc)
3332 Rails . logger . error "Failed to create auth schema: #{ e . message } "
3433 raise
3534 end
@@ -42,24 +41,32 @@ def ensure_schema!
4241
4342# Initialize on boot
4443Rails . application . config . after_initialize do
45- AuthSchemaInitializer . initialize!
44+ # Tthe `auth` schema is created and managed by itself —
45+ # running CREATE SCHEMA here generates a wasteful DDL call on every Puma
46+ # worker and Sidekiq process boot (228 DDL calls seen in Query Performance).
47+ # Only run when connecting to a local/non-Supabase Postgres instance.
48+ db_url = ENV . fetch ( 'SUPABASE_DB_URL' , ENV . fetch ( 'DATABASE_URL' , '' ) )
49+ if db_url . exclude? ( 'supabase' )
50+ AuthSchemaInitializer . initialize!
4651
47- # Run in thread to not block boot, but with retry logic
48- Thread . new do
49- retries = 0
50- max_retries = 3
52+ Thread . new do
53+ retries = 0
54+ max_retries = 3
5155
52- begin
53- sleep 0.5 # Small delay to let other processes/threads start
54- AuthSchemaInitializer . ensure_schema!
55- rescue => e
56- retries += 1
57- if retries < max_retries
58- sleep 1 * retries # Exponential backoff
59- retry
60- else
61- Rails . logger . error "Failed to ensure auth schema after #{ max_retries } attempts: #{ e . message } "
56+ begin
57+ sleep 0.5
58+ AuthSchemaInitializer . ensure_schema!
59+ rescue => e
60+ retries += 1
61+ if retries < max_retries
62+ sleep 1 * retries
63+ retry
64+ else
65+ Rails . logger . error "Failed to ensure auth schema after #{ max_retries } attempts: #{ e . message } "
66+ end
6267 end
63- end
64- end . tap { |t | t . abort_on_exception = false }
68+ end . tap { |t | t . abort_on_exception = false }
69+ else
70+ Rails . logger . debug 'AuthSchemaInitializer skipped — Supabase manages the auth schema'
71+ end
6572end
0 commit comments