-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): add repeatable migrations #3046
base: develop
Are you sure you want to change the base?
Conversation
@sweatybridge I already see the mistake, will push a fixed version soon |
Pull Request Test Coverage Report for Build 12941917448Details
💛 - Coveralls |
@sweatybridge as mentioned in the issue #2784 there are a few different options to implement this. I have opted for a simple solution where repeatable migrations are treated like a seed file. Currently they won't be pushed to remote or show up in the studio, as this would create discrepancies when versioning with timestamps and subsequent comparisons between remote/local. They are treated the exact same as the seed file. I experimented locally with creating repeatable migrations and then using the current timestamp as new version for each repeatable migration when applied. (See opening comment of issue). A way around this would be to remove (?!) the remote migration and apply the local one, since the local migration will always supersede the remote migration. Not really sure what to think of this. |
I think this is the right approach for as far as I understand the behaviour of flyway.
Currently seed files are also versioned and tracked in seed_files table, similar to versioned migration. But it used to be untracked so I can understand where the misconception came from. |
I guess I should also add the repeatable migrations to the |
@sweatybridge that should be everything now. I wasn't aware the seed files are versioned as well. I think it would be good to version repeatable migrations, too if possible. Does the cli manage the seed file versioning, or is that done somewhere else? I couldn't find it in |
What's the use case for tracking repeatable migrations? My understanding is that repeatable migrations should always after all versioned migrations, even if there are no changes.
The versioning of seed file is done in https://github.com/supabase/cli/blob/develop/pkg/migration/seed.go#L33 |
pkg/migration/list.go
Outdated
|
||
for _, migration := range localMigrations { | ||
filename := migration.Name() | ||
if strings.HasPrefix(filename, "r_") && strings.HasSuffix(filename, ".sql") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving this check into ListLocalMigrations so it lists both versioned and repeatable? I think that will cover more scenarios than calling from utils.GetPendingMigrations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, your suggestion is to include all repeatable migrations in the ListLocalMigrations
result.
I separated ListRepeatableMigrations
from ListLocalMigrations
to prevent running into errors when diffing local and remote migrations in migration up
. Since the repeatable migrations aren't kept in the versioned migrations table, we would always run into an ErrMissingRemote
error. That's why the repeatable migrations are added to the diff slice after the check.
If I include repeatable migrations in the ListLocalMigrations
result, I will have to tweak the FindPendingMigrations
func to not return an error for repeatable migrations. LMK if that's your preferred solution.
NOTE: There could be further side effects of including repeatable migrations in ListLocalMigrations
.
A few more complications that need answers
|
I suppose tracking them within the db isn't necessary considering they are tracked in version control and always applied after the versioned migrations. The only use case I see is that you could inspect them in supabase studio, which currently isn't possible (I think?). Leaning towards not tracking them then.
Thanks, will have a look at it. |
I think it would be ok to break if the reset can be reverted. Alternatively not allow the command with a warning. Maybe we could do a dry run, see if it succeeds, and react accordingly.
True, 2 needs to be considered. I guess at this point it might make sense to treat repeatable migrations as versioned migrations with only one or an empty/ We could then load them through What are your thoughts on that? @sweatybridge |
Many birds in one stone. I think this is the most ideal solution. Thank you for coming up with the suggestion. |
f67586b
to
322044b
Compare
@sweatybridge the current implementation should satisfy most requirements. I changed it so repeatable migrations are now treated as versioned migrations, with their name as version. Leaving it as an empty string wouldn't work because the The regex to check the migration files for correct formatting and Both I also modified the The repeatable migrations now also show up in the studio: Before I implement the |
@sweatybridge any updates? |
Sorry again for the delay. Given the complexity of this change, I took a step back and suggested an alternative in the original issue #2784 (comment) Let's see if users are comfortable with declarative schema which imo better addresses the duplication issue. |
What kind of change does this PR introduce?
Similar to flyways repeatable migrations this adds rudimentary functionality for repeatable database migrations to the supabase cli.
supabase migration new
to create a repeatable migrationsupabase migration up
Instead of versioning repeatable migration files they are applied after all pending migrations locally and can then be pushed to remote.
What is the current behavior?
Currently database objects like views, functions etc. must be duplicated in the migration files when changed. E.g. to change a
view
we create a new versioned migration in which we duplicate the definition of theview
.What is the new behavior?
supabase migration new
can now be used to create repeatable migrationssupabase migration up
now applies repeatable migrations after all pending migrationsAdditional context
Should close #2784