eCourt-Doc-Edit/backend/WordVersioning.Api/Migrations/20260819045552_TemplatesAndFieldSync.cs
Suphonchai Phoonsawat 25c2ce53cd Phase 3
2026-08-19 12:15:20 +07:00

117 lines
5.1 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WordVersioning.Api.Migrations
{
/// <inheritdoc />
public partial class TemplatesAndFieldSync : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "DocumentFieldValues",
columns: table => new
{
DocumentId = table.Column<Guid>(type: "uuid", nullable: false),
FieldKey = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
Value = table.Column<string>(type: "text", nullable: false),
SourceVersionId = table.Column<Guid>(type: "uuid", nullable: false),
UpdatedByUserId = table.Column<string>(type: "text", nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DocumentFieldValues", x => new { x.DocumentId, x.FieldKey });
table.ForeignKey(
name: "FK_DocumentFieldValues_Documents_DocumentId",
column: x => x.DocumentId,
principalTable: "Documents",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Templates",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
Description = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: true),
ObjectKey = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false),
IsActive = table.Column<bool>(type: "boolean", nullable: false),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Templates", x => x.Id);
});
migrationBuilder.CreateTable(
name: "TemplateFields",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
TemplateId = table.Column<Guid>(type: "uuid", nullable: false),
Key = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
Label = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false),
Type = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
IsRequired = table.Column<bool>(type: "boolean", nullable: false),
SortOrder = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TemplateFields", x => x.Id);
table.ForeignKey(
name: "FK_TemplateFields_Templates_TemplateId",
column: x => x.TemplateId,
principalTable: "Templates",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Documents_TemplateId",
table: "Documents",
column: "TemplateId");
migrationBuilder.CreateIndex(
name: "IX_TemplateFields_TemplateId_Key",
table: "TemplateFields",
columns: new[] { "TemplateId", "Key" },
unique: true);
migrationBuilder.AddForeignKey(
name: "FK_Documents_Templates_TemplateId",
table: "Documents",
column: "TemplateId",
principalTable: "Templates",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Documents_Templates_TemplateId",
table: "Documents");
migrationBuilder.DropTable(
name: "DocumentFieldValues");
migrationBuilder.DropTable(
name: "TemplateFields");
migrationBuilder.DropTable(
name: "Templates");
migrationBuilder.DropIndex(
name: "IX_Documents_TemplateId",
table: "Documents");
}
}
}