Initial project import
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MiaoJiZhang.Infrastructure.Persistence.Migrations;
|
||||
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20260722030000_AiChatQuotas")]
|
||||
public partial class AiChatQuotas : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "AiChatLimit",
|
||||
table: "Users",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 50);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "AiChatPeriod",
|
||||
table: "Users",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "AiChatUsed",
|
||||
table: "Users",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "AiChatWindowStartedAt",
|
||||
table: "Users",
|
||||
type: "datetime(6)",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1970, 1, 1));
|
||||
|
||||
migrationBuilder.Sql("""
|
||||
UPDATE Users
|
||||
SET AiChatWindowStartedAt =
|
||||
CONVERT_TZ(DATE(CONVERT_TZ(UTC_TIMESTAMP(6), '+00:00', '+08:00')), '+08:00', '+00:00');
|
||||
""");
|
||||
migrationBuilder.Sql("""
|
||||
INSERT INTO AppConfigs (`Key`, Value, Version, UpdatedAt)
|
||||
SELECT 'quota.default_ai_chat_limit', '50', 1, UTC_TIMESTAMP(6)
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM AppConfigs
|
||||
WHERE `Key` = 'quota.default_ai_chat_limit'
|
||||
);
|
||||
""");
|
||||
migrationBuilder.Sql("""
|
||||
INSERT INTO AppConfigs (`Key`, Value, Version, UpdatedAt)
|
||||
SELECT 'quota.default_ai_chat_period', 'day', 1, UTC_TIMESTAMP(6)
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM AppConfigs
|
||||
WHERE `Key` = 'quota.default_ai_chat_period'
|
||||
);
|
||||
""");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(name: "AiChatLimit", table: "Users");
|
||||
migrationBuilder.DropColumn(name: "AiChatPeriod", table: "Users");
|
||||
migrationBuilder.DropColumn(name: "AiChatUsed", table: "Users");
|
||||
migrationBuilder.DropColumn(name: "AiChatWindowStartedAt", table: "Users");
|
||||
migrationBuilder.Sql(
|
||||
"DELETE FROM AppConfigs WHERE `Key` IN ('quota.default_ai_chat_limit', 'quota.default_ai_chat_period');");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user