Repository navigation
Description
Existing issues
- I have searched the existing issues.
Affected area
Seeding
Problem to solve
supabase seed buckets, and the bucket seeding that supabase start and supabase db reset run, upload every file under objects_path with a content type and a cache control, and nothing else. There is no way to set user_metadata on a seeded object, so seeded rows in storage.objects have user_metadata = NULL.
The Storage API supports custom metadata on every upload path: the x-metadata header or the metadata form field on a standard upload, the metadata field on a TUS upload, and x-amz-meta-* on S3. Applications read it in views, triggers, and RLS policies. A project whose schema reads storage.objects.user_metadata cannot produce working seed data with objects_path.
This matters most on preview branches. A preview branch seeds itself from config.toml and the seed files, and it runs no custom script, so there is no step where a project can add the metadata itself. On a local stack a script after db reset can re-upload the files with metadata. On a preview branch nothing can.
Our case: a view marks an object as valid for some uses only when user_metadata holds a specifically structured JSON object. Seeded files fail that check, so the local app treats every seeded object as broken.
Where the gap is today:
uploadObjectsinapps/cli/src/command-internal/seed-buckets.tscallsgateway.uploadObjectwithcontentType,cacheControl, andoverwriteonly.[storage.buckets.<name>]acceptspublic,file_size_limit,allowed_mime_types, andobjects_path.supabase storage cphas--cache-controland--content-type, and no metadata flag.
Proposed solution
Let the config declare metadata for seeded objects, and send it as the x-metadata header (base64-encoded JSON) on the existing upload request.
A sidecar manifest next to the files would cover per-file values such as dimensions and duration. One JSON file maps a relative object path to its metadata:
[storage.buckets.assets]
objects_path = "./seed-assets"
objects_metadata_path = "./seed-assets.metadata.json"{
"videos/sample.mp4": { "width": 1280, "height": 720, "durationMs": 794527, "fps": 29.97 },
"videos/sample-thumbnail.jpg": { "width": 1280, "height": 720 }
}Expected behavior:
- JSON types survive. A number or a boolean in the manifest reaches
user_metadataas a number or a boolean, not a string. - The manifest applies to local seeding and to
seed buckets --linked. - The seed fails, and names the object path, when the manifest lists a file that does not exist under
objects_path. - A file with no manifest entry uploads as it does today.
Alternatives considered
- A
metadatakey on the[[storage.objects]]block proposed in https://github.com/orgs/supabase/discussions/12390 (comment from February 25, 2025). That block sets properties per key prefix, which suits values shared by every file under a prefix. It does not cover our case, because each file needs its own values. - A custom script after
db resetthat uploads withstorage-jsand{ metadata }. This works on a local stack only. A preview branch runs no custom script, and preview branches are one of the main reasons to seed storage at all. objects_pathplusUPDATE storage.objects SET user_metadata = .... Bucket seeding runs after the database seed files, so the statement cannot live in a seed file. It needs a separate step, which a preview branch does not run.INSERT INTO storage.objectsfrom a seed file. This creates rows with no file in the storage backend.
Additional context
- CLI version: 3.1.0
- Local storage-api version: v1.94.2
- feat: add user metadata support for RLS policies storage#825 passes
user_metadatato the RLS check on every upload path, so RLS policies can depend on it during upload. - Related discussion: https://github.com/orgs/supabase/discussions/12390
Activity
vaibhav375 commentedon Nov 17, 2026
I'd like to implement this. I read through the current code and the Storage API, and the sidecar manifest proposed above looks like a small change. Here's how I'd scope it. I'll wait for
open-for-contributionbefore opening a PR.Where it goes
packages/config/src/storage.ts: add an optionalobjects_metadata_pathstring tobucketSchema, defaulting to empty. A relative path resolves againstsupabase/, the same wayobjects_pathdoes.apps/cli/src/command-internal/seed-buckets.ts(uploadObjects): if the bucket has a manifest, read and validate it once per bucket, look up each file by its path relative toobjects_path, and pass the entry to the gateway.apps/cli/src/command-internal/storage-gateway.ts(uploadObject): add an optionalmetadatafield toUploadObjectOptions. When it's set, sendx-metadata: base64(JSON.stringify(metadata)).storage cpkeeps working as it does today.Behavior
parseUserMetadatabase64-decodes andJSON.parses the header, so numbers and booleans arrive as numbers and booleans.catchinparseUserMetadatareturnsundefined), so a typo would otherwise just give youNULLmetadata. The seed fails with the manifest path and the bad key if:objects_path./separators, so a manifest works the same on Windows. Ifobjects_pathis a single file, its key is the file's basename.objects_path, it's skipped instead of uploaded as an object.supabase start,db resetandseed buckets --linked.Tests
x-metadataheader.buckets.integration.test.tsthat checksuser_metadataon a seeded object.Questions for maintainers
@supabase/config), or does the platform have its own seeder? If it's separate, this PR only covers local seeding and--linked, and branches would need a follow-up on the platform side.objects_metadata_pathfine, or would you rather have something else, such as a nested[storage.buckets.<name>.objects]table?--metadataflag forsupabase storage cpout of this PR unless you want it included.