eclipse-hawkbit / hawkbit

Eclipse hawkBit™
https://projects.eclipse.org/projects/iot.hawkbit
Eclipse Public License 2.0
463 stars 188 forks source link

Flyway Migration Fails with hawkbit/hawkbit-update-server:latest #1430

Closed lizziemac closed 1 year ago

lizziemac commented 1 year ago

I'm trying to set up a local instance with Docker and PostgreSQL with the following service configuration in a Docker compose file:

  hawkbit:
    image: hawkbit/hawkbit-update-server:latest
    container_name: backend-hawkbit
    depends_on:
      - postgres
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://backend-postgres/hawkbit
      SPRING_DATASOURCE_USERNAME: backend_user
      SPRING_DATASOURCE_PASSWORD: password
    ports:
      - "3001:8080"
    platform: linux/amd64
    volumes:
      - ./application.properties:/opt/hawkbit/application.properties

However, when running the service, I encounter a Flyway DB migration error that seems to be a SQL syntax issue:

backend-hawkbit   | ----------------------------------------------------------------
backend-hawkbit   | SQL State  : 42601
backend-hawkbit   | Error Code : 0
backend-hawkbit   | Message    : ERROR: syntax error at or near "RENAME"
backend-hawkbit   |   Position: 52
backend-hawkbit   | Location   : db/migration/H2/V1_2_0__update_target_info_for_message___H2.sql (/opt/hawkbit/file:/opt/hawkbit/hawkbit-update-server.jar!/BOOT-INF/lib/hawkbit-repository-jpa-0.3.0M9.jar!/db/migration/H2/V1_2_0__update_target_info_for_message___H2.sql)
backend-hawkbit   | Line       : 3
backend-hawkbit   | Statement  : ALTER TABLE sp_target_info ALTER COLUMN ip_address RENAME TO address
backend-hawkbit   | 
backend-hawkbit   |     at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.handleException(DefaultSqlScriptExecutor.java:275)
backend-hawkbit   |     at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.executeStatement(DefaultSqlScriptExecutor.java:222)
backend-hawkbit   |     at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.execute(DefaultSqlScriptExecutor.java:126)
backend-hawkbit   |     at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.executeOnce(SqlMigrationExecutor.java:69)
backend-hawkbit   |     at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.lambda$execute$0(SqlMigrationExecutor.java:58)
backend-hawkbit   |     at org.flywaydb.core.internal.database.DefaultExecutionStrategy.execute(DefaultExecutionStrategy.java:27)
backend-hawkbit   |     at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:57)
backend-hawkbit   |     at org.flywaydb.core.internal.command.DbMigrate.doMigrateGroup(DbMigrate.java:377)
backend-hawkbit   |     ... 132 common frames omitted
backend-hawkbit   | Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "RENAME"
backend-hawkbit   |   Position: 52
backend-hawkbit   |     at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2675)
backend-hawkbit   |     at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2365)
backend-hawkbit   |     at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:355)
backend-hawkbit   |     at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:490)
backend-hawkbit   |     at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:408)
backend-hawkbit   |     at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:329)
backend-hawkbit   |     at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:315)
backend-hawkbit   |     at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:291)
backend-hawkbit   |     at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:286)
backend-hawkbit   |     at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94)
backend-hawkbit   |     at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
backend-hawkbit   |     at org.flywaydb.core.internal.jdbc.JdbcTemplate.executeStatement(JdbcTemplate.java:201)
backend-hawkbit   |     at org.flywaydb.core.internal.sqlscript.ParsedSqlStatement.execute(ParsedSqlStatement.java:95)
backend-hawkbit   |     at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.executeStatement(DefaultSqlScriptExecutor.java:210)
backend-hawkbit   |     ... 138 common frames omitted
backend-hawkbit   | 
backend-hawkbit   | 
backend-hawkbit exited with code 1

I believe the correct method is

ALTER TABLE sp_target_info RENAME COLUMN ip_address TO address;

What is the recommended approach for getting past this? Editing the migration will likely invalidate checksums for other developers, if they were able to get past this point.

Thanks! Liz

lizziemac commented 1 year ago

I realized that you actually need to specify the database type, here's the updated .yaml (the secret is SPRING_JPA_DATABASE)

  hawkbit:
    image: hawkbit/hawkbit-update-server:latest
    container_name: backend-hawkbit
    depends_on:
      - postgres
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://backend-postgres/hawkbit
      SPRING_DATASOURCE_USERNAME: backend_user
      SPRING_DATASOURCE_PASSWORD: password
      SPRING_JPA_DATABASE: POSTGRESQL

    ports:
      - "3001:8080"
    platform: linux/amd64
    volumes:
      - ./application.properties:/opt/hawkbit/application.properties