EntityFrameworkCore.Sqlite.Migrations 1.0.0

dotnet add package EntityFrameworkCore.Sqlite.Migrations --version 1.0.0                
NuGet\Install-Package EntityFrameworkCore.Sqlite.Migrations -Version 1.0.0                
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="EntityFrameworkCore.Sqlite.Migrations" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EntityFrameworkCore.Sqlite.Migrations --version 1.0.0                
#r "nuget: EntityFrameworkCore.Sqlite.Migrations, 1.0.0"                
#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 EntityFrameworkCore.Sqlite.Migrations as a Cake Addin
#addin nuget:?package=EntityFrameworkCore.Sqlite.Migrations&version=1.0.0

// Install EntityFrameworkCore.Sqlite.Migrations as a Cake Tool
#tool nuget:?package=EntityFrameworkCore.Sqlite.Migrations&version=1.0.0                

This lib provide ability to create migrations for Sqlite database with EF Core 3.0

Problem

  • You want update Sqlite database schema with migrations.
  • You want write migrations for database with SQL.
  • You use EF Core.

Solution

  • Put migrations with SQL scripts in the separate files.
  • List all this migrations files in the migrations.txt file in asc order.
  • Apply mirgations from migrations.txt to database.

Example of directory with migrations

.
├── migrations
│   ├── add table `Cat`.sql
│   ├── add table `User`.sql
│   └── init db.sql
└── migrations.txt

Example of migrations.txt

migrations/init db.sql
migrations/add table `User`.sql
migrations/add table `Cat`.sql

How to use lib

// Path to the database file
var dbPath = @"..\..\..\..\..\data\test.db";
            
// Path to the file that contains list of files with migrations
var migrationsPath = @"..\..\..\..\..\db\migrations.txt";

var builder = new DbContextOptionsBuilder() { };
builder.UseSqlite($"Data Source={dbPath}");

var migrationService = new MigrationsService(builder.Options);
await migrationService.MigrateAsync(migrationsPath);

Interesting to know

migrationService.MigrateAsync method will

  • create database if it is not exists
  • create __EFSqliteMigrationsHistory table in the database, that contains rows:
    • MigrationFileSourceSha1 for storing sha1 hash of migration file source
    • MigrationFileName migration file name, it can be not uniq, so you can apply one migration several times
    • MigrationFileSource - it can include source of migration
    • Created - date time of applying migration

Example of database structure

Example of database structure

Example of migrations table

Example of migrations table

Example of migrations table with source of migrations

Example of migrations table

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp3.0 is compatible.  netcoreapp3.1 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
1.0.0 4,051 1/10/2019