Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Do not do any queries if there were no migrations before. #56

Merged
merged 1 commit into from
Mar 29, 2018
Merged

Do not do any queries if there were no migrations before. #56

merged 1 commit into from
Mar 29, 2018

Conversation

Ignas
Copy link
Contributor

@Ignas Ignas commented Mar 22, 2017

Summary

This works around java.util.NoSuchElementException being returned by cassandra
server when executing an empty batch.


Pull Request (PR) Checklist

Documentation

  • Documentation in README.md or Wiki updated
  • Update Release Notes if applicable -- collaborator-access only

Code Review

  • Self code review -- take another pass through the changes yourself

Tests

  • All tests passes

@hhandoko
Copy link
Owner

Thanks for your contribution @Ignas ! Before I can merge it, can you please write some test to check this condition?

if (migrationVersions.size == 0) {
return 1;
}

Copy link
Owner

Choose a reason for hiding this comment

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

This could be rewritten as if (migrationVersions.isEmpty()) return 1 guard clause.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't this line prevent batch from being executed with statements return i + 1?

@hhandoko
Copy link
Owner

Hi @Ignas , can you elaborate the steps to reproduce the issue (i.e. triggering the NoSuchElementException)?

I've tried adding an empty migrations directory and no exceptions are thrown. The for-loop at for (versionRow in versionRows) { ... } and for (i in migrationVersions.indices) { ... } are skipped if no prior migrations exists or versionRows is empty.

@Ignas
Copy link
Contributor Author

Ignas commented Dec 22, 2017

Issue #65 is resolved by the change. This can be easily reproduced with newer cassandra drivers.

@Ignas
Copy link
Contributor Author

Ignas commented Dec 22, 2017

Ok, strike that, this does not resolve the issue, it seems that even when versions table is populated empty batch still gets executed. So the fix should instead check that batch is empty and skip it.

This works around java.util.NoSuchElementException being returned by cassandra
server when executing an empty batch.
@Ignas
Copy link
Contributor Author

Ignas commented Dec 22, 2017

I just removed the batch generation code, as if batch has statements in it - it does not get executed ever.

@hhandoko hhandoko merged commit b42778d into hhandoko:master Mar 29, 2018
@hhandoko
Copy link
Owner

Thank you for your PR, sorry it was left open for too long!

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

Successfully merging this pull request may close these issues.

2 participants