Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change WithDatabase method to public #984

Closed

Conversation

MarkusKeusch
Copy link

What does this PR do?

Expose the WithDatabase method of MsSqlBuilder

Why is it important?

By default the initial catalog of the connectionstring is set to master. In some cases we want to just delete and recreate the whole database which is not possible for the master database.

Related issues

@netlify
Copy link

netlify bot commented Aug 29, 2023

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 6cfca8e
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-dotnet/deploys/64ee09ce112d470007d1ea31
😎 Deploy Preview https://deploy-preview-984--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the Microsoft SQL Server Docker image does not support the configuration of the database or username through environment variables during the container start. Changing the modifier to public will not create or configure the database. This limitation is from the image itself, rather than a constraint from Testcontainers.

/// <remarks>
/// The Docker image does not allow to configure the database.
/// </remarks>

Nevertheless, the image does allow the execution of customized SQL scripts (with a couple of adjustments). Along with WithResourceMapping(bytes[], string), we can utilize this to configure the database or username. Furthermore, this enhances the capabilities of the module (image) to similar functionalities like PostgreSQL image offers.

Another alternative is to use the EF or override the database in the connection string.

This issue relates:

@JonasBenz
Copy link
Contributor

JonasBenz commented Aug 30, 2023

Unfortunately, the Microsoft SQL Server Docker image does not support the configuration of the database or username through environment variables during the container start. Changing the modifier to public will not create or configure the database. This limitation is from the image itself, rather than a constraint from Testcontainers.

/// <remarks>
/// The Docker image does not allow to configure the database.
/// </remarks>

Nevertheless, the image does allow the execution of customized SQL scripts (with a couple of adjustments). Along with WithResourceMapping(bytes[], string), we can utilize this to configure the database or username. Furthermore, this enhances the capabilities of the module (image) to similar functionalities like PostgreSQL image offers.

Another alternative is to use the EF or override the database in the connection string.

This issue relates:

What @MarkusKeusch and me want is just to have the "initialCatalog" of the connection string set to a specific DB. Of course we can set the initalCatalog in our project manually or make our own extension method. We will care ourself about creating the DB.

But it would be nice to have the functionality directly from testcontainers. I understand that WithDatabase could lead to false assumptions, that the DB will be created for you.

@HofmeisterAn What do you think about adding an overload for GetConnectionString(), where you can specify the DB, like this: GetConnectionString(string database) or maybe better: GetConnectionString(string initialCatalog)

Or what if we make a builder method WithInitialCatalog(string database)? I would like this approach the best, because it would be obvious, that this will not create a DB and you can specify it once, when you by default not want to work with the "master" DB.

@HofmeisterAn
Copy link
Collaborator

You are referring to the workaround mentioned above, in which Entity Framework creates the database if it does not already exist, right? As previously mentioned, I believe this can be quite misleading. If developers do not utilize EF to generate the non-existent database, they run into issues. I will close this issue. Let's continue the discussion in #986 and see if we can find a suitable solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants