As far as I know I can only apply migration scripts to a database through Visual Studio Package Console. But what if I need to deploy scripts of latest changes I made to the database to a production database that I don't have access to through visual studio. Is there a way to convert the .cs migration scripts into an .sql script that I can apply directly through SQL Server? or is there an alternative method for deploying database updates to production databases?
1 Answer
There is a program called Migrate.exe (it should be placed in your package folder) that should be used by some deployment script in your CI system (jenkins/teamcity/visualstudioonline)
When you install Entity Framework using NuGet migrate.exe will be inside the tools folder of the downloaded package. In \packages\EntityFramework.\tools
Once you have migrate.exe then you need to copy it to the location of the assembly that contains your migrations.
YOU SHOULD NEVER CONSIDER DOING A MIGRATION FROM VISUALSTUDIO
for .NET CORE you can simply use a command:
dotnet ef migrations script --output "script.sql" --context MY_DBCONTEXT
the context can be your localdb but it HAS TO be on same migration state as your production database, there is alot configuration going on in the console version so you should be able to google one where instead of context you can put a connection string.