Files
ChatBot/ChatBot/Migrations/20251016214154_InitialCreate.cs
Leonid Pershin 5ce7219703 fix errors
2025-10-17 02:36:47 +03:00

149 lines
5.7 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace ChatBot.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
private const string ChatSessionsTableName = "chat_sessions";
private const string ChatMessagesTableName = "chat_messages";
private const string ChatSessionsIdColumn = "id";
private const string ChatMessagesSessionIdColumn = "session_id";
private const string IntegerType = "integer";
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: ChatSessionsTableName,
columns: table => new
{
id = table
.Column<int>(type: IntegerType, nullable: false)
.Annotation(
"Npgsql:ValueGenerationStrategy",
NpgsqlValueGenerationStrategy.IdentityByDefaultColumn
),
session_id = table.Column<string>(
type: "character varying(50)",
maxLength: 50,
nullable: false
),
chat_id = table.Column<long>(type: "bigint", nullable: false),
chat_type = table.Column<string>(
type: "character varying(20)",
maxLength: 20,
nullable: false
),
chat_title = table.Column<string>(
type: "character varying(200)",
maxLength: 200,
nullable: false
),
model = table.Column<string>(
type: "character varying(100)",
maxLength: 100,
nullable: false
),
created_at = table.Column<DateTime>(
type: "timestamp with time zone",
nullable: false
),
last_updated_at = table.Column<DateTime>(
type: "timestamp with time zone",
nullable: false
),
max_history_length = table.Column<int>(type: IntegerType, nullable: false),
},
constraints: table =>
{
table.PrimaryKey("PK_chat_sessions", x => x.id);
}
);
migrationBuilder.CreateTable(
name: ChatMessagesTableName,
columns: table => new
{
id = table
.Column<int>(type: IntegerType, nullable: false)
.Annotation(
"Npgsql:ValueGenerationStrategy",
NpgsqlValueGenerationStrategy.IdentityByDefaultColumn
),
session_id = table.Column<int>(type: IntegerType, nullable: false),
content = table.Column<string>(
type: "character varying(10000)",
maxLength: 10000,
nullable: false
),
role = table.Column<string>(
type: "character varying(20)",
maxLength: 20,
nullable: false
),
created_at = table.Column<DateTime>(
type: "timestamp with time zone",
nullable: false
),
message_order = table.Column<int>(type: IntegerType, nullable: false),
},
constraints: table =>
{
table.PrimaryKey("PK_chat_messages", x => x.id);
table.ForeignKey(
name: "FK_chat_messages_chat_sessions_session_id",
column: x => x.session_id,
principalTable: ChatSessionsTableName,
principalColumn: ChatSessionsIdColumn,
onDelete: ReferentialAction.Cascade
);
}
);
migrationBuilder.CreateIndex(
name: "IX_chat_messages_created_at",
table: ChatMessagesTableName,
column: "created_at"
);
migrationBuilder.CreateIndex(
name: "IX_chat_messages_session_id",
table: ChatMessagesTableName,
column: ChatMessagesSessionIdColumn
);
migrationBuilder.CreateIndex(
name: "IX_chat_messages_session_id_message_order",
table: ChatMessagesTableName,
columns: new[] { ChatMessagesSessionIdColumn, "message_order" }
);
migrationBuilder.CreateIndex(
name: "IX_chat_sessions_chat_id",
table: ChatSessionsTableName,
column: "chat_id"
);
migrationBuilder.CreateIndex(
name: "IX_chat_sessions_session_id",
table: ChatSessionsTableName,
column: "session_id",
unique: true
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(name: ChatMessagesTableName);
migrationBuilder.DropTable(name: ChatSessionsTableName);
}
}
}