Search code examples
springspring-booth2database-migration

Database migration cause errors for H2 database


When i run tests the following migration file causes an

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "ALTER TABLE ACCOUNT
 ADD IS_PROVIDER_ROOT_ACCOUNT VARCHAR(1) NOT NULL,[*]
 ADD PROVIDER_ORGANISATION_ID VARCHAR(255) NULL"; SQL statement:
alter table account
 add is_provider_root_account varchar(1) not null,
 add provider_organisation_id varchar(255) null [42000-200]

error

alter table account
 add is_provider_root_account varchar(1) not null,
 add provider_organisation_id varchar(255) null;

The thing is, if I remove any one of the adds there are no errors. So what can I do here?

My testing configuration file:

spring.datasource.url=jdbc:h2:mem:testdb:MODE=MYSQL
spring.datasource.username=sa
spring.datasource.password=secret
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true

Solution

  • Looking at the H2 syntax (note parentheses), when adding multiple columns, one should do:

    alter table account
    add (
        is_provider_root_account varchar(1) not null,
        provider_organisation_id varchar(255) null
    );