Skip to content
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

Add extension rollback command #1363

Merged
merged 4 commits into from
Feb 12, 2018

Conversation

clarkwinkelmann
Copy link
Member

I'm not sure this adds any end-user benefit but this would really help extension developers when they're trying to run your migrations over and over again.

This also fixes migrateDown not returning the list of notes.

This PR adds a command that is used like this:

$ php flarum migrate:rollback flarum-auth-twitter
Rolling back extension: flarum-auth-twitter
Rolled back: 2015_09_15_000000_add_twitter_id_to_users_table
DONE.

Given that command will probably only be used by developer or when troubleshooting, I'm not sure it's worth checking if the extension is enabled or not. Or maybe rollback could be forbidden for enabled extensions and we could add a --force flag to do it even if the extension is enabled ?

Maybe you'd prefer having the extension name parameter as an option instead of an argument to keep backwards compatibility if you add more options (core or migration-file-specific) to migrate:rollback in the future ?

@clarkwinkelmann
Copy link
Member Author

Just curious, what's the name or the standard you use for the spacing ? phpStorm always adds spaces between 'text' . 'text' and removes space between !$var and I always fall in the StyleCI trap 😬

@tobyzerner
Copy link
Contributor

tobyzerner commented Feb 9, 2018

Does this roll back all migrations for a specific extension? That's confusing behaviour given that the Laravel migrate:rollback command will only roll back the last batch of migrations that were run.

Perhaps this command should be renamed to migrate:reset, which is the equivalent command name for this behaviour in Laravel.

In an ideal world, we should really be extending Laravel's migration stuff rather than rolling our own like we are now. I wonder if it'd be possible to use some of the Laravel classes as a base and override methods as necessary...

Don't think we need a --force flag at the moment.

I think inline with the generate:migration command that extension should be an option rather than an argument.

StyleCI rules are here: https://github.com/flarum/core/blob/master/.styleci.yml

@clarkwinkelmann
Copy link
Member Author

clarkwinkelmann commented Feb 9, 2018 via email

@tobyzerner
Copy link
Contributor

Sounds good. I've made an issue #1365 to track future refactoring.

@franzliedke
Copy link
Contributor

How about wrapping tasks like these in a php flarum extension foo/bar command with subtasks?

@tobyzerner
Copy link
Contributor

I think I prefer an option, because it keeps things simple (eg. when you do php flarum help, you get a flat list of all of the available commands and don't have to worry about sub-commands or anything)

@franzliedke
Copy link
Contributor

That was my point as well, when running php flarum extension foo/bar, you would obviously get a list of (currently available) subtasks. For active extensions, this list would be different from that for inactive ones.

@tobyzerner
Copy link
Contributor

Ah I see, that could be quite handy actually. 👍

@clarkwinkelmann
Copy link
Member Author

I made the changes.

I also added the message "No extension specified. Please check command syntax." if you don't specify the --migration option, because it seems you can't make options being required (which seems kind of logic)

@tobyzerner
Copy link
Contributor

If an extension isn't specified, should we reset core migrations?

@clarkwinkelmann
Copy link
Member Author

I didn't implement it because it doesn't seem to make sense. Unless steps are implemented this will delete the whole forum. Well maybe for development it can be useful.

More a recipe for disaster if somebody types it by mistake on their forum I guess 😬

Or maybe add another flag, like --core to run these ? Just like in the Migrate command, there will be quite a few lines to copy-paste to run the reset.

@clarkwinkelmann
Copy link
Member Author

Also, if somebody runs the core down migrations without first running every migration down migrations, the migrator will be left in a broken state. If any extension changed the columns of a core table, you won't be able to run these down if the column (and table) was removed when reseting core. Even if you re-run migrate, these extension migrations will still be marked as run but the database won't reflect them.

The command could check whether all extensions were reset before resetting the core maybe ?

@tobyzerner
Copy link
Contributor

Sound reasoning. I think we can leave it out for now.

@tobyzerner tobyzerner merged commit 34588a7 into flarum:master Feb 12, 2018
@franzliedke
Copy link
Contributor

@clarkwinkelmann Am I missing something, or would running down migrations for core and active extensions work properly when not providing an extension?

@tobyzerner
Copy link
Contributor

I suppose it would. But it would be dangerous, we'd need a warning/confirmation.

@clarkwinkelmann
Copy link
Member Author

@franzliedke it would be easy to implement the opposite of the migrate command, however this is not only dangerous but this might simply not work at all.

If you only rollback active extensions, but inactive extension have been previously enabled, you're stuck in a state where you need to rollback every single migration that has ever been run before you can safely rollback the core extensions.

Resetting core would probably require more checks to be able to do it safely, for both database integrity and prevent user mistakes.

Maybe instead of allowing to reset core we could just add a migrate:fresh behavior like in Laravel ? Don't try to run down anything, just delete the lot and start again. That's probably what you're going for anyway, given there are no migration steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants