· 10 years ago · Sep 18, 2016, 03:10 PM
1play.evolutions {
2 db.default.enabled = true
3 autoApply = true
4}
5
6db {
7 default {
8 driver = org.h2.Driver
9 url = "jdbc:h2:mem:test;MODE=MYSQL;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1"
10 username = sa
11 password = ""
12 pool = "bonecp" // otherwise you can't log your sql...
13 bonecp.logStatements=true
14 }
15}
16
17# --- !Ups
18
19CREATE TABLE PROJECTS (
20 id int(11) NOT NULL
21) ;
22
23# --- !Downs
24
25DROP TABLE IF EXISTS PROJECTS;
26
27class DataManagementController @Inject()(db: Database) extends Controller {
28
29 def test() = Action {
30 db.withConnection { conn =>
31 val st = conn.createStatement()
32 val res = st.executeQuery("SELECT * FROM PROJECTS")
33 while (res.next()) { println(res.getInt("id")) }
34 }
35 Ok("")
36 }
37}
38
39class ControllerSpec extends PlaySpec with OneAppPerSuite {
40
41 val TestDb = Databases.inMemory("default")
42 val dataCtrl = new DataManagementController(TestDb)
43
44 "DataManagementController" should {
45 "test" in {
46 dataCtrl.test().apply(FakeRequest())
47 }
48 }
49}
50
51~ test-only ControllerSpec
52
53[info] ControllerSpec:
54[debug] c.j.b.BoneCPDataSource - JDBC URL = jdbc:h2:mem:test;MODE=MYSQL;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1, Username = sa, partitions = 1, max (per partition) = 30, min (per partition) = 5, idle max age = 10 min, idle test period = 1 min, strategy = DEFAULT
55[debug] c.j.b.StatementHandle - select id, hash, apply_script, revert_script, state, last_problem from play_evolutions where state like 'applying_%'
56[error] o.j.StatementLogger - java.sql.Statement.executeQuery: select id, hash, apply_script, revert_script, state, last_problem from play_evolutions where state like 'applying_%';
57throws exception: org.h2.jdbc.JdbcSQLException: Table "play_evolutions" not found; SQL statement:
58select id, hash, apply_script, revert_script, state, last_problem from play_evolutions where state like 'applying_%' [42102-192]
59[...]
60[debug] c.j.b.StatementHandle -
61 create table play_evolutions (
62[...]
63[debug] c.j.b.StatementHandle - CREATE TABLE PROJECTS (
64 id int(11) NOT NULL AUTO_INCREMENT,
65 person_id int(11) NOT NULL,
66 name varchar(255) NOT NULL,
67 PRIMARY KEY (id),
68)
69[debug] c.j.b.StatementHandle - update play_evolutions set state = 'applied' where id = 1
70[debug] c.j.b.StatementHandle - select id, hash, apply_script, revert_script, state, last_problem from play_evolutions where state like 'applying_%'
71
72[info] DataManagementController
73[info] application - Creating Pool for datasource 'default'
74[info] - should test *** FAILED ***
75[info] org.h2.jdbc.JdbcSQLException: Table "PROJECTS" not found;
76[...]
77
78Database 'default' is in an inconsistent state![An evolution has not been applied properly. Please check the problem and resolve it manually before marking it as resolved.]