Comments (6)
Hi,
Can you show us the error message you have with your configuration?
It might me related to this issue #14
from play-slick.
Thanks for your reply. Actually there is no error message and the test passes. The problem is that test database is not used even though I specified the test database configuration.
Here is the way to reproduce the problem
- Set database configuration like this
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/play_test"
db.default.user=test_user
db.default.password=test_user_pass
test.db.default.driver=com.mysql.jdbc.Driver
test.db.default.url="jdbc:mysql://localhost/play_test"
test.db.default.user=test_user
test.db.default.password=test_user_pass
play run
to apply evolution- Insert some data to Cat table
- Change database configuration to this
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.user=sa
db.default.password=""
test.db.default.driver=com.mysql.jdbc.Driver
test.db.default.url="jdbc:mysql://localhost/play_test"
test.db.default.user=test_user
test.db.default.password=test_user_pass
- Run test
class SlickSpec extends Specification {
// Assume there are more than 2 columns inserted at step 3
// So this test should fail
"Slick" should {
"use test database" in {
running(FakeApplication()) {
import play.api.Play.current
DB.withSession { implicit session =>
val count = Query((for (c <- Query(Cats)) yield c.id).countDistinct).first
count must beEqualTo(1)
}
}
}
}
}
Test should fail, but it passes. This proves test database(in this case MySQL) is not used.
Could you check this?
from play-slick.
Ok I get it now,
This is because the default datasource is always loaded for the slick session if you don't specify a name : https://github.com/freekh/play-slick/blob/master/src/main/scala/play/api/db/slick/DB.scala
You can load a specific DB session with the name parameter of the DB object
from play-slick.
But there is indeed a little problem.
You need to define DB like this :
DB("test").withSession { implicit session =>
val count = Query((for (c <- Query(Cats)) yield c.id).countDistinct).first
count must beEqualTo(1)
}
The datasource will look datasource named ("db.test") and not ("test.default.db")
I will do a little pull request to change this defaults (used in driver loading)
Right now you can configure your application like this :
test.db.default.driver=com.mysql.jdbc.Driver
db.test.driver=com.mysql.jdbc.Driver
db.test.url="jdbc:mysql://localhost/play_test"
db.test.user=test_user
db.test.password=test_user_pass
from play-slick.
With this pull request the convention for driver and datasource will be the same.
But there is another problem : if you want to test some controllers or models that use DB.withSession
you will be binded to the default datasource, not to the test datasource
from play-slick.
I appreciate your PR and reply. I understand how and another problem.
I'll investigate the way I can use environment specified database.
from play-slick.
Related Issues (20)
- Connections not being returned to pool on transaction failure HOT 10
- Cannot acquire connection on many "refresh"
- play 2.7 docs mention play-slick 3.0.0 HOT 2
- Restart connection pools when DB credentials expire HOT 2
- Bump Play version to 2.7.1 HOT 1
- Evolutions fails silently looping the `InvalidDatabaseRevision` for MySQL HOT 1
- Publish for Play 2.7 + slick 3.2? HOT 2
- Unique Indexes break referential integrity. HOT 2
- Evolution script is skipped if there is any Cyrillic character HOT 1
- Why not write Evolutions in Scala ?
- Evolutions are not completed when I access the database programmatically. HOT 15
- Update master Readme to show latest version 5.0.0 HOT 1
- At 5.0.0, Samples don't work HOT 6
- In Play 2.8.2, slick.dbs.default.profile config throws ClassNotFound exception when using custom Profile HOT 4
- Play evolutions throwing error when trying to run it for the first time HOT 10
- please release new version HOT 5
- Unsupported operations post upgrading to scala 2.12 HOT 1
- On startup, evolultion button to apply is disappeared HOT 6
- 6.0.0 Release? HOT 7
- please release new version with slick 3.5.0 final HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from play-slick.