File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ What this does:
3434- A PR branch that changes ` supabase/** ` gets its own Supabase preview branch.
3535- That preview branch runs migrations and bucket config from Git.
3636- Seed data comes from ` supabase/seed.sql ` , not from production data.
37- - Local demo bucket objects come from ` supabase/storage/ ` , not from production storage .
37+ - Demo media is tracked under ` supabase/storage/ ` , but is uploaded only into local Supabase with ` npm run seed:local-media ` .
3838
3939### 2. Require the Supabase PR Check in GitHub
4040
Original file line number Diff line number Diff line change @@ -99,27 +99,39 @@ function normalizeFileSizeLimit(fileSizeLimit) {
9999}
100100
101101async function ensureBucket ( supabase , bucketName , bucketConfig ) {
102- const { error } = await supabase . storage . createBucket ( bucketName , {
102+ const normalizedConfig = {
103103 public : bucketConfig . public ,
104104 fileSizeLimit : normalizeFileSizeLimit ( bucketConfig . fileSizeLimit ) ,
105105 allowedMimeTypes : bucketConfig . allowedMimeTypes ,
106- } ) ;
106+ } ;
107+
108+ const { data : buckets , error : listError } = await supabase . storage . listBuckets ( ) ;
109+
110+ if ( listError ) {
111+ throw listError ;
112+ }
107113
108- if ( ! error ) return ;
114+ const existingBucket = buckets ?. find (
115+ ( bucket ) => bucket . id === bucketName || bucket . name === bucketName
116+ ) ;
109117
110- const message = error . message ?. toLowerCase ( ) ?? "" ;
111- const alreadyExists =
112- message . includes ( "already exists" ) || message . includes ( "duplicate" ) ;
118+ if ( ! existingBucket ) {
119+ const { error : createError } = await supabase . storage . createBucket (
120+ bucketName ,
121+ normalizedConfig
122+ ) ;
113123
114- if ( ! alreadyExists ) {
115- throw error ;
124+ if ( createError ) {
125+ throw createError ;
126+ }
127+
128+ return ;
116129 }
117130
118- const { error : updateError } = await supabase . storage . updateBucket ( bucketName , {
119- public : bucketConfig . public ,
120- fileSizeLimit : normalizeFileSizeLimit ( bucketConfig . fileSizeLimit ) ,
121- allowedMimeTypes : bucketConfig . allowedMimeTypes ,
122- } ) ;
131+ const { error : updateError } = await supabase . storage . updateBucket (
132+ bucketName ,
133+ normalizedConfig
134+ ) ;
123135
124136 if ( updateError ) {
125137 throw updateError ;
You can’t perform that action at this time.
0 commit comments