AvaloniaStack/Avalonia-EFCore/Migrations/SQLite/20260515085847_AutoMigration_20260515165835.cs
luoqian 1ab9a90831 feat: 重构数据库迁移架构,支持多数据库提供程序 (SQLite/SQLServer/PostgreSQL/MySQL)
- 将迁移文件按数据库类型分目录存放 (Migrations/SQLite, MySQL, PostgreSQL, SqlServer)
- 新增各数据库提供程序的 DesignTimeDbContextFactory,支持 --provider 参数切换
- 新增 ProviderAppDataContexts,定义各数据库对应的 AppDataContext 子类
- DatabaseExtensions 增加 AddProviderAppDataContext 方法,按配置自动注册对应 DbContext
- 修正 MySQL 提供程序调用方式 (UseMySql -> UseMySQL)
- UserEntity 模型增加新字段
- 更新 add-migration.ps1
2026-05-20 16:40:57 +08:00

55 lines
2.3 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Avalonia_EFCore.Migrations.SQLite
{
/// <inheritdoc />
public partial class AutoMigration_20260515165835 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "api-refresh-token",
columns: table => new
{
id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
userid = table.Column<int>(name: "user-id", type: "INTEGER", nullable: false),
tokenhash = table.Column<string>(name: "token-hash", type: "TEXT", maxLength: 128, nullable: false),
createdat = table.Column<DateTime>(name: "created-at", type: "TEXT", nullable: false),
expiresat = table.Column<DateTime>(name: "expires-at", type: "TEXT", nullable: false),
revokedat = table.Column<DateTime>(name: "revoked-at", type: "TEXT", nullable: true),
replacedbytokenhash = table.Column<string>(name: "replaced-by-token-hash", type: "TEXT", maxLength: 128, nullable: true),
device = table.Column<string>(type: "TEXT", maxLength: 200, nullable: true),
ipaddress = table.Column<string>(name: "ip-address", type: "TEXT", maxLength: 64, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk-api-refresh-token", x => x.id);
},
comment: "API refresh token");
migrationBuilder.CreateIndex(
name: "idx-api-refresh-token-hash",
table: "api-refresh-token",
column: "token-hash",
unique: true);
migrationBuilder.CreateIndex(
name: "idx-api-refresh-token-user-id",
table: "api-refresh-token",
column: "user-id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "api-refresh-token");
}
}
}