zapodot/embedded-db-junit

Support multiple .withInitialSql() / .withInitialSqlFromResource()

NielsUll opened this issue · 6 comments

We have our sql split in several files - "create_tables.sql", "create_views.sql", "create_indexes.sql".
We cannot load all of them, since each call to .withInitialSqlFromResource() replaces the previous one.

So don't overwrite the previous value of PROP_INIT_SQL
and, optionally, change the signature of .withInitialSqlFromResource to

public Builder withInitialSqlFromResource(final String... resource)

The workaround is of course to set PROP_INIT_SQL manually, but that is less readable

Thank you for the suggestion!

For the next major release, multiple SQL statements will be supported as part of the rewrite to support multiple engines (see #13 ).

Solved on the master branch. Will be available in the 1.1 release

@NielsUll The 1.1.0 release which includes this feature is now available in Maven central. Thank you for adding this feature request :-)

I tried this but can't get it to work. This is what i tested:
@Rule public final EmbeddedDatabaseRule dbRule = EmbeddedDatabaseRule.builder().withMode(CompatibilityMode.MySQL) .withInitialSqlFromResource("classpath:create_foo_table.sql") .withInitialSqlFromResource("classpath:create_bar_table.sql").build();

@andham hard to figure out without the stacktrace and some details of your project and classpath setup

I checked the code and it doesn't work. The second call to withInitialSqlFromResource overwrites the first FilePathInitializationPlugin added.
https://github.com/zapodot/embedded-db-junit/blob/master/embedded-db-junit/src/main/java/org/zapodot/junit/db/EmbeddedDatabaseRule.java#L334

But it's supposed to work and hence a bug?