supabase / cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
https://supabase.com/docs/reference/cli/about
MIT License
1.09k stars 212 forks source link

Supabase db push should support migration sub directories #2881

Closed FrancescoMasaia closed 1 week ago

FrancescoMasaia commented 1 week ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

It could be interesting to have the support for push migration for subdirectories instead of only the main directory of supabase/migrations that could be helpful in order to have features or scheme separated for each migration, specially in bigger projects i think that something like that is essential.

Describe the solution you'd like A clear and concise description of what you want to happen.

I would like the script to iterate over supabase/migrations/*/.sql instead of only supabase/migrations/*.sql

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

The other alternative is naming convention but that doesn't help to pre filter easily the files in the file explorer

Additional context Add any other context or screenshots about the feature request here.

sweatybridge commented 1 week ago

We will probably support this by allowing custom migrations path to be declared in config.toml, similar to https://github.com/supabase/cli/issues/2139#issuecomment-2055650677

I will close this one as a duplicate, but feel free to upvote the other issue to help us prioritise.

GitTorres commented 5 days ago

Will a single custom migration path really be the solution here? I too have an interest in organizing my migrations folder by using subdirectories because it's a huge pain to search through to find the right SQL statements to adjust.

example:

migrations/some_view_name/*.sql
migrations/some_other_view_name/*.sql

Is the current vision for custom paths in the config.toml really supporting this?

FrancescoMasaia commented 5 days ago

I don’t think so, but that was my same necessity, and making this possible would be a very little change on the supabase cli (just using a recursive file list instead of looking in the main directory).Il giorno 20 nov 2024, alle ore 20:52, Jose Torres @.***> ha scritto: Will a single custom migration path really be the solution here? I too have an interest in organizing my migrations folder by using subdirectories because it's a huge pain to search through to find the right SQL statements to adjust. example:

subdirectory for each table I've changed. That way I know the last file in each folder is the latest sql for that view.

migrations/vw_some_view migrations/vw_some_other_view

Is the current vision for custom paths in the config.toml really supporting this?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

sweatybridge commented 5 days ago

I too have an interest in organizing my migrations folder by using subdirectories because it's a huge pain to search through to find the right SQL statements to adjust.

That's a slightly different issue. I believe a nice solution for that is to use declarative schemas. So you would declare all your tables once in supabase/schemas directory and use db diff to generate migrations against the declared schema when making changes.

This is currently lacking some docs so I will try to explain the process more in a docs update.

See also https://github.com/supabase/cli/pull/2099

GitTorres commented 5 days ago

Thanks for the idea @sweatybridge! Much appreciated. I'll give that approach a try.