How to change default database connection while testing ? #4493
-
Hello everyone, I'm currently facing an issue regarding changing the default database connection to Here's a snippet of my code:
Thank you in advance ! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
const dbConfig = defineConfig({
connection: env.get('DB_CONNECTION'), // 👈👈👈👈
connections: {
sqlite: {
// ...
},
sqliteTest: {
// ...
}
},
})
export default dbConfig And when you run your tests, the see https://docs.adonisjs.com/guides/testing#environment-variables |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your quick response! |
Beta Was this translation helpful? Give feedback.
DB_CONNECTION=sqlite
variable in your environment variables (.env
+env.ts
)DB_CONNECTION=sqliteTest
variable in your.env.test
fileDB_CONNECTION
in yourconfig/database.ts
file:And when you run your tests, the
.env.test
will be used, so yoursqliteTest
connection defined in your config will be usedsee https://docs.adonisjs.com/guides/testing#environment-variables