MikeyT.DbMigrations 0.1.0-alpha

This is a prerelease version of MikeyT.DbMigrations.
There is a newer version of this package available.
See the version list below for details.
dotnet add package MikeyT.DbMigrations --version 0.1.0-alpha
NuGet\Install-Package MikeyT.DbMigrations -Version 0.1.0-alpha
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MikeyT.DbMigrations" Version="0.1.0-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MikeyT.DbMigrations --version 0.1.0-alpha
#r "nuget: MikeyT.DbMigrations, 0.1.0-alpha"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MikeyT.DbMigrations as a Cake Addin
#addin nuget:?package=MikeyT.DbMigrations&version=0.1.0-alpha&prerelease

// Install MikeyT.DbMigrations as a Cake Tool
#tool nuget:?package=MikeyT.DbMigrations&version=0.1.0-alpha&prerelease

db-migrations-dotnet

This is an example of how to manage DB migrations using plain SQL scripts and the built-in dotnet ef tool (Entity Framework) using some simple wrapper code to provide a connection string and give EF your script paths. All this without actually forcing you into using EF for your data access (we're only using it for the DB migrations themselves). An example project also shows how to use simple node package.json commands and gulp tasks to make the process even easier.

You could extend this concept into a small framework, or just copy and paste a few lines from this example into your own project. The point is that you can get DB migrations without being forced into using EF for data access and without using a heavy opinionated DB migrations framework.

What do we need out of a DB migration tool?

At the most basic level, a DB migration framework should really just be responsible for keeping track of what scripts have run and provide simple commands to roll forward or back to a particular migration.

Why?

There are a number of full-featured DB migration frameworks and libraries out there. Most of the time it's probably wise to go with one of these solutions. However, there may be factors that might lead you to make a different choice in some circumstances.

Here are some opinions on why choosing a large framework for DB migrations might not always be the best option:

  • Using a DB migration framework might add unnecessary complexity to your project
  • Most DB migration frameworks are highly opinionated about how you treat DB management. The moment you need something they don't agree with, you're looking at a large effort to create a workaround, or you may end up ejecting from their solution completely, wasting valuable time.
  • DB frameworks advertise that they've created the ability to manipulate SQL in your favorite non-SQL programming language. My experience is that the best language for SQL is usually... SQL. Using your favorite programming language to manipulate SQL seems cool, but risks ending up as a novelty that costs more time than it saves.

The goal of this project is to demonstrate that there are alternatives to hitching up with a big opinionated DB migration framework or creating an entire framework of your own. Instead we can leverage some existing tools (dotnet ef) and the tried and tested plain SQL scripts that won't fail because of an intermediary translation layer failure.

What is the shortest path to implementing this?

Most of the code in this project is just example stuff you probably don't need or want. At a minimum, you need:

  • A project that includes references to:
    • Microsoft.EntityFrameworkCore
    • Microsoft.EntityFrameworkCore.Relational
    • Microsoft.EntityFrameworkCore.Design
  • A DbContext class that you provide a DB connection string to
  • A helper method that calls the MigrationBuilder.Sql() method that you can use in in the Up and Down methods that the dotnet ef tool generates

What extra stuff is in this example project?

Most of the extra fluff in this example project falls in one of these categories:

  • Gather up environment variables to be used to create a DB connection string
  • Convenience console app script commands to create the initial DB or drop it on a developer machine
  • Code to read in SQL files from a common location and process/replace any script placeholders
  • Add convenience scripts to build and package a console app that can be used to migrate DBs in non-dev environments

Most projects/teams are going to have specific requirements and preferences when it comes to environments and deployments, so much of this extra example code may or my not be relevant to your particular situation. The key here is that you can take just the dotnet ef tool use and plain SQL scripts and use your team's other custom processes. Flexibility is the name of the game here.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.7.2 289 2/10/2024
0.7.1 477 12/10/2023
0.7.0 377 12/10/2023
0.6.1 369 12/5/2023
0.6.0 397 12/5/2023
0.5.0 440 12/2/2023
0.4.5 443 12/1/2023
0.4.4 373 12/1/2023
0.4.3 444 11/26/2023
0.4.2 384 11/26/2023
0.4.1 401 11/13/2023
0.4.0 400 11/8/2023
0.3.0-alpha 383 11/2/2023
0.2.1-alpha 402 9/29/2023
0.2.0-alpha 461 7/20/2022
0.1.1-alpha 417 7/3/2022
0.1.0-alpha 454 5/2/2022