using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Complex.Infrastructure.Migrations { public partial class InitialCreate : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "BasicTables", columns: table => new { Id = table.Column(type: "int", nullable: false), Title = table.Column(type: "nvarchar(max)", nullable: false), Discriminator = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_BasicTables", x => x.Id); }); migrationBuilder.CreateTable( name: "Chats", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ComplexId = table.Column(type: "uniqueidentifier", nullable: false), PersonMobileNumber = table.Column(type: "nvarchar(max)", nullable: false), Body = table.Column(type: "nvarchar(max)", nullable: false), ChatTypeId = table.Column(type: "tinyint", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Chats", x => x.Id); }); migrationBuilder.CreateTable( name: "ComplexUnitEvents", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UnitId = table.Column(type: "uniqueidentifier", nullable: true), ComplexId = table.Column(type: "int", nullable: true), EventDate = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false), RegisterMobileNumber = table.Column(type: "nvarchar(max)", nullable: false), Body = table.Column(type: "nvarchar(max)", nullable: false), Description = table.Column(type: "nvarchar(max)", nullable: true), InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 28, 45, 624, DateTimeKind.Local).AddTicks(5016)), IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), RemoveTime = table.Column(type: "datetime2", nullable: true), UpdateTime = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ComplexUnitEvents", x => x.Id); }); migrationBuilder.CreateTable( name: "Persons", columns: table => new { Id = table.Column(type: "nvarchar(450)", nullable: false), FirstName = table.Column(type: "nvarchar(max)", nullable: true), LastName = table.Column(type: "nvarchar(max)", nullable: true), Gender = table.Column(type: "tinyint", nullable: true), Avatar = table.Column(type: "varbinary(max)", nullable: true), IsActive = table.Column(type: "bit", nullable: false), InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 28, 45, 625, DateTimeKind.Local).AddTicks(1728)), IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), RemoveTime = table.Column(type: "datetime2", nullable: true), UpdateTime = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Persons", x => x.Id); }); migrationBuilder.CreateTable( name: "Posters", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), RegisterMobileNumber = table.Column(type: "nvarchar(max)", nullable: false), IsActive = table.Column(type: "bit", nullable: false), ImagePath = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Posters", x => x.Id); }); migrationBuilder.CreateTable( name: "Provinces", columns: table => new { ProvinceId = table.Column(type: "int", nullable: false), ProvinceTitle = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Provinces", x => x.ProvinceId); }); migrationBuilder.CreateTable( name: "SmsCodes", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false), Code = table.Column(type: "nvarchar(max)", nullable: false), Used = table.Column(type: "bit", nullable: false), RequestCount = table.Column(type: "int", nullable: false), InsertDate = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SmsCodes", x => x.Id); }); migrationBuilder.CreateTable( name: "UnitStates", columns: table => new { Id = table.Column(type: "int", nullable: false), ComplexId = table.Column(type: "uniqueidentifier", nullable: true), Title = table.Column(type: "nvarchar(max)", nullable: false), Icon = table.Column(type: "nvarchar(max)", nullable: false), InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 28, 45, 626, DateTimeKind.Local).AddTicks(1646)), IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), RemoveTime = table.Column(type: "datetime2", nullable: true), UpdateTime = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UnitStates", x => x.Id); }); migrationBuilder.CreateTable( name: "ComplexPersons", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ComplexId = table.Column(type: "uniqueidentifier", nullable: false), PersonMobileNumberId = table.Column(type: "nvarchar(450)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ComplexPersons", x => x.Id); table.ForeignKey( name: "FK_ComplexPersons_Persons_PersonMobileNumberId", column: x => x.PersonMobileNumberId, principalTable: "Persons", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "UserTokens", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), TokenHash = table.Column(type: "nvarchar(max)", nullable: false), TokenExp = table.Column(type: "datetime2", nullable: false), RefreshToken = table.Column(type: "nvarchar(max)", nullable: false), RefreshTokenExp = table.Column(type: "datetime2", nullable: false), MobileModel = table.Column(type: "nvarchar(max)", nullable: false), PersonId = table.Column(type: "nvarchar(450)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserTokens", x => x.Id); table.ForeignKey( name: "FK_UserTokens_Persons_PersonId", column: x => x.PersonId, principalTable: "Persons", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Cities", columns: table => new { CityId = table.Column(type: "int", nullable: false), ProvinceId = table.Column(type: "int", nullable: true), CityTitle = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Cities", x => x.CityId); table.ForeignKey( name: "FK_Cities_Provinces_ProvinceId", column: x => x.ProvinceId, principalTable: "Provinces", principalColumn: "ProvinceId"); }); migrationBuilder.CreateTable( name: "ComplexEntities", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Title = table.Column(type: "nvarchar(max)", nullable: false), Address = table.Column(type: "nvarchar(max)", nullable: true), StateId = table.Column(type: "int", nullable: true), AreaMeter = table.Column(type: "int", nullable: true), YardMeter = table.Column(type: "int", nullable: true), ElevatorCount = table.Column(type: "int", nullable: true), WarehouseCount = table.Column(type: "int", nullable: true), YearMake = table.Column(type: "int", nullable: true), ParentId = table.Column(type: "uniqueidentifier", nullable: true), Description = table.Column(type: "nvarchar(max)", nullable: true), CityId = table.Column(type: "int", nullable: false), InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 28, 45, 623, DateTimeKind.Local).AddTicks(7632)), IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), RemoveTime = table.Column(type: "datetime2", nullable: true), UpdateTime = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ComplexEntities", x => x.Id); table.ForeignKey( name: "FK_ComplexEntities_Cities_CityId", column: x => x.CityId, principalTable: "Cities", principalColumn: "CityId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ComplexEntities_ComplexEntities_ParentId", column: x => x.ParentId, principalTable: "ComplexEntities", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "ComplexManagers", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ComplexId = table.Column(type: "uniqueidentifier", nullable: false), ManagerMobileNumberId = table.Column(type: "nvarchar(450)", nullable: true), StartDate = table.Column(type: "nvarchar(max)", nullable: false), EndDate = table.Column(type: "nvarchar(max)", nullable: false), InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 28, 45, 624, DateTimeKind.Local).AddTicks(2426)), IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), RemoveTime = table.Column(type: "datetime2", nullable: true), UpdateTime = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ComplexManagers", x => x.Id); table.ForeignKey( name: "FK_ComplexManagers_ComplexEntities_ComplexId", column: x => x.ComplexId, principalTable: "ComplexEntities", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ComplexManagers_Persons_ManagerMobileNumberId", column: x => x.ManagerMobileNumberId, principalTable: "Persons", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "IncomeCostTitles", columns: table => new { Id = table.Column(type: "int", nullable: false), Title = table.Column(type: "nvarchar(max)", nullable: true), TransactionTypeId = table.Column(type: "int", nullable: false), ComplexId = table.Column(type: "uniqueidentifier", nullable: true), RegisterMobileNumber = table.Column(type: "nvarchar(max)", nullable: true), InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 28, 45, 624, DateTimeKind.Local).AddTicks(9858)), IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), RemoveTime = table.Column(type: "datetime2", nullable: true), UpdateTime = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_IncomeCostTitles", x => x.Id); table.ForeignKey( name: "FK_IncomeCostTitles_BasicTables_TransactionTypeId", column: x => x.TransactionTypeId, principalTable: "BasicTables", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_IncomeCostTitles_ComplexEntities_ComplexId", column: x => x.ComplexId, principalTable: "ComplexEntities", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Units", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), ComplexId = table.Column(type: "uniqueidentifier", nullable: false), UnitName = table.Column(type: "nvarchar(max)", nullable: false), OwnerId = table.Column(type: "nvarchar(450)", nullable: true), TenantId = table.Column(type: "nvarchar(450)", nullable: true), IsActive = table.Column(type: "bit", nullable: false), AreaMeter = table.Column(type: "int", nullable: true), EmergencyTels = table.Column(type: "nvarchar(max)", nullable: true), ParkingAreaMeter = table.Column(type: "int", nullable: true), YardMeter = table.Column(type: "int", nullable: true), PublicState = table.Column(type: "nvarchar(max)", nullable: true), StateId = table.Column(type: "int", nullable: true), Floor = table.Column(type: "int", nullable: true), ManagerDescription = table.Column(type: "nvarchar(max)", nullable: true), InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 28, 45, 625, DateTimeKind.Local).AddTicks(7151)), IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), RemoveTime = table.Column(type: "datetime2", nullable: true), UpdateTime = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Units", x => x.Id); table.ForeignKey( name: "FK_Units_ComplexEntities_ComplexId", column: x => x.ComplexId, principalTable: "ComplexEntities", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Units_Persons_OwnerId", column: x => x.OwnerId, principalTable: "Persons", principalColumn: "Id"); table.ForeignKey( name: "FK_Units_Persons_TenantId", column: x => x.TenantId, principalTable: "Persons", principalColumn: "Id"); table.ForeignKey( name: "FK_Units_UnitStates_StateId", column: x => x.StateId, principalTable: "UnitStates", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "CostCycles", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), ComplexId = table.Column(type: "uniqueidentifier", nullable: false), Title = table.Column(type: "nvarchar(max)", nullable: false), StartDate = table.Column(type: "date", nullable: false), EndDate = table.Column(type: "date", nullable: false), Amount = table.Column(type: "bigint", nullable: false), EncouragementDay = table.Column(type: "int", nullable: false), EncouragementAmount = table.Column(type: "bigint", nullable: false), IncomeCostTitleId = table.Column(type: "int", nullable: true), InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 28, 45, 624, DateTimeKind.Local).AddTicks(7249)), IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), RemoveTime = table.Column(type: "datetime2", nullable: true), UpdateTime = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_CostCycles", x => x.Id); table.ForeignKey( name: "FK_CostCycles_ComplexEntities_ComplexId", column: x => x.ComplexId, principalTable: "ComplexEntities", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_CostCycles_IncomeCostTitles_IncomeCostTitleId", column: x => x.IncomeCostTitleId, principalTable: "IncomeCostTitles", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "CostCycleUnit", columns: table => new { CostCyclesId = table.Column(type: "uniqueidentifier", nullable: false), UnitsId = table.Column(type: "uniqueidentifier", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CostCycleUnit", x => new { x.CostCyclesId, x.UnitsId }); table.ForeignKey( name: "FK_CostCycleUnit_CostCycles_CostCyclesId", column: x => x.CostCyclesId, principalTable: "CostCycles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_CostCycleUnit_Units_UnitsId", column: x => x.UnitsId, principalTable: "Units", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "UnitCosts", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), CostCycleId = table.Column(type: "uniqueidentifier", nullable: false), UnitId = table.Column(type: "uniqueidentifier", nullable: false), TransactionId = table.Column(type: "int", nullable: true), Date = table.Column(type: "date", nullable: false), InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 28, 45, 625, DateTimeKind.Local).AddTicks(9764)), IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), RemoveTime = table.Column(type: "datetime2", nullable: true), UpdateTime = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UnitCosts", x => x.Id); table.ForeignKey( name: "FK_UnitCosts_CostCycles_CostCycleId", column: x => x.CostCycleId, principalTable: "CostCycles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UnitCosts_Units_UnitId", column: x => x.UnitId, principalTable: "Units", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Transactions", columns: table => new { Id = table.Column(type: "bigint", nullable: false), TransactionTitleId = table.Column(type: "int", nullable: true), TransactionPersianDate = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false), TransactionDate = table.Column(type: "datetime2", nullable: false), Amount = table.Column(type: "bigint", nullable: false), Description = table.Column(type: "nvarchar(max)", nullable: true), CostCycleId = table.Column(type: "uniqueidentifier", nullable: true), UnitId = table.Column(type: "uniqueidentifier", nullable: true), FicheId = table.Column(type: "nvarchar(max)", nullable: true), ComplexId = table.Column(type: "uniqueidentifier", nullable: false), UnitCostId = table.Column(type: "bigint", nullable: false), PersonId = table.Column(type: "nvarchar(450)", nullable: false), InsertTime = table.Column(type: "datetime2", nullable: false, defaultValue: new DateTime(2026, 6, 9, 2, 28, 45, 625, DateTimeKind.Local).AddTicks(3921)), IsRemoved = table.Column(type: "bit", nullable: false, defaultValue: false), RemoveTime = table.Column(type: "datetime2", nullable: true), UpdateTime = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Transactions", x => x.Id); table.ForeignKey( name: "FK_Transactions_CostCycles_CostCycleId", column: x => x.CostCycleId, principalTable: "CostCycles", principalColumn: "Id"); table.ForeignKey( name: "FK_Transactions_IncomeCostTitles_TransactionTitleId", column: x => x.TransactionTitleId, principalTable: "IncomeCostTitles", principalColumn: "Id"); table.ForeignKey( name: "FK_Transactions_Persons_PersonId", column: x => x.PersonId, principalTable: "Persons", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Transactions_UnitCosts_UnitCostId", column: x => x.UnitCostId, principalTable: "UnitCosts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Transactions_Units_UnitId", column: x => x.UnitId, principalTable: "Units", principalColumn: "Id"); }); migrationBuilder.CreateIndex( name: "IX_Cities_ProvinceId", table: "Cities", column: "ProvinceId"); migrationBuilder.CreateIndex( name: "IX_ComplexEntities_CityId", table: "ComplexEntities", column: "CityId"); migrationBuilder.CreateIndex( name: "IX_ComplexEntities_ParentId", table: "ComplexEntities", column: "ParentId"); migrationBuilder.CreateIndex( name: "IX_ComplexManagers_ComplexId", table: "ComplexManagers", column: "ComplexId"); migrationBuilder.CreateIndex( name: "IX_ComplexManagers_ManagerMobileNumberId", table: "ComplexManagers", column: "ManagerMobileNumberId"); migrationBuilder.CreateIndex( name: "IX_ComplexPersons_PersonMobileNumberId", table: "ComplexPersons", column: "PersonMobileNumberId"); migrationBuilder.CreateIndex( name: "IX_CostCycles_ComplexId", table: "CostCycles", column: "ComplexId"); migrationBuilder.CreateIndex( name: "IX_CostCycles_IncomeCostTitleId", table: "CostCycles", column: "IncomeCostTitleId"); migrationBuilder.CreateIndex( name: "IX_CostCycleUnit_UnitsId", table: "CostCycleUnit", column: "UnitsId"); migrationBuilder.CreateIndex( name: "IX_IncomeCostTitles_ComplexId", table: "IncomeCostTitles", column: "ComplexId"); migrationBuilder.CreateIndex( name: "IX_IncomeCostTitles_TransactionTypeId", table: "IncomeCostTitles", column: "TransactionTypeId"); migrationBuilder.CreateIndex( name: "IX_Transactions_CostCycleId", table: "Transactions", column: "CostCycleId"); migrationBuilder.CreateIndex( name: "IX_Transactions_PersonId", table: "Transactions", column: "PersonId"); migrationBuilder.CreateIndex( name: "IX_Transactions_TransactionTitleId", table: "Transactions", column: "TransactionTitleId"); migrationBuilder.CreateIndex( name: "IX_Transactions_UnitCostId", table: "Transactions", column: "UnitCostId", unique: true); migrationBuilder.CreateIndex( name: "IX_Transactions_UnitId", table: "Transactions", column: "UnitId"); migrationBuilder.CreateIndex( name: "IX_UnitCosts_CostCycleId", table: "UnitCosts", column: "CostCycleId"); migrationBuilder.CreateIndex( name: "IX_UnitCosts_UnitId", table: "UnitCosts", column: "UnitId"); migrationBuilder.CreateIndex( name: "IX_Units_ComplexId", table: "Units", column: "ComplexId"); migrationBuilder.CreateIndex( name: "IX_Units_OwnerId", table: "Units", column: "OwnerId"); migrationBuilder.CreateIndex( name: "IX_Units_StateId", table: "Units", column: "StateId"); migrationBuilder.CreateIndex( name: "IX_Units_TenantId", table: "Units", column: "TenantId"); migrationBuilder.CreateIndex( name: "IX_UserTokens_PersonId", table: "UserTokens", column: "PersonId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Chats"); migrationBuilder.DropTable( name: "ComplexManagers"); migrationBuilder.DropTable( name: "ComplexPersons"); migrationBuilder.DropTable( name: "ComplexUnitEvents"); migrationBuilder.DropTable( name: "CostCycleUnit"); migrationBuilder.DropTable( name: "Posters"); migrationBuilder.DropTable( name: "SmsCodes"); migrationBuilder.DropTable( name: "Transactions"); migrationBuilder.DropTable( name: "UserTokens"); migrationBuilder.DropTable( name: "UnitCosts"); migrationBuilder.DropTable( name: "CostCycles"); migrationBuilder.DropTable( name: "Units"); migrationBuilder.DropTable( name: "IncomeCostTitles"); migrationBuilder.DropTable( name: "Persons"); migrationBuilder.DropTable( name: "UnitStates"); migrationBuilder.DropTable( name: "BasicTables"); migrationBuilder.DropTable( name: "ComplexEntities"); migrationBuilder.DropTable( name: "Cities"); migrationBuilder.DropTable( name: "Provinces"); } } }