question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migrations Bundles

See original GitHub issue

We currently have dotnet ef migrations script and database update to apply migrations. Unfortunately, they each have their shortcomings.

migrations script is pretty good at producing SQL scripts (there are some known issues with the scripts), but figuring out what to do with those scripts may not be obvious. Publish from Visual Studio wraps these scripts up in a web deployment package and uses MSDeploy to run them on the server. This works well for SQL Server on Windows, but nothing else.

database update is a lot better at applying migrations. It doesn’t have any of the issues the SQL script does. Unfortunately, it requires the .NET Core SDK, your app’s source code, and a direct connection to the production database. Having all of these things available where you need them is’t always possible.

I propose we introduce a new migrations bundle command. This would create a self-contained EXE that you could use to apply migrations. It would behave the same as database update and let you specify the connection string. This would make SSH/Docker/PowerShell deployment a lot easier. You wouldn’t need to copy your source files to a server inside the firewall and you wouldn’t need to install the .NET Core SDK. Here is an example of what it might look like to use SSH:

dotnet ef migrations bundle
scp bundle me@myhost.com:./
ssh me@myhost.com "./bundle --connectionString ${DEPLOYMENT_CONNECTION_STRING}"
ssh me@myhost.com "rm bundle"

Taking this further, Visual Studio could do all of this for you like they do today on MSDeploy but when you’re deploying to Docker. They could even create a new SSH deployment experience.


TODO

  • Add --output to allow renaming the bundle
  • Match TargetFramework, RuntimeIdentifier, and SelfContained of startup project by default
    • Add --no-self-contained
  • --self-contained doesn’t work

    error NETSDK1031: It is not supported to build or publish a self-contained application without specifying a RuntimeIdentifier. You must either specify a RuntimeIdentifier or set SelfContained to false.

  • --runtime doesn’t work between Windows and other OSes. We look for *.exe based on the current runtime instead of the target runtime.
  • Add automated tests
  • Add --force to overwrite an existing bundle #25271
  • Refine command output #25274
  • --configuration and --runtime optoins are repeated in help

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:65
  • Comments:101 (37 by maintainers)

github_iconTop GitHub Comments

39reactions
bricelamcommented, Jul 1, 2021

📢 Status update

I got an end-to-end working. There are still a lot of details to sort out before sending a PR…

Bundles

13reactions
bricelamcommented, Jan 24, 2020

dacpac is perfect for DB-first; keep using it there. However, it’s fundamentally different from Migrations which are designed for a code-first workflow. Also, dacpac is SQL Server-only and a big part of these bundles is to improve the experience when using other databases like PostgreSQL, MySQL, and Oracle.

Fun fact, the first prototype of Migrations was based on dacpac.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Applying Migrations - EF Core
Migration bundles are single-file executables that can be used to apply migrations to a database. They address some of the shortcomings of the ......
Read more >
Migrate your database using Entity Framework Core ...
A migration bundle is a file produced by EF Core that can be used to apply migrations to a database. It was introduced...
Read more >
EF Core 6.0: Introducing Migration Bundles
EF Core 6.0: Introducing Migration Bundles. In this post, let's have a look at a new feature that's coming with EF Core 6...
Read more >
What can they do the migration scripts don't? - YouTube
Introduction to Migration Bundles - What can they do the migration scripts don't? 2.5K views · 1 year ago ...more ...
Read more >
Working with DevOps friendly EF Core Migration Bundles
The migration bundle is a self-contained executable with everything needed to run a migration. It accepts the connection string as a parameter ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found