question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Tapaccommented, Feb 15, 2020

I guess it’s not possible to change a scheme(at least for mssql) as it is mentioned

That’s why simple support of schemes in queries should be enough.

To support schema in a proper way I propose to add an optional field

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.

class SchemeTable<T:Table>(val scheme: String, private val table: Table) : Table() {
    override val tableName: String = "$scheme.${table.tableName}"
    
}

It just an example and there could be a lot of pitfalls in implementation by I hope you catch the idea.

2reactions
Tapaccommented, Feb 15, 2020

@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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create Database Connection (Data Management)—ArcGIS Pro
ArcGIS geoprocessing tool that creates connection files to databases or enterprise geodatabases.
Read more >
How to properly create and connect to database with Kotlin ...
User from the datasource must have create db privilege. But if you want proceed with your current approach, first you should create a...
Read more >
Creating a Test Database with Navicat 16
Duplicating a database is no exception. ... In the Navigation pane, right-click your connection and select New Database: new_database (51K).
Read more >
SQL Change Automation Visual Studio 4.2 release notes
SQL Change Automation 4 Home · Release notes and other versions ... possible as that will usually result in a faster database connection....
Read more >
Configuration • Akka Persistence JDBC - Documentation
There are several possible ways to configure loading your database connections. Options will be explained below. One database connection pool per journal type....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found