using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace TakeoutSaaS.Infrastructure.Migrations.IdentityDb
{
///
public partial class InitSnowflake_Identity : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "identity_users",
columns: table => new
{
Id = table.Column(type: "bigint", nullable: false, comment: "实体唯一标识。")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Account = table.Column(type: "character varying(64)", maxLength: 64, nullable: false, comment: "登录账号。"),
DisplayName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false, comment: "展示名称。"),
PasswordHash = table.Column(type: "character varying(256)", maxLength: 256, nullable: false, comment: "密码哈希。"),
MerchantId = table.Column(type: "bigint", nullable: true, comment: "所属商户(平台管理员为空)。"),
Roles = table.Column(type: "text", nullable: false, comment: "角色集合。"),
Permissions = table.Column(type: "text", nullable: false, comment: "权限集合。"),
Avatar = table.Column(type: "character varying(256)", maxLength: 256, nullable: true, comment: "头像地址。"),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, comment: "创建时间(UTC)。"),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "最近一次更新时间(UTC),从未更新时为 null。"),
DeletedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "软删除时间(UTC),未删除时为 null。"),
CreatedBy = table.Column(type: "bigint", nullable: true, comment: "创建人用户标识,匿名或系统操作时为 null。"),
UpdatedBy = table.Column(type: "bigint", nullable: true, comment: "最后更新人用户标识,匿名或系统操作时为 null。"),
DeletedBy = table.Column(type: "bigint", nullable: true, comment: "删除人用户标识(软删除),未删除时为 null。"),
TenantId = table.Column(type: "bigint", nullable: false, comment: "所属租户 ID。")
},
constraints: table =>
{
table.PrimaryKey("PK_identity_users", x => x.Id);
},
comment: "管理后台账户实体(平台管理员、租户管理员或商户员工)。");
migrationBuilder.CreateTable(
name: "mini_users",
columns: table => new
{
Id = table.Column(type: "bigint", nullable: false, comment: "实体唯一标识。")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OpenId = table.Column(type: "character varying(128)", maxLength: 128, nullable: false, comment: "微信 OpenId。"),
UnionId = table.Column(type: "character varying(128)", maxLength: 128, nullable: true, comment: "微信 UnionId,可能为空。"),
Nickname = table.Column(type: "character varying(64)", maxLength: 64, nullable: false, comment: "昵称。"),
Avatar = table.Column(type: "character varying(256)", maxLength: 256, nullable: true, comment: "头像地址。"),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, comment: "创建时间(UTC)。"),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "最近一次更新时间(UTC),从未更新时为 null。"),
DeletedAt = table.Column(type: "timestamp with time zone", nullable: true, comment: "软删除时间(UTC),未删除时为 null。"),
CreatedBy = table.Column(type: "bigint", nullable: true, comment: "创建人用户标识,匿名或系统操作时为 null。"),
UpdatedBy = table.Column(type: "bigint", nullable: true, comment: "最后更新人用户标识,匿名或系统操作时为 null。"),
DeletedBy = table.Column(type: "bigint", nullable: true, comment: "删除人用户标识(软删除),未删除时为 null。"),
TenantId = table.Column(type: "bigint", nullable: false, comment: "所属租户 ID。")
},
constraints: table =>
{
table.PrimaryKey("PK_mini_users", x => x.Id);
},
comment: "小程序用户实体。");
migrationBuilder.CreateIndex(
name: "IX_identity_users_TenantId",
table: "identity_users",
column: "TenantId");
migrationBuilder.CreateIndex(
name: "IX_identity_users_TenantId_Account",
table: "identity_users",
columns: new[] { "TenantId", "Account" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_mini_users_TenantId",
table: "mini_users",
column: "TenantId");
migrationBuilder.CreateIndex(
name: "IX_mini_users_TenantId_OpenId",
table: "mini_users",
columns: new[] { "TenantId", "OpenId" },
unique: true);
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "identity_users");
migrationBuilder.DropTable(
name: "mini_users");
}
}
}