Creating storage buckets by code (with migrations or config) and seeding files
is there any way to create storage buckets through config or migration SQL? And bonus points if anyone knows how to seed files automatically.
Right now when we run supabase db reset we have to recreate the buckets by hand, which isn’t great and sometimes they get set up wrong and cause issues. We also have a few files we always need for running some features of the application, and we’re adding those manually after every reset.
Would be awesome if this could all happen automatically like DB migrations/seeds. Anyone done this before?
4 Replies
https://supabase.com/docs/guides/storage/buckets/creating-buckets?queryGroups=language&language=sql
No way to create/load files in a migration file though.
Thanks for pointing this way.
After this I stated googling again and found this:
https://github.com/orgs/supabase/discussions/12390#discussioncomment-10260149
That you can add for example the following to you config.toml:
[storage.buckets.images]
public = false
file_size_limit = "50MiB"
allowed_mime_types = ["image/png", "image/jpeg"]
objects_path = "./path/to/images"
and then do 'supabase seed buckets' (see https://supabase.com/docs/reference/cli/supabase-seed#supabase-seed-buckets)
Only the documentation about this is verry minimal and could not find if it is really out of beta now or not. But will try this and let it know here if it worked.
Yeah. Possibly. I was thinking of SQL migrations and not of config.
Yeah would be great if you just need one command, but two commands, if that makes everything the same on all devs laptops, is also oke for me.