hhandoko / cassandra-migration

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

Avoid exception if keyspace does not exist #66

Closed FuriKuri closed 7 years ago

FuriKuri commented 7 years ago

Summary

I've replace keyspaces.first with keyspaces.filter. At the moment keyspaces.first will throw a NoSuchElementException. With keyspaces.filter the full statement will return false and a CassandraMigrationException will be thrown.

Stack trace before:

Exception in thread "main" java.util.NoSuchElementException: Collection contains no element matching the predicate.
  at com.builtamont.cassandra.migration.CassandraMigration.execute$cassandra_migration(CassandraMigration.kt:535)
  at com.builtamont.cassandra.migration.CassandraMigration.execute$cassandra_migration$default(CassandraMigration.kt:263)
  at com.builtamont.cassandra.migration.CassandraMigration.migrate(CassandraMigration.kt:168)
  at com.builtamont.cassandra.migration.CommandLine.main(CommandLine.kt:68)

Stack trace after:

Exception in thread "main" com.builtamont.cassandra.migration.api.CassandraMigrationException: Keyspace: cassandra_migration_test does not exist.
  at com.builtamont.cassandra.migration.CassandraMigration.execute$cassandra_migration(CassandraMigration.kt:347)
  at com.builtamont.cassandra.migration.CassandraMigration.execute$cassandra_migration$default(CassandraMigration.kt:263)
  at com.builtamont.cassandra.migration.CassandraMigration.migrate(CassandraMigration.kt:168)
  at com.builtamont.cassandra.migration.CommandLine.main(CommandLine.kt:68)

Pull Request (PR) Checklist

Documentation

Code Review

Tests

hhandoko commented 7 years ago

Thanks for your contribution! There's some issue with the CI, I'll merge this as soon as I can fix it (the CI issue).