Kros-sk / Kros.Libs

This repo contains Kros.Utils, Kros.Utils.MsAccess, Kros.KORM and Kros.KORM.MsAccess libraries.
MIT License
7 stars 13 forks source link

Database migrations for ASP.NET Core apps #189

Closed Burgyn closed 5 years ago

Burgyn commented 5 years ago

This PR adding migration capability for Asp.net core apps.

For simple database migration, you must call:

public void ConfigureServices(IServiceCollection services)
{
  services.AddKorm(Configuration)
    .AddKormMigrations(Configuration)
    .Migrate();
}   

The previous code requires the KormMigration section in the configurations:

"KormMigrations": {
  "ConnectionString": {
    "ProviderName": "System.Data.SqlClient",
    "ConnectionString": "Server=servername\\instancename;Initial Catalog=database;Persist Security Info=False;"
  },
  "AutoMigrate": "True"
}

Korm performs migrations that default searches in the main assembly in the Sql scripts directory. The script file name must match pattern {migrationId}_{MigrationName}.sql. MigrationId is increasing number over time.

For example: 20190301001_AddPeopleTable.sql

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].People(
    [Id] [int] NOT NULL,
    [Name] [nvarchar](255)
CONSTRAINT [PK_People] PRIMARY KEY CLUSTERED
(
    [Id] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

For more information read README file.