comeara / pillar

Pillar manages migrations for your Cassandra data stores.
https://github.com/comeara/pillar
MIT License
111 stars 64 forks source link

Support migrations with multiple statements (batch) #6

Closed magro closed 10 years ago

magro commented 10 years ago

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?

magro commented 10 years ago

@pvenable Any thought on this?

pvenable commented 10 years ago

We haven't had this use case so far. Is there a compelling reason to support it instead of using multiple files?

magro commented 10 years ago

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*.

fkoehler commented 10 years ago

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

comeara commented 10 years ago

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.

magro commented 8 years ago

Still missing this. Unfortunately github doesn't allow to reopen issues for non project owners :-/