using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace Somnia.GuestLog.Infrastructure.Migrations { /// public partial class GuestDocument_ChangePKToIdAndVersion : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { //Data don't really matter right now. Just get it working good. //This migration will destry all data, but it's fine. migrationBuilder.DropTable( name: "GuestDocumentStayEntry" ); migrationBuilder.Sql("""DELETE FROM "StayEntry";"""); migrationBuilder.DropTable( name: "GuestDocument" ); migrationBuilder.CreateTable( name: "GuestDocument", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Version = table.Column(type: "integer", nullable: false), DocumentType = table.Column(type: "character varying(8)", maxLength: 8, nullable: false), DocumentNum = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), IssueDate = table.Column(type: "date", nullable: false), SupportNum = table.Column(type: "character varying(10)", maxLength: 10, nullable: true), Nationality = table.Column(type: "character varying(3)", maxLength: 3, nullable: false), Name = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Surname = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Surname2 = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), BirthDate = table.Column(type: "date", nullable: false), Gender = table.Column(type: "character varying(1)", maxLength: 1, nullable: true), PhoneNumber = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), EmailAddress = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), CreateTime = table.Column(type: "timestamp(3) with time zone", nullable: false), UpdateTime = table.Column(type: "timestamp(3) with time zone", nullable: false), IsLastVersion = table.Column(type: "boolean", nullable: false), AddressDetails_Address = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), AddressDetails_AddressCity = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), AddressDetails_AddressCountry = table.Column(type: "character varying(3)", maxLength: 3, nullable: true), AddressDetails_AddressProvince = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), AddressDetails_AddressState = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), AddressDetails_ZipCode = table.Column(type: "character varying(12)", maxLength: 12, nullable: true) }, constraints: table => { table.PrimaryKey("PK_GuestDocument", x => new { x.Id, x.Version }); } ); //Existing index for "DocType" and "DocNum" can be useful, so let's keep it. migrationBuilder.CreateTable( name: "GuestDocumentStayEntry", columns: table => new { StayEntryId = table.Column(type: "bigint", nullable: false), GuestDocumentsId = table.Column(type: "bigint", nullable: false), GuestDocumentsVersion = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_GuestDocumentStayEntry", x => new { x.StayEntryId, x.GuestDocumentsId, x.GuestDocumentsVersion }); table.ForeignKey( name: "FK_GuestDocumentStayEntry_GuestDocument_GuestDocumentsId_Guest~", columns: x => new { x.GuestDocumentsId, x.GuestDocumentsVersion }, principalTable: "GuestDocument", principalColumns: new[] { "Id", "Version" }, onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_GuestDocumentStayEntry_StayEntry_StayEntryId", column: x => x.StayEntryId, principalTable: "StayEntry", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_GuestDocumentStayEntry_GuestDocumentsId_GuestDocumentsVersi~", table: "GuestDocumentStayEntry", columns: new[] { "GuestDocumentsId", "GuestDocumentsVersion" }); } /// protected override void Down(MigrationBuilder migrationBuilder) { throw new NotSupportedException("Rollback is not supported for this migration!"); } } }