-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Improve user experience for running migrations after deployment #6313
Comments
cc @rowanmiller we move this to backlog for now but we can discuss pulling it in 1.1.0 or whether we should have better documentation on how to do it manually. |
Any progress on this? I am keen to use this in our application as we are ready to migrate to new environments. I notice that ef.exe is now part of preview 3 and 4 and whilst the --help for the console app is somewhat helpful, a more detailed explanation of the options and commands would be helpful. |
I've helped this scenario a little bit by logging our call to
It's a bit less dramatic on .NET Framework:
|
@bricelam -- Any updates on how to get this to work with the current version of EFCore? As a little background, I'm trying to do an assembly-based migration (not code-based) from TFS Release Management. Thanks, |
Look at the output of |
Thanks for the tip, @bricelam. To make it easier to call from an automated build or TFS Release Management, I turned the calls into a batch script. https://www.benday.com/2017/03/17/deploy-entity-framework-core-migrations-from-a-dll/ |
what about an app published on linux, where ef.dll is nowhere to be found? |
Hi @pdesterlich -- It works almost exactly the same but the paths are slightly different. I've just updated my blog post (https://www.benday.com/2017/03/17/deploy-entity-framework-core-migrations-from-a-dll/) to include a bash shell script for doing the deployment plus a sample of how to call it. Here's a direct link to the bash script: https://www.benday.com/wp-content/uploads/2017/03/deploy-ef-migrations.sh_.txt |
thank you @benday for the reply, but it seems to me i'm missing something. maybe a bit of information about my test setup can help you to help me i have an asp.net core project, developed both on windows and linux; now i'm trying to deploy on a linux server; for my test i'm using a local virtual machine with ubuntu server 16.04 (i'm following more or less a tutorial found here: https://www.junian.net/2017/01/running-your-first-aspnet-core-web-app-on-ubuntu-16-04.html ) When i run my app (with dotnet app-name.dll, or with service as in tutorial above) for some reason the first migration is automatically run, but any subsequent migration is ignored (the same happen in my dev machine if i try to run on a non existent database). I have no .nuget dir anywhere on the server, and i have no ef.dll file also. I could easily generate a migration script and manually apply it to the database, but i'd like to use migration on the deploy machine. What am i missing? |
Hmm. If you can build your dotnet core project on that Ubuntu machine ("dotnet build"), then you definitely have a .nuget folder somewhere. I know that sometimes I get confused when I need to find something in a hidden folder in Linux -- any chance you aren't seeing your $HOME/.nuget directory because that folder is a hidden folder? What happens if you run the following lines?: Do you see a .nuget folder now? What about if you run "cd $HOME/.nuget"? |
Well my ubuntu dev machine is a different machine from my ubuntu server. I already tried "ls -la" on home dir in ubuntu server but as said there isn't a .nuget dir. Keep in mind that everything i'm doing is on an ubuntu server wich is only a deploy server, no development is done on that server |
oh...that's tricky. :) I think you're going to have to find a way to include ef.dll in your build output. It should be pretty easy -- just copy the file from $HOME/.nuget on your dev box and include it in your output files. |
Hi guys, I've also faced this problem. When I execute script from https://www.benday.com/wp-content/uploads/2017/03/deploy-ef-migrations.bat_.txt I receive <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputType>exe</OutputType>
<NuGetPackageRoot> $(USERPROFILE)\.nuget\packages\</NuGetPackageRoot>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<ApplicationIcon />
<OutputTypeEx>exe</OutputTypeEx>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Abp.EntityFrameworkCore" Version="2.1.3" />
<PackageReference Include="Abp.ZeroCore.EntityFrameworkCore" Version="2.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>
|
Version 1.0.0 of the Microsoft.EntityFrameworkCore.Tools.DotNet package isn't compatible with the .NET Core SDK 2.0. Add the following {
"sdk": {
"version": "1.0.4"
}
} |
For .NET Core 2.0 the script by @benday (a huge help) needs modifying. The
|
Hey @Nogbit -- I've been meaning to post an update to the script. I've got a batch script working but (for whatever reason) it seems like there's some inconsistency about where that ef.dll is located for some people's machines. If you're trying to deploy from a TFS build or a TFS release, I've got a better solution that hides the existence of the ef.dll location and skips the deployment script. You can download/install this TFS extension and use the Deploy EF Core Migrations task directly in your build. https://marketplace.visualstudio.com/items?itemName=bendayconsulting.build-task I do a demo of how to use that task in a DevOps video I did for Channel 9. The ef core task part of the demo starts at about 48 min and 45 secs. https://channel9.msdn.com/Events/dotnetConf/2017/T219 If TFS isn't an option, here's the updated batch script:
-Ben |
I'm building and deploying on and to Linux. I have to manually copy that |
@Nogbit -- Managing the location of that ef.dll is about 75% of the problem, huh? :) FYI, my TFS build task is cross-plat and works on Linux and on Windows build agents. |
Hie guys! Is there some progress creating tool that could do migration after deploying assembly ??? |
The tool is available. Getting it on the server and invoking it are the hard parts (see comments above). |
Maybe some One Provides A tutorial? I Have searched this solution about week ! |
@benday has some good guidance and automation tips: https://www.benday.com/2017/03/17/deploy-entity-framework-core-migrations-from-a-dll/ |
Closing in favor of dotnet/EntityFramework.Docs#691 |
Problem
Running migrations on deployment typically means you only have compiled output, not the project system. In theory, ef.exe/ef.dll should work well in this scenario, but figuring out all the arguments requires deep knowledge of how these tools work and is opaque to most users. Furthermore, ef.exe does not end up in compiled output, which requires users to do some NuGet cache spelunking to get the file.
Possible solutions
The text was updated successfully, but these errors were encountered: