cassandra-migration icon indicating copy to clipboard operation
cassandra-migration copied to clipboard

Avoid Cassandra db exception during migration

Open pura1029 opened this issue 6 years ago • 2 comments

How Avoid Cassandra db exception during migration? for eg: @Table(value = "Student ") @Data public class Student { private String id; private String name; }

in my application using spring-data-cassandra, so when i will start application, spring will create table during server start-up. now i want to add age column in Student table @Table(value = "Student ") @Data public class Student { private String id; private String name; private Integer age; } when i will start application, spring will not create table during server start-up. because student table is already exist. so here i using cassandra migration and have written cql script file with ALTER TABLE student add age int; so it is working fine for existing db. if i'm using same cql script file for new fresh db then giving error like Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Invalid column name age because it conflicts with an existing column Caused by: org.cognitor.cassandra.migration.MigrationException: Error during migration of script 1_test.cql while executing 'ALTER TABLE student add age int;' at org.cognitor.cassandra.migration.Database.execute(Database.java:187) ~[cassandra-migration-2.2.0.jar:?] at java.util.ArrayList.forEach(ArrayList.java:1257) ~[?:1.8.0_181] at org.cognitor.cassandra.migration.MigrationTask.migrate(MigrationTask.java:52) ~[cassandra-migration-2.2.0.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]

this error is coming because spring is already added the age column in student table because it is a fresh new db and student table doesn't exist.

so is there any way to skip this type of errors?

pura1029 avatar Mar 29 '19 05:03 pura1029

Hi,

I don’t have any experience with spring data Cassandra so keep that in mind when reading my answer 🙂

Personally I would not try to ignore this exception as it is the symptom of another problem. In my opinion you should not mix the frameworks used for schema creation but go for one of them exclusively. Otherwise you will always depend on your spring container doing things in the right order, meaning first spring data does it’s schema thing and then cassandra migration. The idea of cassandra migration is that you manage your whole schema lifecycle in it. So, if you go for this approach you should create your tables with it in the first place instead of relying on tables that are created by something else. Otherwise you end up with shared responsibilities which is almost never a good idea.

Given that spring data cassandra cannot update a schema without dropping it, according to what I have read, I would go for the approach to have create table statements in cassandra migration as well.

Hope this helps, otherwise I am there for questions.

Cheers Patrick

Am 29.03.2019 um 06:59 schrieb Gautam Kumar [email protected]:

How Avoid Cassandra db exception during migration? for eg: @table(value = "Student ") @DaTa public class Student { private String id; private String name; }

in my application using spring-data-cassandra, so when i will start application, spring will create table during server start-up. now i want to add age column in Student table @table(value = "Student ") @DaTa public class Student { private String id; private String name; private Integer age; } when i will start application, spring will not create table during server start-up. because student table is already exist. so here i using cassandra migration and have written cql script file with ALTER TABLE student add age int; so it is working fine for existing db. if i'm using same cql script file for new fresh db then giving error like Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Invalid column name tags because it conflicts with an existing column Caused by: org.cognitor.cassandra.migration.MigrationException: Error during migration of script 7_test.cql while executing 'ALTER TABLE endpointspec add tags map<text,text>;' at org.cognitor.cassandra.migration.Database.execute(Database.java:187) ~[cassandra-migration-2.2.0.jar:?] at java.util.ArrayList.forEach(ArrayList.java:1257) ~[?:1.8.0_181] at org.cognitor.cassandra.migration.MigrationTask.migrate(MigrationTask.java:52) ~[cassandra-migration-2.2.0.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]

this error is coming because spring is already added the age column in student table because it is a fresh new db and student table doesn't exist.

so is there any way to skip this type of error?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

patka avatar Mar 29 '19 07:03 patka

refer : https://github.com/patka/cassandra-migration/issues/25

kumargautam-vmware avatar May 13 '19 08:05 kumargautam-vmware