-
Notifications
You must be signed in to change notification settings - Fork 64
How to run migration from ASP.NET Core
Rodel E. Dagumampan edited this page Feb 11, 2020
·
20 revisions
Run your database migration when your ASP.NET Core host service starts up. This ensures that database is always at latest compatible state before operating the service. This is made using Yuniql.AspNetCore nuget package. Package can be used for Worker and WebApp services.
- .NET Core 3.0+ SDK
- SQL Server or Azure SQL Database
- Docker Client, if you choose SQL Server on Container
Deploy an SQL Server on Linux container or use your preferred instance.
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=P@ssw0rd!" -p 1400:1433 -d mcr.microsoft.com/mssql/server:2017-latestCreate new web app
dotnet --version
3.0.100
dotnet new web -o aspnetcore-sample
cd aspnetcore-sampleAdd Yuniql.AspNetCore
dotnet add package Yuniql.AspNetCore
dotnet buildCopy sample database into _db directory in your project
git clone https://github.com/rdagumampan/yuniql.git c:\temp\yuniql-aspnetcore
cd c:\temp\yuniql-aspnetcore\samples\basic-sqlserver-sampleModify the Configure method of Startup.cs, add these lines
using Yuniql.AspNetCore;
...
...
var traceService = new ConsoleTraceService { IsDebugEnabled = true };
app.UseYuniql(traceService, new YuniqlConfiguration
{
WorkspacePath = Path.Combine(Environment.CurrentDirectory, "_db"),
ConnectionString = "Server=localhost,1400;Database=yuniqldb;User Id=SA;Password=P@ssw0rd!",
AutoCreateDatabase = true
});Test run
dotnet build
dotnet run --debugHelp us improve further please create an issue.