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 rollback_to feature #133

Merged
merged 4 commits into from
Jul 3, 2019
Merged

Conversation

KCErb
Copy link
Contributor

@KCErb KCErb commented Jul 3, 2019

Wow, that was easier than I thought!

But I don't understand the specs well enough to be sure that these tasks don't have specs. Is there somewhere I'm missing that a task spec belongs?

Also you'll notice that I changed the messaging a bit in the test script. Since I put this before rollback_all I wanted to make sure I could visually compare (assuming that's our test method) what the message says we are rolling back to vs what actually got rolled back.

If this goes in, I'll be happy to update the docs (over on the lucky webpage right?). The doc should say something like "rollback_to " and make it clear that we are not rolling back the migration named in the time stamp, we are rolling back to the state that that migration provided.

@@ -26,7 +29,7 @@ if [ $# -eq 0 ]
then
printf "\nChecking that tasks build correctly\n\n"
$COMPOSE shards build

printf "\nChecking code formatting\n\n"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, didn't notice this whitespace change. I guess my editor automatically kills whitespace at the end of lines. I can revert this if desired.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is great! I'm glad your editor caught it :D

Copy link
Member

@paulcsmith paulcsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small suggestions. Looks great though. Thanks for adding this :D

@@ -26,7 +29,7 @@ if [ $# -eq 0 ]
then
printf "\nChecking that tasks build correctly\n\n"
$COMPOSE shards build

printf "\nChecking code formatting\n\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is great! I'm glad your editor caught it :D

@@ -14,6 +14,9 @@ then
$COMPOSE lucky db.drop
$COMPOSE lucky db.create
$COMPOSE lucky db.migrate
printf "\nRolling back to 20180802180356\n"
$COMPOSE lucky db.rollback_to 20180802180356
printf "\nRolling back remainder\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great :)

if version && version.to_i64?
Avram::Migrator::Runner.new.rollback_to(version.to_i64)
else
raise "Migration version is required. Example: lucky db.rollback_to 20180802180356".colorize(:red).to_s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

subset = migrated_migrations.select do |mm|
mm.new.version.to_i64 > last_version
end
subset.reverse.each &.new.down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about printing a message after this like "Done rolling back to #{last_ version}"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me

class Db::RollbackTo < LuckyCli::Task
summary "Rollback to a specific migration"

def call(version : String? = nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this argument is not being used so I think it can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the pattern from gen.migration. I was assuming there was some reason to provide both a method argument and from ARGV in general. I'll remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably left on accident :S I think we can use something like this to test with in the future though. I need to go through and cleanup specs and do some refactoring at some point :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should I leave it in in case of future test or leave it out for now? I'm happy both ways :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I wasn't clear there at all 🤣 you can go ahead and remove it for now. I'll add it back in when I spruce up the tests

@paulcsmith
Copy link
Member

Travis is having an incident so I ran this locally and specs pass. Merging now. Thanks @KCErb :D

@paulcsmith paulcsmith merged commit b6cb187 into luckyframework:master Jul 3, 2019
@KCErb
Copy link
Contributor Author

KCErb commented Jul 3, 2019

🎉 sweet

@KCErb KCErb deleted the rollback_to branch July 3, 2019 15:47
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.

2 participants