Reputation: 387
I have a pretty normal playframework project that implements a number of rest services. 'activator test' runs fine from the command line. When I try to run one of the tests in the debugger in IntelliJ 15, one of my database evolution scripts fails:
12:34:29.031 [main] ERROR play.api.db.evolutions.DefaultEvolutionsApi - Table "TOKEN" not found;SQL statement:
alter table "TOKEN" rename to "POS_TOKEN" [42102-187] [ERROR:42102, SQLSTATE:42S02]
My h2/2.sql looks like this:
# --- !Ups
alter table "TOKEN" rename to "POS_TOKEN";
drop sequence "TOKEN_SEQ" ;
create sequence "POS_TOKEN_SEQ";
# --- !Downs
alter table "POS_TOKEN" rename to "TOKEN";
drop sequence "POS_TOKEN_SEQ" ;
create sequence "TOKEN_SEQ";
The relevant definition of h2/1.sql is
create table token (
id bigint not null,
access_token varchar(255) not null
constraint pk_token primary key (id))
;
This evolution fails only when running in the debugger. When starting the application with 'activator run' the evolution step 2 is executed without error, and the table is renamed correctly. I have verified this using the h2-browser.
I am using IntelliJ 15 Ultimate Edition. The Debug configuration is Class#methodName, VM-arg is -ea, Working dir = $MODULE_DIR$
.
My unit tests that interact with the dabase all extend InMemoryDbTest:
public abstract class InMemoryDbTest {
protected final String fakeUser = "FakeUser";
public FakeApplication app;
@Before
public void before() {
Map<String, String> inMemoryDatabase = Helpers.inMemoryDatabase("h2");
app = Helpers.fakeApplication(inMemoryDatabase);
Helpers.start(app);
}
@After
public void after() {
Helpers.stop(app);
}
}
I am stumped. Any help with solving this issue is appreciated.
Upvotes: 0
Views: 94
Reputation: 387
The key to this issue was that the test runner in IntelliJ had been set up to use the working dir = $MODULE_DIR$, which in my setup equates to $PROJECT_HOME/.idea/modules.
FakeApplication tries to locate the evolutions-script in $MODULE_DIR/conf/evolutions/h2/1.sql, doesnt find it there, and proceeds to autogenerate it based on the latest version of the models. Later on, it runs the evolutions against the database. First it finds the newly autogenerated 1.sql and applies it, then it tries to run the manually created 2.sql and subsequent steps. These fail, because the initial 1.sql is not the 1.sql in $APP/conf/evolutions/h2/1.sql, but the autogenerated $MODULE_DIR$/conf/evolutions/h2/1.sql.
Setting Working Dir in the run configuration for thetest to an empty string solved the problem.
Upvotes: 2