JetBrains / JetBrains/Exposed

SchemaUtils.createDatabase should work without database connection (+other improvements)

Open
#795 9 comments 2 reactions 1 assignee Claimed by @Tapac View on GitHub
enhancement good-first-issue
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.