-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
Enable conditional migrations through when
callback
#3689
Conversation
PR for the documentation: flarum/docs#442 While working on the docs, I realized 2 potential issues:
EDIT: And yet another thing I haven't really tested, what order do the migrations run during forum installation? Could it cause an issue? I think |
Do we need backend tests for this? |
Let's not merge yet |
Just got around to reading this. It seems like it might make things more difficult then 🤔. We should come up with solutions to these before implementing it.
For this, we could switch to running all migrations instead, which would pick up new migrations for the current ext and dependent ones.
I'm not sure if we can selectively rollback dependent migrations with the current logic 🤔
Since 1.6 they run in the same order as |
Closing until we can look into it in 2.0 |
Fixes #0000
Changes proposed in this pull request:
A new feature that allows extensions to skip database migrations while keeping the ability to execute them again later.
Since Flarum always attempts running all migrations for all extensions on each extension activation, this works well to add tables, columns and constraints that are only needed with optional dependencies.
This cannot be achieved with regular migrations because not doing anything in the
up
callback will still get the migration logged as run and will never be attempted again. And extensions can't easily affect the migration repository to invalidate the recent migration since it's only updated at a later point after the migration callback has run.This feature only applies to
up
migrations.down
migrations don't need the ability to be skipped. If the thing to roll down no longer exists, migrations are already expected to become a no-op and will then successfully be marked as run down. Also, they will only run down if they successfully ran up before.This feature has been successfully implemented in
flamarkt/backoffice
and used byflamarkt/taxonomies
since March 2022. Implementing it in core will enable more extensions to use this feature without the need to addflamarkt/backoffice
as a dependency.Since there is intention to use this for the mentions-tags optional integration, it makes sense to put it in core.
Example implementation in a migration https://github.com/flamarkt/taxonomies/blob/main/migrations/20210401_000400_create_product_term_table.php
Reviewers should focus on:
Other options considered were to use a special return value in the
up
callback or throwing a special exception fromup
. But the dedicatedwhen
callback is the option I find most elegant.I have dropped the
protected
methodresolveAndRunClosureMigration
that was introduced very recently in #3664 because it was making things more complex than necessary since we need the ability toreturn
early in therunUp
method.Screenshot
The only part visible to the user is that the "Skipped" message will be shown every time they run
migrate
if the migration conditions are not met:Necessity
Confirmed
composer test
).Required changes: