Skip to content

Commit 969a331

Browse files
committed
address review on local media seeding
1 parent 17955fd commit 969a331

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

docs/supabase-local-first.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

scripts/seed-local-media.mjs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,39 @@ function normalizeFileSizeLimit(fileSizeLimit) {
9999
}
100100

101101
async 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;

0 commit comments

Comments
 (0)