using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace WordVersioning.Api.Migrations { /// public partial class TemplatesAndFieldSync : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "DocumentFieldValues", columns: table => new { DocumentId = table.Column(type: "uuid", nullable: false), FieldKey = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), Value = table.Column(type: "text", nullable: false), SourceVersionId = table.Column(type: "uuid", nullable: false), UpdatedByUserId = table.Column(type: "text", nullable: false), UpdatedAt = table.Column(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(type: "uuid", nullable: false), Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), Description = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), ObjectKey = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false), IsActive = table.Column(type: "boolean", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(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(type: "uuid", nullable: false), TemplateId = table.Column(type: "uuid", nullable: false), Key = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), Label = table.Column(type: "character varying(512)", maxLength: 512, nullable: false), Type = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), IsRequired = table.Column(type: "boolean", nullable: false), SortOrder = table.Column(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); } /// 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"); } } }