SchemaUtils.createDatabase should work without database connection (+other improvements)
- Dominant language
- Kotlin
- Stars
- 9.3k
- Forks
- 798
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 26
Description
Here's the use case:
1. Try to connect to DB X
2. First check if it exists
2.1 If it exists, go ahead and connect to it
2.2 If it does not exists, create it and then connect to it
This would be essential in building a resilient system which would allow spinning up new environments quickly with no manual processes involved. I'm picturing spinning up dev/staging/prod environments with auto-created databases, as well as automatically creating feature-based temporary environments for QA approval testing via CI/CD flows.
So, `SchemaUtils.createDatabase` should work in the same "level" as `Database.connect()` to allow this. That is, I first want to check for the existence of a database, create it if it doesn't exist, and then connect to it.
So, perhaps an alternate version of `createDatabase` that tries to establish a connection to the SQL server all on it's own could be used to accomplish this. Or perhaps extend `Database.connect()` with a flag `createDatabaseIfNotExists = true`.
Another Util method `SchemaUtils.doesDatabaseExist(): Boolean` would be helpful as well.
cc @hichem-fazai
Contributor guide
Assessment
This issue has not been assessed yet.