My grails application uses h2 embedded database in production and recently I decided to upgrade it from grails 2.3 to 2.4. It went fine while in development mode, but after deploy to tomcat I mentioned that some things are broken, e.g there are problems with counting users, ApplicationContext fails to load my services with getBean etc. I checked the logs and found the following errors:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"; SQL statement: ALTER TABLE PUBLIC.SHIRO_USER_ROLES ADD CONSTRAINT PUBLIC.FKBA2210573552FAD9 FOREIGN KEY(SHIRO_USER_ID) REFERENCES PUBLIC.SHIRO_USER(ID) NOCHECK [23505-176] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:701) Caused by: org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"; SQL statement: ALTER TABLE PUBLIC.SHIRO_USER_ROLES ADD CONSTRAINT PUBLIC.FKBA2210573552FAD9 FOREIGN
KEY(SHIRO_USER_ID) REFERENCES PUBLIC.SHIRO_USER(ID) NOCHECK [23505-176] ... 6 more Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY > KEY ON """".PAGE_INDEX"; SQL statement: ALTER TABLE PUBLIC.SHIRO_USER_ROLES ADD CONSTRAINT PUBLIC.FKBA2210573552FAD9 FOREIGN KEY(SHIRO_USER_ID) REFERENCES PUBLIC.SHIRO_USER(ID) NOCHECK [23505-176]
It looks like the H2 driver version has been updated in grails 2.4 and it is not compatible with the database scheme from the previous version. So what I can do about it? How do I migrate my database to the new H2 so it would work normally?