432 lines
21 KiB
C#
432 lines
21 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace MiaoJiZhang.Infrastructure.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitialBaseline : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AlterDatabase()
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "AiAvatars",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
Key = table.Column<string>(type: "varchar(255)", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
DefaultName = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
SpeechTic = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
ImageUrl = table.Column<string>(type: "longtext", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_AiAvatars", x => x.Id);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "AiPersonas",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
Key = table.Column<string>(type: "varchar(255)", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Name = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Description = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
SampleLine = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
PromptTemplate = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Version = table.Column<int>(type: "int", nullable: false),
|
|
IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_AiPersonas", x => x.Id);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "AppConfigs",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
Key = table.Column<string>(type: "varchar(255)", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Value = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Version = table.Column<int>(type: "int", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_AppConfigs", x => x.Id);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Categories",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
UserId = table.Column<long>(type: "bigint", nullable: true),
|
|
Type = table.Column<int>(type: "int", nullable: false),
|
|
Name = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
IconKey = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
SortOrder = table.Column<int>(type: "int", nullable: false),
|
|
IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Categories", x => x.Id);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "ChatMessages",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
UserId = table.Column<long>(type: "bigint", nullable: false),
|
|
Role = table.Column<int>(type: "int", nullable: false),
|
|
Type = table.Column<int>(type: "int", nullable: false),
|
|
Content = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
TransactionId = table.Column<long>(type: "bigint", nullable: true),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_ChatMessages", x => x.Id);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Stickers",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
Key = table.Column<string>(type: "varchar(255)", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Label = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
ImageUrl = table.Column<string>(type: "longtext", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
GroupKey = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
TriggerTags = table.Column<string>(type: "longtext", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Stickers", x => x.Id);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Users",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
Username = table.Column<string>(type: "varchar(32)", maxLength: 32, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
PasswordHash = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Nickname = table.Column<string>(type: "varchar(32)", maxLength: 32, nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
AvatarUrl = table.Column<string>(type: "longtext", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Email = table.Column<string>(type: "varchar(255)", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
EmailVerified = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
Phone = table.Column<string>(type: "varchar(255)", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
PhoneVerified = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
WeChatOpenId = table.Column<string>(type: "varchar(255)", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
WeChatUnionId = table.Column<string>(type: "longtext", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
AppleUserId = table.Column<string>(type: "longtext", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
AppMode = table.Column<int>(type: "int", nullable: false),
|
|
IsBanned = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
LastLoginAt = table.Column<DateTime>(type: "datetime(6)", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Users", x => x.Id);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "AiCompanionSettings",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
UserId = table.Column<long>(type: "bigint", nullable: false),
|
|
AvatarKey = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
CustomName = table.Column<string>(type: "longtext", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
PersonaKey = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
RoastLevel = table.Column<int>(type: "int", nullable: false),
|
|
StickerFrequency = table.Column<int>(type: "int", nullable: false),
|
|
ProactiveLevel = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_AiCompanionSettings", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_AiCompanionSettings_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Ledgers",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
OwnerId = table.Column<long>(type: "bigint", nullable: false),
|
|
Name = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
IconKey = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
IsDefault = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Ledgers", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Ledgers_Users_OwnerId",
|
|
column: x => x.OwnerId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Budgets",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
LedgerId = table.Column<long>(type: "bigint", nullable: false),
|
|
UserId = table.Column<long>(type: "bigint", nullable: false),
|
|
CategoryId = table.Column<long>(type: "bigint", nullable: true),
|
|
Period = table.Column<int>(type: "int", nullable: false),
|
|
Amount = table.Column<decimal>(type: "decimal(12,2)", precision: 12, scale: 2, nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Budgets", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Budgets_Ledgers_LedgerId",
|
|
column: x => x.LedgerId,
|
|
principalTable: "Ledgers",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Transactions",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
LedgerId = table.Column<long>(type: "bigint", nullable: false),
|
|
UserId = table.Column<long>(type: "bigint", nullable: false),
|
|
CategoryId = table.Column<long>(type: "bigint", nullable: false),
|
|
Type = table.Column<int>(type: "int", nullable: false),
|
|
Amount = table.Column<decimal>(type: "decimal(12,2)", precision: 12, scale: 2, nullable: false),
|
|
Note = table.Column<string>(type: "longtext", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
PaymentMethod = table.Column<string>(type: "longtext", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
OccurredAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
Source = table.Column<int>(type: "int", nullable: false),
|
|
SourceText = table.Column<string>(type: "longtext", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
SourceChatMessageId = table.Column<long>(type: "bigint", nullable: true),
|
|
IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
DeletedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Transactions", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Transactions_Categories_CategoryId",
|
|
column: x => x.CategoryId,
|
|
principalTable: "Categories",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_Transactions_Ledgers_LedgerId",
|
|
column: x => x.LedgerId,
|
|
principalTable: "Ledgers",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AiAvatars_Key",
|
|
table: "AiAvatars",
|
|
column: "Key",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AiCompanionSettings_UserId",
|
|
table: "AiCompanionSettings",
|
|
column: "UserId",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AiPersonas_Key",
|
|
table: "AiPersonas",
|
|
column: "Key",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AppConfigs_Key",
|
|
table: "AppConfigs",
|
|
column: "Key",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Budgets_LedgerId_Period_CategoryId",
|
|
table: "Budgets",
|
|
columns: new[] { "LedgerId", "Period", "CategoryId" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_ChatMessages_UserId_CreatedAt",
|
|
table: "ChatMessages",
|
|
columns: new[] { "UserId", "CreatedAt" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Ledgers_OwnerId",
|
|
table: "Ledgers",
|
|
column: "OwnerId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Stickers_Key",
|
|
table: "Stickers",
|
|
column: "Key",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Transactions_CategoryId",
|
|
table: "Transactions",
|
|
column: "CategoryId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Transactions_LedgerId_OccurredAt",
|
|
table: "Transactions",
|
|
columns: new[] { "LedgerId", "OccurredAt" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Transactions_UserId_IsDeleted",
|
|
table: "Transactions",
|
|
columns: new[] { "UserId", "IsDeleted" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Users_Email",
|
|
table: "Users",
|
|
column: "Email",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Users_Phone",
|
|
table: "Users",
|
|
column: "Phone",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Users_Username",
|
|
table: "Users",
|
|
column: "Username",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Users_WeChatOpenId",
|
|
table: "Users",
|
|
column: "WeChatOpenId",
|
|
unique: true);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "AiAvatars");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "AiCompanionSettings");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "AiPersonas");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "AppConfigs");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Budgets");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "ChatMessages");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Stickers");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Transactions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Categories");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Ledgers");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Users");
|
|
}
|
|
}
|
|
}
|