Skip to content

seed buckets: support user_metadata on objects uploaded from objects_path #7676

In review

Description

@icopp

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:

  • uploadObjects in apps/cli/src/command-internal/seed-buckets.ts calls gateway.uploadObject with contentType, cacheControl, and overwrite only.
  • [storage.buckets.<name>] accepts public, file_size_limit, allowed_mime_types, and objects_path.
  • supabase storage cp has --cache-control and --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_metadata as 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 metadata key 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 reset that uploads with storage-js and { 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_path plus UPDATE 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.objects from a seed file. This creates rows with no file in the storage backend.

Additional context

Activity

  1. vaibhav375 commented on Nov 17, 2026

    @vaibhav375

    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-contribution before opening a PR.

    Where it goes

    • packages/config/src/storage.ts: add an optional objects_metadata_path string to bucketSchema, defaulting to empty. A relative path resolves against supabase/, the same way objects_path does.
    • 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 to objects_path, and pass the entry to the gateway.
    • apps/cli/src/command-internal/storage-gateway.ts (uploadObject): add an optional metadata field to UploadObjectOptions. When it's set, send x-metadata: base64(JSON.stringify(metadata)). storage cp keeps working as it does today.

    Behavior

    • Values keep their JSON types. Storage's parseUserMetadata base64-decodes and JSON.parses the header, so numbers and booleans arrive as numbers and booleans.
    • The CLI validates the manifest before it uploads anything. Storage silently drops a header it can't parse (the catch in parseUserMetadata returns undefined), so a typo would otherwise just give you NULL metadata. The seed fails with the manifest path and the bad key if:
      • the file isn't valid JSON or isn't an object,
      • an entry isn't a plain object,
      • a key doesn't match a file under objects_path.
    • Keys always use / separators, so a manifest works the same on Windows. If objects_path is a single file, its key is the file's basename.
    • If the manifest sits inside objects_path, it's skipped instead of uploaded as an object.
    • Files with no entry upload exactly as they do now.
    • The same code path covers supabase start, db reset and seed buckets --linked.

    Tests

    • Unit tests for parsing and validating the manifest, and for key matching, including the single-file case.
    • A gateway test that checks the encoded x-metadata header.
    • An integration test in buckets.integration.test.ts that checks user_metadata on a seeded object.

    Questions for maintainers

    1. Preview branches: that's the main reason for this issue. Does branch seeding run this CLI code (or @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.
    2. Naming: is objects_metadata_path fine, or would you rather have something else, such as a nested [storage.buckets.<name>.objects] table?
    3. Scope: I'd leave a --metadata flag for supabase storage cp out of this PR unless you want it included.
  2. self-assigned this
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions