Decathlon / tzatziki

Decathlon library to ease and promote Test Driven Development of Java microservices!
Apache License 2.0
59 stars 27 forks source link

DatabaseCleaner seems not taking care of schema name #340

Closed robindecath closed 4 days ago

robindecath commented 1 week ago

https://github.com/Decathlon/tzatziki/blob/c392abc4081b9a88c32e94d940dcde7d093b7cd8/tzatziki-spring-jpa/src/main/java/com/decathlon/tzatziki/utils/DatabaseCleaner.java#L86

Hello,

My db is composed of several schemas. During tests, it happened that when running a single test alone, it worked, but running all tests, some failed that haven't failed when running separately.

I have seen that my table were not truncated. I tried to used your DatabaseClean.clean(dataSource, "schemaname") but it would not work, telling me for example relation "XXX" does not exist. Indeed running the sql line TRUNCATE XXX RESTART IDENTITY CASCADE would not work, but specifying the schema TRUNCATE SCHEMANAME.XXX RESTART IDENTITY CASCADE would make it work.

I copied your DatabaseClean class locally and updated this line to add the schema name, and it worked finally for me:

action.accept(jdbcTemplate, "%s.%s".formatted(schema, table));

Can you see for it and update if needed ?

Kind regards

alexandrepa commented 6 days ago

Hi, thanks for rising this issue, I can see there is some quick adjustment to handle properly multiple schema in a datasource. I'm going to do the adjustments soon.

alexandrepa commented 4 days ago

v1.6.0 should resolve your issue. You can specify a list of schema to clean in your initializer : SpringJPASteps.schemasToClean = List.of("public", "library", "store");

robindecath commented 4 days ago

Hello, thanks for the fix. I will try that and keep you updated.