-
-
Notifications
You must be signed in to change notification settings - Fork 46
Rollback command #300
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
Rollback command #300
Conversation
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.
awesome work @krzykamil!! 💪 i left a few comments
more broadly: do you think its worth adding a flag for the number of steps? e.g.: rollback -s 3 or rollback --steps=2 or something similar. i like the simplicity of just passing a number, but i feel the explicitness could both prevent mistypes, help simplify the implementation (since its currently handling the ambiguity), and reduce overall 'magic'
maybe we could keep just passing a single number (like we currently have), as a shortcut. and then the steps flag would be 'in-addition'? i'm curious what you and the rest of the team think about this!
looking forward to seeing where this goes! this is a great feature to have
thanks, I applied everything you caught I like passing steps as a number by default and having it explicit as -s or --steps both. Basically it is either argument or option in the DSL so not much work to change it |
|
great, thanks @krzykamil! everything else looks good to me, curious what everyone else thinks 🙂 |
Thanks, thanks I am also wondering how to do specs in a smart way. Not sure if just copying every spec I have into context for postgres and mysql is the best way, or should I DRY it up (personally not a big fan of RSpec shared_example as it makes debugging nasty sometimes). If none has better ideas I would just copy the specs for each of the database adapters |
The default behavior, if |
Okey, thanks, I somehow missed that code, that makes a lot more sense now :) Will have to adapt my code a bit then |
|
@krzykamil Thanks so much for putting in the work on this command. I recognise that it's pretty gnarly, and I appreciate that you're willing to dive in! Based on your last comment, it sounds like you need to make a couple of adjustments before this is ready for review again? Before that happens, I wonder if we can simplify your job a little bit. Thinking about the “which database(s) to use” heuristic that @alassek shared above, I wonder if it even makes sense for a command like So: what if we made If you have an app with just one database, then you can do (I think we could apply the same “single database only” logic to the If we took this approach, I think this would make the What do you reckon? |
You make valid points ofc, I did work out some scenarios without thinking how useful they are (was thinking too much about if I could, rather than if I should :d . I will refocus on this PR now with those things in mind:
|
|
This has been updated, I am still working on making specs for other databases but the new approach should be clearly visible now |
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.
@krzykamil This is looking beautiful! Definitely the right direction. The command class is much clearer and easier to follow. Thank you! Left a couple of very minor thoughts for you while I was here. Let me know again when this is ready for merge! ❤️
| end | ||
| end | ||
|
|
||
| def resolve_default_database(command_exit) |
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.
Thanks for doing this one. I like that we can keep hanami db rollback simple to call for Hanami apps that have just one database.
| target = steps if steps && !target && !code_is_number?(steps) | ||
| steps_count = steps && code_is_number?(steps) ? Integer(steps) : 1 |
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.
These feel like they could do with some comments explaining what's happening. It's a lot of logic in two lines!
| # When rolling back N steps, we want to target the migration that is N steps back | ||
| # If we have migrations [A, B, C, D] and want to rollback 2 steps from D, | ||
| # we want to target B (index -3, since we go back 2 steps + 1 for the target) |
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.
Explaining this here is very helpful! Thank you!
|
@timriley did some cleanup, added comment about specs, I think its ready |
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.
@krzykamil Beautiful! We made it! What a journey this has been, thank you so much for your persistence 🥰
I'll go ahead and merge this now!
If this is accepted I will provide relevant documentation changes