How can solve JSON column in H2

前端 未结 10 1899
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 13:39

I use in application MySQL 5.7 and I have JSON columns. When I try running my integration tests don\'t work because the H2 database can\'t create the table. This is the erro

10条回答
  •  青春惊慌失措
    2020-12-24 13:51

    I am in the same situation as @madz, where we use Postgres in production and H2 for unit tests. In my case i found a bit more simple solution, i think. We use Liquibase for database migrations, so here i made a conditional migration only to be run on H2, where i change the column type to H2's "other" type.

    With the other type, H2 just stores it in the database and doesn't think twice about how the data is formatted etc. This does require however that you are not doing anything with the JSON directly in the database, and only in your application.

    My migration looks like this:

      # Use other type in H2, as jsonb is not supported
      - changeSet:
          id: 42
          author: Elias Jørgensen
          dbms: h2
          changes:
            - modifyDataType:
                tableName: myTableName
                columnName: config
                newDataType: other
    

    Along with this, i added the following to my test datasource:

    INIT=create domain if not exists jsonb as text;
    

提交回复
热议问题