Olav Grønås Gjerde

profile image
Full stack system architect with passion for Unix, Java, Python and databases.
Twitter @olavgg
2 years ago

Micronaut Test and Flyway. How to clean database for each run.

I had a case where I needed to clean the database when running tests with Micronaut. This is a simple configuration. Just add clean_schema to your application-test.yml

Example:

jpa:
  default:
    properties:
      hibernate:
        show_sql: true
        format_sql: true
datasources:
  default:
    driver-class-name: org.postgresql.Driver
    db-type: postgres
    schema-generate: NONE
    dialect: POSTGRES
    url: jdbc:postgresql://localhost:5432/my_example_test
    username: example_test
    password: example_pw
flyway:
  datasources:
    default:
      enabled: true
      clean-schema: true