using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace Brizco.Repository.Migrations { /// public partial class Init : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.EnsureSchema( name: "public"); migrationBuilder.CreateTable( name: "Complexes", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "text", nullable: false), Address = table.Column(type: "text", nullable: false), SupportPhone = table.Column(type: "text", nullable: false), RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedBy = table.Column(type: "text", nullable: false), IsRemoved = table.Column(type: "boolean", nullable: false), RemovedBy = table.Column(type: "text", nullable: false), ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), ModifiedBy = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Complexes", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), FirstName = table.Column(type: "text", nullable: false), LastName = table.Column(type: "text", nullable: false), BirthDate = table.Column(type: "timestamp without time zone", nullable: false), Gender = table.Column(type: "integer", nullable: false), SignUpStatus = table.Column(type: "integer", nullable: false), UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), EmailConfirmed = table.Column(type: "boolean", nullable: false), PasswordHash = table.Column(type: "text", nullable: true), SecurityStamp = table.Column(type: "text", nullable: true), ConcurrencyStamp = table.Column(type: "text", nullable: true), PhoneNumber = table.Column(type: "text", nullable: true), PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), TwoFactorEnabled = table.Column(type: "boolean", nullable: false), LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), LockoutEnabled = table.Column(type: "boolean", nullable: false), AccessFailedCount = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Roles", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Description = table.Column(type: "text", nullable: false), EnglishName = table.Column(type: "text", nullable: false), PersianName = table.Column(type: "text", nullable: false), ComplexId = table.Column(type: "uuid", nullable: true), Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), ConcurrencyStamp = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Roles", x => x.Id); table.ForeignKey( name: "FK_Roles_Complexes_ComplexId", column: x => x.ComplexId, principalSchema: "public", principalTable: "Complexes", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Shifts", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Title = table.Column(type: "text", nullable: false), StartAt = table.Column(type: "interval", nullable: false), EndAt = table.Column(type: "interval", nullable: false), Description = table.Column(type: "text", nullable: false), ComplexId = table.Column(type: "uuid", nullable: false), RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedBy = table.Column(type: "text", nullable: false), IsRemoved = table.Column(type: "boolean", nullable: false), RemovedBy = table.Column(type: "text", nullable: false), ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), ModifiedBy = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Shifts", x => x.Id); table.ForeignKey( name: "FK_Shifts_Complexes_ComplexId", column: x => x.ComplexId, principalSchema: "public", principalTable: "Complexes", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Tasks", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Type = table.Column(type: "integer", nullable: false), Title = table.Column(type: "text", nullable: false), Description = table.Column(type: "text", nullable: false), IsRelatedToShift = table.Column(type: "boolean", nullable: false), IsRelatedToRole = table.Column(type: "boolean", nullable: false), IsRelatedToPerson = table.Column(type: "boolean", nullable: false), IsDisposable = table.Column(type: "boolean", nullable: false), SetFor = table.Column(type: "timestamp without time zone", nullable: false), HasDisposed = table.Column(type: "boolean", nullable: false), ComplexId = table.Column(type: "uuid", nullable: false), Amount = table.Column(type: "integer", nullable: false), AmountType = table.Column(type: "integer", nullable: false), Discriminator = table.Column(type: "text", nullable: false), Status = table.Column(type: "integer", nullable: true), DoneAt = table.Column(type: "timestamp without time zone", nullable: true), IsDone = table.Column(type: "boolean", nullable: true), PerformanceDescription = table.Column(type: "text", nullable: true), RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedBy = table.Column(type: "text", nullable: false), IsRemoved = table.Column(type: "boolean", nullable: false), RemovedBy = table.Column(type: "text", nullable: false), ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), ModifiedBy = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tasks", x => x.Id); table.ForeignKey( name: "FK_Tasks_Complexes_ComplexId", column: x => x.ComplexId, principalSchema: "public", principalTable: "Complexes", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Claims", schema: "public", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "uuid", nullable: false), ClaimType = table.Column(type: "text", nullable: true), ClaimValue = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Claims", x => x.Id); table.ForeignKey( name: "FK_Claims_Users_UserId", column: x => x.UserId, principalSchema: "public", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Logins", schema: "public", columns: table => new { LoginProvider = table.Column(type: "text", nullable: false), ProviderKey = table.Column(type: "text", nullable: false), ProviderDisplayName = table.Column(type: "text", nullable: true), UserId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Logins", x => new { x.LoginProvider, x.ProviderKey }); table.ForeignKey( name: "FK_Logins_Users_UserId", column: x => x.UserId, principalSchema: "public", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Tokens", schema: "public", columns: table => new { UserId = table.Column(type: "uuid", nullable: false), LoginProvider = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: false), Value = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Tokens", x => new { x.UserId, x.LoginProvider, x.Name }); table.ForeignKey( name: "FK_Tokens_Users_UserId", column: x => x.UserId, principalSchema: "public", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "ComplexUsers", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), ComplexId = table.Column(type: "uuid", nullable: false), RoleId = table.Column(type: "uuid", nullable: false), RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedBy = table.Column(type: "text", nullable: false), IsRemoved = table.Column(type: "boolean", nullable: false), RemovedBy = table.Column(type: "text", nullable: false), ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), ModifiedBy = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ComplexUsers", x => x.Id); table.ForeignKey( name: "FK_ComplexUsers_Complexes_ComplexId", column: x => x.ComplexId, principalSchema: "public", principalTable: "Complexes", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_ComplexUsers_Roles_RoleId", column: x => x.RoleId, principalSchema: "public", principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_ComplexUsers_Users_UserId", column: x => x.UserId, principalSchema: "public", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "RoleClaims", schema: "public", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), RoleId = table.Column(type: "uuid", nullable: false), ClaimType = table.Column(type: "text", nullable: true), ClaimValue = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_RoleClaims", x => x.Id); table.ForeignKey( name: "FK_RoleClaims_Roles_RoleId", column: x => x.RoleId, principalSchema: "public", principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "UserRoles", schema: "public", columns: table => new { UserId = table.Column(type: "uuid", nullable: false), RoleId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId }); table.ForeignKey( name: "FK_UserRoles_Roles_RoleId", column: x => x.RoleId, principalSchema: "public", principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_UserRoles_Users_UserId", column: x => x.UserId, principalSchema: "public", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "ShiftDays", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), DayOfWeek = table.Column(type: "integer", nullable: false), ShiftId = table.Column(type: "uuid", nullable: false), RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedBy = table.Column(type: "text", nullable: false), IsRemoved = table.Column(type: "boolean", nullable: false), RemovedBy = table.Column(type: "text", nullable: false), ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), ModifiedBy = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ShiftDays", x => x.Id); table.ForeignKey( name: "FK_ShiftDays_Shifts_ShiftId", column: x => x.ShiftId, principalSchema: "public", principalTable: "Shifts", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "ShiftPlans", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), StartAt = table.Column(type: "timestamp without time zone", nullable: false), EndAt = table.Column(type: "timestamp without time zone", nullable: false), ShiftId = table.Column(type: "uuid", nullable: false), RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedBy = table.Column(type: "text", nullable: false), IsRemoved = table.Column(type: "boolean", nullable: false), RemovedBy = table.Column(type: "text", nullable: false), ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), ModifiedBy = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ShiftPlans", x => x.Id); table.ForeignKey( name: "FK_ShiftPlans_Shifts_ShiftId", column: x => x.ShiftId, principalSchema: "public", principalTable: "Shifts", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "TaskRoles", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), RoleId = table.Column(type: "uuid", nullable: false), TaskId = table.Column(type: "uuid", nullable: false), RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedBy = table.Column(type: "text", nullable: false), IsRemoved = table.Column(type: "boolean", nullable: false), RemovedBy = table.Column(type: "text", nullable: false), ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), ModifiedBy = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_TaskRoles", x => x.Id); table.ForeignKey( name: "FK_TaskRoles_Roles_RoleId", column: x => x.RoleId, principalSchema: "public", principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_TaskRoles_Tasks_TaskId", column: x => x.TaskId, principalSchema: "public", principalTable: "Tasks", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "TaskShifts", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), TaskId = table.Column(type: "uuid", nullable: false), ShiftId = table.Column(type: "uuid", nullable: false), RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedBy = table.Column(type: "text", nullable: false), IsRemoved = table.Column(type: "boolean", nullable: false), RemovedBy = table.Column(type: "text", nullable: false), ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), ModifiedBy = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_TaskShifts", x => x.Id); table.ForeignKey( name: "FK_TaskShifts_Shifts_ShiftId", column: x => x.ShiftId, principalSchema: "public", principalTable: "Shifts", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_TaskShifts_Tasks_TaskId", column: x => x.TaskId, principalSchema: "public", principalTable: "Tasks", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "TaskUsers", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), TaskId = table.Column(type: "uuid", nullable: false), RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedBy = table.Column(type: "text", nullable: false), IsRemoved = table.Column(type: "boolean", nullable: false), RemovedBy = table.Column(type: "text", nullable: false), ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), ModifiedBy = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_TaskUsers", x => x.Id); table.ForeignKey( name: "FK_TaskUsers_Tasks_TaskId", column: x => x.TaskId, principalSchema: "public", principalTable: "Tasks", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_TaskUsers_Users_UserId", column: x => x.UserId, principalSchema: "public", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "ShiftPlanUsers", schema: "public", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ShiftPlanId = table.Column(type: "uuid", nullable: false), ApplicationUserId = table.Column(type: "uuid", nullable: false), RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), CreatedBy = table.Column(type: "text", nullable: false), IsRemoved = table.Column(type: "boolean", nullable: false), RemovedBy = table.Column(type: "text", nullable: false), ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), ModifiedBy = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ShiftPlanUsers", x => x.Id); table.ForeignKey( name: "FK_ShiftPlanUsers_ShiftPlans_ShiftPlanId", column: x => x.ShiftPlanId, principalSchema: "public", principalTable: "ShiftPlans", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_ShiftPlanUsers_Users_ApplicationUserId", column: x => x.ApplicationUserId, principalSchema: "public", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_Claims_UserId", schema: "public", table: "Claims", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_ComplexUsers_ComplexId", schema: "public", table: "ComplexUsers", column: "ComplexId"); migrationBuilder.CreateIndex( name: "IX_ComplexUsers_RoleId", schema: "public", table: "ComplexUsers", column: "RoleId"); migrationBuilder.CreateIndex( name: "IX_ComplexUsers_UserId", schema: "public", table: "ComplexUsers", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Logins_UserId", schema: "public", table: "Logins", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_RoleClaims_RoleId", schema: "public", table: "RoleClaims", column: "RoleId"); migrationBuilder.CreateIndex( name: "IX_Roles_ComplexId", schema: "public", table: "Roles", column: "ComplexId"); migrationBuilder.CreateIndex( name: "RoleNameIndex", schema: "public", table: "Roles", column: "NormalizedName", unique: true); migrationBuilder.CreateIndex( name: "IX_ShiftDays_ShiftId", schema: "public", table: "ShiftDays", column: "ShiftId"); migrationBuilder.CreateIndex( name: "IX_ShiftPlans_ShiftId", schema: "public", table: "ShiftPlans", column: "ShiftId"); migrationBuilder.CreateIndex( name: "IX_ShiftPlanUsers_ApplicationUserId", schema: "public", table: "ShiftPlanUsers", column: "ApplicationUserId"); migrationBuilder.CreateIndex( name: "IX_ShiftPlanUsers_ShiftPlanId", schema: "public", table: "ShiftPlanUsers", column: "ShiftPlanId"); migrationBuilder.CreateIndex( name: "IX_Shifts_ComplexId", schema: "public", table: "Shifts", column: "ComplexId"); migrationBuilder.CreateIndex( name: "IX_TaskRoles_RoleId", schema: "public", table: "TaskRoles", column: "RoleId"); migrationBuilder.CreateIndex( name: "IX_TaskRoles_TaskId", schema: "public", table: "TaskRoles", column: "TaskId"); migrationBuilder.CreateIndex( name: "IX_Tasks_ComplexId", schema: "public", table: "Tasks", column: "ComplexId"); migrationBuilder.CreateIndex( name: "IX_TaskShifts_ShiftId", schema: "public", table: "TaskShifts", column: "ShiftId"); migrationBuilder.CreateIndex( name: "IX_TaskShifts_TaskId", schema: "public", table: "TaskShifts", column: "TaskId"); migrationBuilder.CreateIndex( name: "IX_TaskUsers_TaskId", schema: "public", table: "TaskUsers", column: "TaskId"); migrationBuilder.CreateIndex( name: "IX_TaskUsers_UserId", schema: "public", table: "TaskUsers", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_UserRoles_RoleId", schema: "public", table: "UserRoles", column: "RoleId"); migrationBuilder.CreateIndex( name: "EmailIndex", schema: "public", table: "Users", column: "NormalizedEmail"); migrationBuilder.CreateIndex( name: "UserNameIndex", schema: "public", table: "Users", column: "NormalizedUserName", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Claims", schema: "public"); migrationBuilder.DropTable( name: "ComplexUsers", schema: "public"); migrationBuilder.DropTable( name: "Logins", schema: "public"); migrationBuilder.DropTable( name: "RoleClaims", schema: "public"); migrationBuilder.DropTable( name: "ShiftDays", schema: "public"); migrationBuilder.DropTable( name: "ShiftPlanUsers", schema: "public"); migrationBuilder.DropTable( name: "TaskRoles", schema: "public"); migrationBuilder.DropTable( name: "TaskShifts", schema: "public"); migrationBuilder.DropTable( name: "TaskUsers", schema: "public"); migrationBuilder.DropTable( name: "Tokens", schema: "public"); migrationBuilder.DropTable( name: "UserRoles", schema: "public"); migrationBuilder.DropTable( name: "ShiftPlans", schema: "public"); migrationBuilder.DropTable( name: "Tasks", schema: "public"); migrationBuilder.DropTable( name: "Roles", schema: "public"); migrationBuilder.DropTable( name: "Users", schema: "public"); migrationBuilder.DropTable( name: "Shifts", schema: "public"); migrationBuilder.DropTable( name: "Complexes", schema: "public"); } } }