hhandoko / cassandra-migration

Apache Cassandra / DataStax Enterprise database migration (schema evolution) library
Apache License 2.0
51 stars 21 forks source link

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

Closed Ignas closed 6 years ago

Ignas commented 7 years ago

Summary

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


Pull Request (PR) Checklist

Documentation

Code Review

Tests

hhandoko commented 7 years ago

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

hhandoko commented 7 years ago

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 commented 6 years ago

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

Ignas commented 6 years ago

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.

Ignas commented 6 years ago

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

hhandoko commented 6 years ago

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