- 将迁移文件按数据库类型分目录存放 (Migrations/SQLite, MySQL, PostgreSQL, SqlServer) - 新增各数据库提供程序的 DesignTimeDbContextFactory,支持 --provider 参数切换 - 新增 ProviderAppDataContexts,定义各数据库对应的 AppDataContext 子类 - DatabaseExtensions 增加 AddProviderAppDataContext 方法,按配置自动注册对应 DbContext - 修正 MySQL 提供程序调用方式 (UseMySql -> UseMySQL) - UserEntity 模型增加新字段 - 更新 add-migration.ps1
63 lines
3.1 KiB
C#
63 lines
3.1 KiB
C#
using System;
|
||
using Microsoft.EntityFrameworkCore.Migrations;
|
||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||
|
||
#nullable disable
|
||
|
||
namespace Avalonia_EFCore.Migrations.SQLite
|
||
{
|
||
/// <summary>
|
||
/// 初始数据库基线。后续软件版本只追加新的 Migration,不修改已发布 Migration。
|
||
/// </summary>
|
||
public partial class InitialCreate : Migration
|
||
{
|
||
protected override void Up(MigrationBuilder migrationBuilder)
|
||
{
|
||
migrationBuilder.CreateTable(
|
||
name: "user",
|
||
columns: table => new
|
||
{
|
||
Id = table.Column<int>(name: "id", nullable: false, comment: "用户主键")
|
||
.Annotation("SqlServer:Identity", "1, 1")
|
||
.Annotation("Sqlite:Autoincrement", true)
|
||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||
Name = table.Column<string>(name: "name", maxLength: 100, nullable: true, comment: "用户名称"),
|
||
Email = table.Column<string>(name: "email", maxLength: 200, nullable: true, comment: "用户邮箱"),
|
||
CreatedAt = table.Column<DateTime>(name: "created-at", nullable: false, comment: "创建时间"),
|
||
UpdatedAt = table.Column<DateTime>(name: "updated-at", nullable: false, comment: "更新时间")
|
||
},
|
||
constraints: table =>
|
||
{
|
||
table.PrimaryKey("pk-user", x => x.Id);
|
||
},
|
||
comment: "用户实体,演示数据库 CRUD 操作");
|
||
|
||
migrationBuilder.CreateTable(
|
||
name: "weather-forecast",
|
||
columns: table => new
|
||
{
|
||
Id = table.Column<int>(name: "id", nullable: false, comment: "天气预报主键")
|
||
.Annotation("SqlServer:Identity", "1, 1")
|
||
.Annotation("Sqlite:Autoincrement", true)
|
||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||
Date = table.Column<DateOnly>(name: "date", nullable: false, comment: "预报日期"),
|
||
TemperatureC = table.Column<int>(name: "temperature-c", nullable: false, comment: "摄氏温度"),
|
||
Summary = table.Column<string>(name: "summary", maxLength: 200, nullable: true, comment: "天气摘要"),
|
||
CreatedAt = table.Column<DateTime>(name: "created-at", nullable: false, comment: "创建时间"),
|
||
UpdatedAt = table.Column<DateTime>(name: "updated-at", nullable: false, comment: "更新时间")
|
||
},
|
||
constraints: table =>
|
||
{
|
||
table.PrimaryKey("pk-weather-forecast", x => x.Id);
|
||
},
|
||
comment: "天气预报数据实体");
|
||
}
|
||
|
||
protected override void Down(MigrationBuilder migrationBuilder)
|
||
{
|
||
migrationBuilder.DropTable(name: "weather-forecast");
|
||
migrationBuilder.DropTable(name: "user");
|
||
}
|
||
}
|
||
}
|