using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace UnivateProperties_API.Migrations { public partial class Initial : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Agencies", 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), AgencyName = table.Column(nullable: true), EAABEFFCNumber = table.Column(nullable: true), CompanyRegNumber = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Agencies", x => x.Id); }); migrationBuilder.CreateTable( name: "Hosts", 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), Host = table.Column(nullable: true), NeedsAuthorize = table.Column(nullable: false), User = table.Column(nullable: true), Password = table.Column(nullable: true), UseSSL = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Hosts", x => x.Id); }); migrationBuilder.CreateTable( name: "PropertyTypes", 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), Description = table.Column(nullable: true), UsageType = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_PropertyTypes", x => x.Id); }); migrationBuilder.CreateTable( name: "Provinces", 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), Description = table.Column(nullable: true), Code = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Provinces", x => x.Id); }); migrationBuilder.CreateTable( name: "Seasons", 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) }, constraints: table => { table.PrimaryKey("PK_Seasons", x => x.Id); }); migrationBuilder.CreateTable( name: "Status", 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), Code = table.Column(nullable: true), Description = table.Column(nullable: true), StatusType = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Status", x => x.Id); }); migrationBuilder.CreateTable( name: "UnitConfigurations", 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), Code = table.Column(nullable: true), Bedrooms = table.Column(nullable: false), Adults = table.Column(nullable: false), Children = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_UnitConfigurations", x => x.Id); }); migrationBuilder.CreateTable( name: "UserDefinedGroups", 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), Description = table.Column(nullable: true), UsageType = table.Column(nullable: false), Rank = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserDefinedGroups", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", 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), Username = table.Column(nullable: true), Role = table.Column(nullable: true), PasswordHash = table.Column(nullable: true), PasswordSalt = table.Column(nullable: true), Verified = table.Column(nullable: false), Token = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Accounts", 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), Address = table.Column(nullable: true), DisplayName = table.Column(nullable: true), SMTPHostId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Accounts", x => x.Id); table.ForeignKey( name: "FK_Accounts_Hosts_SMTPHostId", column: x => x.SMTPHostId, principalTable: "Hosts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Cities", 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), ProvinceId = table.Column(nullable: false), Description = table.Column(nullable: true), Code = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Cities", x => x.Id); table.ForeignKey( name: "FK_Cities_Provinces_ProvinceId", column: x => x.ProvinceId, principalTable: "Provinces", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UnitConfigurationTypes", 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), Description = table.Column(nullable: true), UnitConfigurationId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_UnitConfigurationTypes", x => x.Id); table.ForeignKey( name: "FK_UnitConfigurationTypes_UnitConfigurations_UnitConfiguration~", column: x => x.UnitConfigurationId, principalTable: "UnitConfigurations", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserDefinedFields", 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), GroupId = table.Column(nullable: false), FieldName = table.Column(nullable: true), FieldType = table.Column(nullable: true), Rank = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserDefinedFields", x => x.Id); table.ForeignKey( name: "FK_UserDefinedFields_UserDefinedGroups_GroupId", column: x => x.GroupId, principalTable: "UserDefinedGroups", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Agents", 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), UserId = table.Column(nullable: false), Name = table.Column(nullable: true), Surname = table.Column(nullable: true), Email = table.Column(nullable: true), Telephone = table.Column(nullable: true), CellNumber = table.Column(nullable: true), AgencyId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Agents", x => x.Id); table.ForeignKey( name: "FK_Agents_Agencies_AgencyId", column: x => x.AgencyId, principalTable: "Agencies", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Agents_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Individuals", 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), UserId = table.Column(nullable: false), Name = table.Column(nullable: true), Surname = table.Column(nullable: true), Email = table.Column(nullable: true), Telephone = table.Column(nullable: true), CellNumber = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Individuals", x => x.Id); table.ForeignKey( name: "FK_Individuals_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Emails", 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), SenderId = table.Column(nullable: false), Comment = table.Column(nullable: true), Subject = table.Column(nullable: true), IsBodyHtml = table.Column(nullable: false), CC = table.Column(nullable: true), BCC = table.Column(nullable: true), Body = table.Column(nullable: true), To = table.Column(nullable: true), ToDisplay = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Emails", x => x.Id); table.ForeignKey( name: "FK_Emails_Accounts_SenderId", column: x => x.SenderId, principalTable: "Accounts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Suburbs", 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), CityId = table.Column(nullable: false), Description = table.Column(nullable: true), PostalCode = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Suburbs", x => x.Id); table.ForeignKey( name: "FK_Suburbs_Cities_CityId", column: x => x.CityId, principalTable: "Cities", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Weeks", 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), ReferedByAgent = table.Column(nullable: false), AgentId = table.Column(nullable: true), AgencyId = table.Column(nullable: true), OwnerId = table.Column(nullable: false), OtherResort = table.Column(nullable: false), ResortCode = table.Column(nullable: true), ResortName = table.Column(nullable: true), RegionId = table.Column(nullable: false), Season = table.Column(nullable: true), Module = table.Column(nullable: true), Bedrooms = table.Column(nullable: false), MaxSleep = table.Column(nullable: false), WeekNumber = table.Column(nullable: true), LevyAmount = table.Column(nullable: false), CurrentYearBanked = table.Column(nullable: false), BankedWith = table.Column(nullable: true), LeviesPaidInFull = table.Column(nullable: false), WeekPlacedForRental = table.Column(nullable: false), OriginalPurchasePrice = table.Column(nullable: false), OriginalPurchaseDate = table.Column(nullable: false), ArrivalDate = table.Column(nullable: false), DepartureDate = table.Column(nullable: false), StatusId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Weeks", x => x.Id); table.ForeignKey( name: "FK_Weeks_Agencies_AgencyId", column: x => x.AgencyId, principalTable: "Agencies", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Weeks_Agents_AgentId", column: x => x.AgentId, principalTable: "Agents", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Weeks_Individuals_OwnerId", column: x => x.OwnerId, principalTable: "Individuals", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Weeks_Provinces_RegionId", column: x => x.RegionId, principalTable: "Provinces", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Weeks_Status_StatusId", column: x => x.StatusId, principalTable: "Status", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Properties", 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), CreatedBy = table.Column(nullable: true), PropertyTypeId = table.Column(nullable: false), PropertyName = table.Column(nullable: true), Unit = table.Column(nullable: true), OperationalCosts = table.Column(nullable: false), Price = table.Column(nullable: false), PricePer = table.Column(nullable: true), IsSale = table.Column(nullable: false), Description = table.Column(nullable: true), ShortDescription = table.Column(nullable: true), AddressLine1 = table.Column(nullable: true), AddressLine2 = table.Column(nullable: true), AddressLine3 = table.Column(nullable: true), SuburbId = table.Column(nullable: false), CityId = table.Column(nullable: false), ProvinceId = table.Column(nullable: false), Published = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Properties", x => x.Id); table.ForeignKey( name: "FK_Properties_Cities_CityId", column: x => x.CityId, principalTable: "Cities", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Properties_PropertyTypes_PropertyTypeId", column: x => x.PropertyTypeId, principalTable: "PropertyTypes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Properties_Provinces_ProvinceId", column: x => x.ProvinceId, principalTable: "Provinces", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Properties_Suburbs_SuburbId", column: x => x.SuburbId, principalTable: "Suburbs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "PropertyImages", 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), PropertyId = table.Column(nullable: false), Image = table.Column(nullable: true), IsDefault = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_PropertyImages", x => x.Id); table.ForeignKey( name: "FK_PropertyImages_Properties_PropertyId", column: x => x.PropertyId, principalTable: "Properties", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "PropertyUserFields", 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), PropertyId = table.Column(nullable: false), UserDefinedFieldId = table.Column(nullable: false), Value = table.Column(nullable: true), Description = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_PropertyUserFields", x => x.Id); table.ForeignKey( name: "FK_PropertyUserFields_Properties_PropertyId", column: x => x.PropertyId, principalTable: "Properties", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_PropertyUserFields_UserDefinedFields_UserDefinedFieldId", column: x => x.UserDefinedFieldId, principalTable: "UserDefinedFields", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Accounts_SMTPHostId", table: "Accounts", column: "SMTPHostId"); migrationBuilder.CreateIndex( name: "IX_Agents_AgencyId", table: "Agents", column: "AgencyId"); migrationBuilder.CreateIndex( name: "IX_Agents_UserId", table: "Agents", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Cities_ProvinceId", table: "Cities", column: "ProvinceId"); migrationBuilder.CreateIndex( name: "IX_Emails_SenderId", table: "Emails", column: "SenderId"); migrationBuilder.CreateIndex( name: "IX_Individuals_UserId", table: "Individuals", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Properties_CityId", table: "Properties", column: "CityId"); migrationBuilder.CreateIndex( name: "IX_Properties_PropertyTypeId", table: "Properties", column: "PropertyTypeId"); migrationBuilder.CreateIndex( name: "IX_Properties_ProvinceId", table: "Properties", column: "ProvinceId"); migrationBuilder.CreateIndex( name: "IX_Properties_SuburbId", table: "Properties", column: "SuburbId"); migrationBuilder.CreateIndex( name: "IX_PropertyImages_PropertyId", table: "PropertyImages", column: "PropertyId"); migrationBuilder.CreateIndex( name: "IX_PropertyUserFields_PropertyId", table: "PropertyUserFields", column: "PropertyId"); migrationBuilder.CreateIndex( name: "IX_PropertyUserFields_UserDefinedFieldId", table: "PropertyUserFields", column: "UserDefinedFieldId"); migrationBuilder.CreateIndex( name: "IX_Suburbs_CityId", table: "Suburbs", column: "CityId"); migrationBuilder.CreateIndex( name: "IX_UnitConfigurations_Code", table: "UnitConfigurations", column: "Code", unique: true); migrationBuilder.CreateIndex( name: "IX_UnitConfigurationTypes_UnitConfigurationId", table: "UnitConfigurationTypes", column: "UnitConfigurationId"); migrationBuilder.CreateIndex( name: "IX_UserDefinedFields_GroupId", table: "UserDefinedFields", column: "GroupId"); migrationBuilder.CreateIndex( name: "IX_Weeks_AgencyId", table: "Weeks", column: "AgencyId"); migrationBuilder.CreateIndex( name: "IX_Weeks_AgentId", table: "Weeks", column: "AgentId"); migrationBuilder.CreateIndex( name: "IX_Weeks_OwnerId", table: "Weeks", column: "OwnerId"); migrationBuilder.CreateIndex( name: "IX_Weeks_RegionId", table: "Weeks", column: "RegionId"); migrationBuilder.CreateIndex( name: "IX_Weeks_StatusId", table: "Weeks", column: "StatusId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Emails"); migrationBuilder.DropTable( name: "PropertyImages"); migrationBuilder.DropTable( name: "PropertyUserFields"); migrationBuilder.DropTable( name: "Seasons"); migrationBuilder.DropTable( name: "UnitConfigurationTypes"); migrationBuilder.DropTable( name: "Weeks"); migrationBuilder.DropTable( name: "Accounts"); migrationBuilder.DropTable( name: "Properties"); migrationBuilder.DropTable( name: "UserDefinedFields"); migrationBuilder.DropTable( name: "UnitConfigurations"); migrationBuilder.DropTable( name: "Agents"); migrationBuilder.DropTable( name: "Individuals"); migrationBuilder.DropTable( name: "Status"); migrationBuilder.DropTable( name: "Hosts"); migrationBuilder.DropTable( name: "PropertyTypes"); migrationBuilder.DropTable( name: "Suburbs"); migrationBuilder.DropTable( name: "UserDefinedGroups"); migrationBuilder.DropTable( name: "Agencies"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Cities"); migrationBuilder.DropTable( name: "Provinces"); } } }