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

Provide guidance for deploying migrations #691

Open
ajcvickers opened this issue Apr 24, 2018 · 5 comments
Open

Provide guidance for deploying migrations #691

ajcvickers opened this issue Apr 24, 2018 · 5 comments
Labels
area-migrations help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. propose-punt punted-for-2.2 punted-for-5.0
Milestone

Comments

@ajcvickers
Copy link
Contributor

This would primarily be:

  • Best practices (For example, don't run migrations on app startup, generate scripts, etc.)
  • How to generate scripts
    • Possibly also how to use ef.exe
  • How to deploy scripts to common places--e.g. Azure
    • Possibly pros and cons of doing this a maintenance window as opposed to against a running app, and strategies for doing it against a running app if this is needed.
@johnnyreilly
Copy link

Really pleased to see this has been raised - looking forward to hearing more!

@divega
Copy link
Contributor

divega commented Jun 25, 2018

Copying the address of @johnnyreilly’s blog post here:

https://blog.johnnyreilly.com/2018/06/vsts-and-ef-core-migrations.html

@codekoenig
Copy link

codekoenig commented Jul 5, 2018

Looking forward to "official" guidelines.

Until then, here's what I'm doing which i find to be a quite nice and straightforward solution without creating an additional console app:

  • Adding DotNetCliToolReference to NuGetPackage Microsoft.EntityFrameworkCore.Tools.DotNet
  • In my Build, I add an additional .NET Core task where I use the custom command ef with the following arguments: migrations script -p $(Build.SourcesDirectory)\Project\Project.csproj -o $(build.artifactstagingdirectory)\migrations\migrations.sql -i
  • This generates an idempotent migration script containing all migrations so it can be executed at any migration state of the database and it is published to my build's artifacts in it's own migrations direcotry
  • I execute this script file now in my Release with a SQL Server Database Deploy task. I set the Sql File property as follows based on the path i provided in the Build task: $(System.DefaultWorkingDirectory)\**\Migrations\migrations.sql

That's it - it's straightforward and works nicely, fits perfectly in a Continous Deployment scenario and allowing us to use a deployment user with all necessary rights to change database schemas - while during app runtime, I can run with a different user that has only datareader/datawriter rights.

There is just one drawback: The generated script does not create the database if it does not exist on the first deployment. So the DB has to be there and prepared - or, and that is what I have done, I added an additional SQL Server Database Deploy task with inline SQL to create the database if it does not exist.

I think it's an ok thing to do, but I'd love to have the possibility to optionally add create database SQL with dotnet ef script tooling.

@ajcvickers
Copy link
Contributor Author

See also dotnet/efcore#13339

@divega divega added the help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. label Nov 5, 2018
@divega divega modified the milestones: Backlog, 2.2.0 Nov 10, 2018
@divega divega removed the help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. label Nov 10, 2018
@pekspro
Copy link

pekspro commented Dec 1, 2018

I’m also looking forward to some good documentation about how to create database migrations in Azure Pipelines with ASP.NET Core. It was a lot of trial and error before I got it right.

That said, I wrote a little task to make this easier :-) I created Entity Framework Core Migrations Script Generator:

https://marketplace.visualstudio.com/items?itemName=pekspro.pekspro-efcore-migration-script-generator

It takes care of the part of generating script, the hardest part according to me.

@divega divega added help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. punted-for-2.2 labels Feb 21, 2019
@divega divega modified the milestones: 2.2.0, 3.0.0 Feb 21, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Aug 28, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 5.0.0 Jan 15, 2020
roji added a commit that referenced this issue Jun 29, 2020
Closes #814
Closes #694
Closes #2369
Closes #2188
Closes #1048
Part of #691
@bricelam bricelam modified the milestones: 5.0.0, Backlog Oct 29, 2020
@bricelam bricelam removed their assignment Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. propose-punt punted-for-2.2 punted-for-5.0
Projects
None yet
Development

No branches or pull requests

7 participants