Support migrations with multiple statements (batch)
Closed this issue · 6 comments
It would be great if a single migration file could contain multiple statements.
I tried to create 2 tables in a migration file, but this seems not to be supported. The migration failed with this error:
com.datastax.driver.core.exceptions.SyntaxError: line 9:0 missing EOF at 'CREATE'
at com.datastax.driver.core.exceptions.SyntaxError.copy(SyntaxError.java:35) ~[cassandra-driver-core-2.0.1.jar:na]
at com.datastax.driver.core.DefaultResultSetFuture.extractCauseFromExecutionException(DefaultResultSetFuture.java:256) ~[cassandra-driver-core-2.0.1.jar:na]
at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:172) ~[cassandra-driver-core-2.0.1.jar:na]
at com.datastax.driver.core.SessionManager.execute(SessionManager.java:91) ~[cassandra-driver-core-2.0.1.jar:na]
at com.datastax.driver.core.SessionManager.execute(SessionManager.java:83) ~[cassandra-driver-core-2.0.1.jar:na]
at com.streamsend.pillar.Migration$class.executeUpStatement(Migration.scala:38) ~[pillar_2.10-1.0.3.jar:1.0.3]
Looking at the Parser
and Migration
classes it seems obvious that it's just not supported.
To support this (without really parsing cql) perhaps a pragmatic/simple solution would be to use some statement separator, like e.g. a line only containing --
with an empty line above/below or s.th. like this.
What do you think?
We haven't had this use case so far. Is there a compelling reason to support it instead of using multiple files?
One use case would be to create a table and add seed data within the same file. Or to create multiple tables as part of a migration of an existing project to C*.
Yes, I agree to magro. We are just starting using it and like in Rails, etc. there are dozens of use cases where one wants to execute multiple statements from one file. Cassandraunit is parsing CQL files and inserting them. Their parser is pretty basic and located here: https://github.com/jsevellec/cassandra-unit/blob/master/cassandra-unit/src/main/java/org/cassandraunit/dataset/cql/AbstractCQLDataSet.java
The original design goal was to promote simple migrations, encouraging developers to write migrations that do one thing. I think that's still feasible. So I'll close this issue.
I'm not completely opposed to the idea of introducing a more sophisticated parser. However, like @pvenable, I don't have a need for it.
Still missing this. Unfortunately github doesn't allow to reopen issues for non project owners :-/