SchemaUtils.createDatabase should work without database connection (+other improvements)
See original GitHub issueHere’s the use case:
- Try to connect to DB X
- 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (7 by maintainers)
Top GitHub Comments
That’s why simple support of schemes in queries should be enough.
Using strings is not a very good idea as it limits you to use extension functions for schemes (if you want to). Also, the field on an original table could not be changed, so I think new class should be introduced.
It just an example and there could be a lot of pitfalls in implementation by I hope you catch the idea.
@hichem-fazai , I’m not sure that it’s possible to change a scheme within the current transaction. Also, I don’t like a restriction with
>Important is that you connect to the instance, not a specific database initially
, why I can’t connect to one database and then change it to another.I guess that the more complex approach to work with scheme/databases should be provided. It should cover other cases like #145 , #254. Do you mind to look at this?