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

Ability to use migrations tool without providing a connection string #2334

Closed
blahDL opened this issue May 15, 2024 · 6 comments
Closed

Ability to use migrations tool without providing a connection string #2334

blahDL opened this issue May 15, 2024 · 6 comments
Labels
question Further information is requested

Comments

@blahDL
Copy link

blahDL commented May 15, 2024

I have a web application which dynamically sets the connection string used by the EF contexts based on request headers. When I start the Migrations Tool it spits out an application exception because the connection string has not been initialised (which is expected as the web application sets the connection string in the dependency injection registration using DbContextOptionsBuilder).

Is it possible to make the database connection string optional when using the migrations tool?
Being able to specify/override a connection string in the options somewhere might work too if the database connection is required

image
On a side note, the error message dialog seems to have a fixed width which makes it insanely long :-|

I currently type commands like these in the command prompt, it would be nice to have a GUI to to simplify these :-)
dotnet ef migrations add --context=[DatabaseContext] [MigrationName]
dotnet ef migrations script --context=[DatabaseContext] --idempotent --output script.sql

@ErikEJ
Copy link
Owner

ErikEJ commented May 15, 2024

Regarding the missing connection string - look at the advise here: https://learn.microsoft.com/en-us/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli (I think you would encounter the exact same issues with the standard CLI tools=

dotnet ef migrations add --context=[DatabaseContext] [MigrationName]

  • does the tool not do that for you already?

dotnet ef migrations script --context=[DatabaseContext] --idempotent --output script.sql

  • Please create a seperate issue for this, seems like a good idea.

@ErikEJ
Copy link
Owner

ErikEJ commented May 17, 2024

@blahDL Ping?

@blahDL
Copy link
Author

blahDL commented May 21, 2024

Weird, I didn't get a notification email from the response or the ping :-|

We always generate the SQL files and run them against our databases, I don't think we have ever tried to run the migrations against a database via the CLI. We have a build step to generate the SQL and commit it to the repository to make it easier for everyone. I'll see what I can get working using that documentation though.

does the tool not do that for you already?

The connection string exception currently prevents me from getting to this functionality :-(

Please create a seperate issue for this, seems like a good idea.

Will do

@blahDL
Copy link
Author

blahDL commented May 21, 2024

I was able to get the migration tool opening up now without throwing the exception by implementing IDesignTimeDbContextFactory for all of the database contexts from the documentation available at https://learn.microsoft.com/en-us/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli#from-a-design-time-factory

image

@blahDL blahDL closed this as completed May 21, 2024
@ErikEJ ErikEJ reopened this May 21, 2024
@ErikEJ ErikEJ closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2024
@ErikEJ ErikEJ added the question Further information is requested label May 21, 2024
@ErikEJ
Copy link
Owner

ErikEJ commented May 21, 2024

Amazing!

@ErikEJ
Copy link
Owner

ErikEJ commented May 21, 2024

If you like my free tools, I would be very grateful for a rating or review on Visual Studio Marketplace or even a one-time or monthly sponsorship

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

No branches or pull requests

2 participants