using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace UnivateProperties_API.Migrations { public partial class BanksAddresses : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Agents_Users_UserId", table: "Agents"); migrationBuilder.DropForeignKey( name: "FK_Individuals_Users_UserId", table: "Individuals"); migrationBuilder.AddColumn( name: "AgencyId", table: "Properties", nullable: true); migrationBuilder.AddColumn( name: "AgentId", table: "Properties", nullable: true); migrationBuilder.AddColumn( name: "OwnerId", table: "Properties", nullable: true); migrationBuilder.AddColumn( name: "StatusId", table: "Properties", nullable: true); migrationBuilder.AlterColumn( name: "UserId", table: "Individuals", nullable: true, oldClrType: typeof(int)); migrationBuilder.AddColumn( name: "AddressId", table: "Individuals", nullable: true); migrationBuilder.AddColumn( name: "CompanyRegNumber", table: "Individuals", nullable: true); migrationBuilder.AddColumn( name: "IdNumber", table: "Individuals", nullable: true); migrationBuilder.AddColumn( name: "IncomeTaxNumber", table: "Individuals", nullable: true); migrationBuilder.AddColumn( name: "MaritalStatus", table: "Individuals", nullable: true); migrationBuilder.AlterColumn( name: "UserId", table: "Agents", nullable: true, oldClrType: typeof(int)); migrationBuilder.CreateTable( name: "Addresses", columns: table => new { Id = table.Column(nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), Created = table.Column(nullable: false), Modified = table.Column(nullable: false), ModifiedBy = table.Column(nullable: true), StreetNumber = table.Column(nullable: true), Street = table.Column(nullable: true), Suburb = table.Column(nullable: true), City = table.Column(nullable: true), PostalCode = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Addresses", x => x.Id); }); migrationBuilder.CreateTable( name: "Banks", columns: table => new { Id = table.Column(nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), Created = table.Column(nullable: false), Modified = table.Column(nullable: false), ModifiedBy = table.Column(nullable: true), Name = table.Column(nullable: true), UniversalBranchCode = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Banks", x => x.Id); }); migrationBuilder.CreateTable( name: "ProcessFlows", columns: table => new { Id = table.Column(nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), Created = table.Column(nullable: false), Modified = table.Column(nullable: false), ModifiedBy = table.Column(nullable: true), TimeshareID = table.Column(nullable: true), PropertyID = table.Column(nullable: true), StatusID = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_ProcessFlows", x => x.Id); table.ForeignKey( name: "FK_ProcessFlows_Properties_PropertyID", column: x => x.PropertyID, principalTable: "Properties", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_ProcessFlows_Status_StatusID", column: x => x.StatusID, principalTable: "Status", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ProcessFlows_Weeks_TimeshareID", column: x => x.TimeshareID, principalTable: "Weeks", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "BankAccounts", columns: table => new { Id = table.Column(nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), Created = table.Column(nullable: false), Modified = table.Column(nullable: false), ModifiedBy = table.Column(nullable: true), AccountHolder = table.Column(nullable: true), AccountNumber = table.Column(nullable: true), BankId = table.Column(nullable: false), OwnerId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_BankAccounts", x => x.Id); table.ForeignKey( name: "FK_BankAccounts_Banks_BankId", column: x => x.BankId, principalTable: "Banks", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_BankAccounts_Individuals_OwnerId", column: x => x.OwnerId, principalTable: "Individuals", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_Properties_AgencyId", table: "Properties", column: "AgencyId"); migrationBuilder.CreateIndex( name: "IX_Properties_AgentId", table: "Properties", column: "AgentId"); migrationBuilder.CreateIndex( name: "IX_Properties_OwnerId", table: "Properties", column: "OwnerId"); migrationBuilder.CreateIndex( name: "IX_Properties_StatusId", table: "Properties", column: "StatusId"); migrationBuilder.CreateIndex( name: "IX_Individuals_AddressId", table: "Individuals", column: "AddressId"); migrationBuilder.CreateIndex( name: "IX_BankAccounts_BankId", table: "BankAccounts", column: "BankId"); migrationBuilder.CreateIndex( name: "IX_BankAccounts_OwnerId", table: "BankAccounts", column: "OwnerId"); migrationBuilder.CreateIndex( name: "IX_ProcessFlows_PropertyID", table: "ProcessFlows", column: "PropertyID"); migrationBuilder.CreateIndex( name: "IX_ProcessFlows_StatusID", table: "ProcessFlows", column: "StatusID"); migrationBuilder.CreateIndex( name: "IX_ProcessFlows_TimeshareID", table: "ProcessFlows", column: "TimeshareID"); migrationBuilder.AddForeignKey( name: "FK_Agents_Users_UserId", table: "Agents", column: "UserId", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); migrationBuilder.AddForeignKey( name: "FK_Individuals_Addresses_AddressId", table: "Individuals", column: "AddressId", principalTable: "Addresses", principalColumn: "Id", onDelete: ReferentialAction.Restrict); migrationBuilder.AddForeignKey( name: "FK_Individuals_Users_UserId", table: "Individuals", column: "UserId", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); migrationBuilder.AddForeignKey( name: "FK_Properties_Agencies_AgencyId", table: "Properties", column: "AgencyId", principalTable: "Agencies", principalColumn: "Id", onDelete: ReferentialAction.Restrict); migrationBuilder.AddForeignKey( name: "FK_Properties_Agents_AgentId", table: "Properties", column: "AgentId", principalTable: "Agents", principalColumn: "Id", onDelete: ReferentialAction.Restrict); migrationBuilder.AddForeignKey( name: "FK_Properties_Individuals_OwnerId", table: "Properties", column: "OwnerId", principalTable: "Individuals", principalColumn: "Id", onDelete: ReferentialAction.Restrict); migrationBuilder.AddForeignKey( name: "FK_Properties_Status_StatusId", table: "Properties", column: "StatusId", principalTable: "Status", principalColumn: "Id", onDelete: ReferentialAction.Restrict); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Agents_Users_UserId", table: "Agents"); migrationBuilder.DropForeignKey( name: "FK_Individuals_Addresses_AddressId", table: "Individuals"); migrationBuilder.DropForeignKey( name: "FK_Individuals_Users_UserId", table: "Individuals"); migrationBuilder.DropForeignKey( name: "FK_Properties_Agencies_AgencyId", table: "Properties"); migrationBuilder.DropForeignKey( name: "FK_Properties_Agents_AgentId", table: "Properties"); migrationBuilder.DropForeignKey( name: "FK_Properties_Individuals_OwnerId", table: "Properties"); migrationBuilder.DropForeignKey( name: "FK_Properties_Status_StatusId", table: "Properties"); migrationBuilder.DropTable( name: "Addresses"); migrationBuilder.DropTable( name: "BankAccounts"); migrationBuilder.DropTable( name: "ProcessFlows"); migrationBuilder.DropTable( name: "Banks"); migrationBuilder.DropIndex( name: "IX_Properties_AgencyId", table: "Properties"); migrationBuilder.DropIndex( name: "IX_Properties_AgentId", table: "Properties"); migrationBuilder.DropIndex( name: "IX_Properties_OwnerId", table: "Properties"); migrationBuilder.DropIndex( name: "IX_Properties_StatusId", table: "Properties"); migrationBuilder.DropIndex( name: "IX_Individuals_AddressId", table: "Individuals"); migrationBuilder.DropColumn( name: "AgencyId", table: "Properties"); migrationBuilder.DropColumn( name: "AgentId", table: "Properties"); migrationBuilder.DropColumn( name: "OwnerId", table: "Properties"); migrationBuilder.DropColumn( name: "StatusId", table: "Properties"); migrationBuilder.DropColumn( name: "AddressId", table: "Individuals"); migrationBuilder.DropColumn( name: "CompanyRegNumber", table: "Individuals"); migrationBuilder.DropColumn( name: "IdNumber", table: "Individuals"); migrationBuilder.DropColumn( name: "IncomeTaxNumber", table: "Individuals"); migrationBuilder.DropColumn( name: "MaritalStatus", table: "Individuals"); migrationBuilder.AlterColumn( name: "UserId", table: "Individuals", nullable: false, oldClrType: typeof(int), oldNullable: true); migrationBuilder.AlterColumn( name: "UserId", table: "Agents", nullable: false, oldClrType: typeof(int), oldNullable: true); migrationBuilder.AddForeignKey( name: "FK_Agents_Users_UserId", table: "Agents", column: "UserId", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); migrationBuilder.AddForeignKey( name: "FK_Individuals_Users_UserId", table: "Individuals", column: "UserId", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); } } }