1

In my ASP.NET Core application, I have two application settings, one for production and one for development. I'm also using database migrations to manage my database, that said, with their being two connection strings I can only update the development database from Visual Studio. My question is, is it possile to run database migrations against two connections strings? i.e. the connections strings I have stored in appsettings.Production.json and appsettings.Development.json?

appsettings.Development.json

{     
  "ConnectionStrings": {
    "DevConnection": "Server=tcp:devdatabase.database.windows.net,1433;Initial Catalog=MyDevelopment;Persist Security Info=False;User ID=whatever;Password=whatever;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
  },
  "AllowedHosts": "*"
}

appsettings.Production.json

{     
  "ConnectionStrings": {
    "ProdConnection": "Server=tcp:proddatabase.database.windows.net,1433;Initial Catalog=MyProduction;Persist Security Info=False;User ID=whatever;Password=whatever;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
  },
  "AllowedHosts": "*"
}

Both my database are stored in Azure, typically if I'm wanting to make changes I'll create a migration in the following manner:

Add-Migration AddedBoolColumns

Followed by

Update-Database

The migration takes the development connection string and updates the development database but production remains unchanged and sometimes I want those changed to carry to that database as well. Is there a way this can be done?

Yanayaya
  • 2,044
  • 5
  • 30
  • 67
  • it would defeat the purpose to update both databases at the same time. the purpose of a development db would be to test it and then update the production db if all is ok – Johan Herstad Jun 03 '21 at 11:04
  • Does this answer your question: https://stackoverflow.com/a/66950778/5519026 – LazZiya Jun 03 '21 at 11:35

1 Answers1

0

If you want to run the migrations from your local machine you can add the connection string to Update-Database as an argument. Example Below.

Update-Database -Connection your_connection_string

With that said you can run the migrations to as many databases as you want ^^