using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace mws.backend.dotnet.infrastructure.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "documents", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ProjectId = table.Column(type: "uuid", nullable: false), ParentId = table.Column(type: "uuid", nullable: true), Title = table.Column(type: "character varying(300)", maxLength: 300, nullable: false), Type = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), ContentHash = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), ContentSize = table.Column(type: "bigint", nullable: true), UpdatedContentAt = table.Column(type: "timestamp with time zone", nullable: true), CreatedBy = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedBy = table.Column(type: "uuid", nullable: true), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_documents", x => x.Id); table.ForeignKey( name: "FK_documents_documents_ParentId", column: x => x.ParentId, principalTable: "documents", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "master_data", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Group = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), Label = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Value = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), SortOrder = table.Column(type: "integer", nullable: false), IsActive = table.Column(type: "boolean", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_master_data", x => x.Id); }); migrationBuilder.CreateTable( name: "roles", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), IsSystem = table.Column(type: "boolean", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_roles", x => x.Id); }); migrationBuilder.CreateTable( name: "users", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Username = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), PasswordHash = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), DisplayName = table.Column(type: "character varying(150)", maxLength: 150, nullable: false), IsActive = table.Column(type: "boolean", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_users", x => x.Id); }); migrationBuilder.CreateTable( name: "role_permissions", columns: table => new { RoleId = table.Column(type: "uuid", nullable: false), Screen = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), CanView = table.Column(type: "boolean", nullable: false), CanCreate = table.Column(type: "boolean", nullable: false), CanEdit = table.Column(type: "boolean", nullable: false), CanDelete = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_role_permissions", x => new { x.RoleId, x.Screen }); table.ForeignKey( name: "FK_role_permissions_roles_RoleId", column: x => x.RoleId, principalTable: "roles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "projects", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Description = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), Status = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), CreatedBy = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedBy = table.Column(type: "uuid", nullable: true), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_projects", x => x.Id); table.ForeignKey( name: "FK_projects_users_CreatedBy", column: x => x.CreatedBy, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_projects_users_UpdatedBy", column: x => x.UpdatedBy, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "tasks", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ProjectId = table.Column(type: "uuid", nullable: false), Title = table.Column(type: "character varying(300)", maxLength: 300, nullable: false), Description = table.Column(type: "text", nullable: true), Status = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), Priority = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), AssigneeId = table.Column(type: "uuid", nullable: true), DueDate = table.Column(type: "timestamp with time zone", nullable: true), CreatedBy = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_tasks", x => x.Id); table.ForeignKey( name: "FK_tasks_users_AssigneeId", column: x => x.AssigneeId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "user_roles", columns: table => new { UserId = table.Column(type: "uuid", nullable: false), RoleId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_user_roles", x => new { x.UserId, x.RoleId }); table.ForeignKey( name: "FK_user_roles_roles_RoleId", column: x => x.RoleId, principalTable: "roles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_user_roles_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "project_members", columns: table => new { ProjectId = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), Role = table.Column(type: "character varying(20)", maxLength: 20, nullable: false) }, constraints: table => { table.PrimaryKey("PK_project_members", x => new { x.ProjectId, x.UserId }); table.ForeignKey( name: "FK_project_members_projects_ProjectId", column: x => x.ProjectId, principalTable: "projects", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_project_members_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "project_member_permissions", columns: table => new { ProjectId = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), Screen = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), CanView = table.Column(type: "boolean", nullable: false), CanCreate = table.Column(type: "boolean", nullable: false), CanEdit = table.Column(type: "boolean", nullable: false), CanDelete = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_project_member_permissions", x => new { x.ProjectId, x.UserId, x.Screen }); table.ForeignKey( name: "FK_project_member_permissions_project_members_ProjectId_UserId", columns: x => new { x.ProjectId, x.UserId }, principalTable: "project_members", principalColumns: new[] { "ProjectId", "UserId" }, onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_documents_ParentId", table: "documents", column: "ParentId"); migrationBuilder.CreateIndex( name: "IX_documents_ProjectId_ParentId", table: "documents", columns: new[] { "ProjectId", "ParentId" }); migrationBuilder.CreateIndex( name: "IX_master_data_Group_Value", table: "master_data", columns: new[] { "Group", "Value" }, unique: true); migrationBuilder.CreateIndex( name: "IX_project_members_UserId", table: "project_members", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_projects_CreatedBy", table: "projects", column: "CreatedBy"); migrationBuilder.CreateIndex( name: "IX_projects_UpdatedBy", table: "projects", column: "UpdatedBy"); migrationBuilder.CreateIndex( name: "IX_roles_Name", table: "roles", column: "Name", unique: true); migrationBuilder.CreateIndex( name: "IX_tasks_AssigneeId", table: "tasks", column: "AssigneeId"); migrationBuilder.CreateIndex( name: "IX_tasks_ProjectId", table: "tasks", column: "ProjectId"); migrationBuilder.CreateIndex( name: "IX_tasks_Status", table: "tasks", column: "Status"); migrationBuilder.CreateIndex( name: "IX_user_roles_RoleId", table: "user_roles", column: "RoleId"); migrationBuilder.CreateIndex( name: "IX_users_Username", table: "users", column: "Username", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "documents"); migrationBuilder.DropTable( name: "master_data"); migrationBuilder.DropTable( name: "project_member_permissions"); migrationBuilder.DropTable( name: "role_permissions"); migrationBuilder.DropTable( name: "tasks"); migrationBuilder.DropTable( name: "user_roles"); migrationBuilder.DropTable( name: "project_members"); migrationBuilder.DropTable( name: "roles"); migrationBuilder.DropTable( name: "projects"); migrationBuilder.DropTable( name: "users"); } } }