using System; using Microsoft.EntityFrameworkCore.Migrations; namespace TicketManager.Migrations { public partial class Migration1 : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "AppUsers", columns: table => new { Id = table.Column(nullable: false), FirstName = table.Column(maxLength: 50, nullable: false), LastName = table.Column(maxLength: 50, nullable: false), Presentation = table.Column(maxLength: 200, nullable: true), Email = table.Column(nullable: true), Phone = table.Column(nullable: true), CreationDate = table.Column(nullable: false), Picture = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_AppUsers", x => x.Id); }); migrationBuilder.CreateTable( name: "Projects", columns: table => new { Id = table.Column(nullable: false) .Annotation("Sqlite:Autoincrement", true), Title = table.Column(maxLength: 50, nullable: false), Description = table.Column(maxLength: 200, nullable: true), CreationDate = table.Column(nullable: false), EndingDate = table.Column(nullable: false), Status = table.Column(nullable: false), ManagerId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Projects", x => x.Id); table.ForeignKey( name: "FK_Projects_AppUsers_ManagerId", column: x => x.ManagerId, principalTable: "AppUsers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Assignments", columns: table => new { UserId = table.Column(nullable: false), ProjectId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Assignments", x => new { x.ProjectId, x.UserId }); table.ForeignKey( name: "FK_Assignments_Projects_ProjectId", column: x => x.ProjectId, principalTable: "Projects", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Assignments_AppUsers_UserId", column: x => x.UserId, principalTable: "AppUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Tickets", columns: table => new { Id = table.Column(nullable: false) .Annotation("Sqlite:Autoincrement", true), Title = table.Column(maxLength: 100, nullable: false), Description = table.Column(maxLength: 100, nullable: true), CreationDate = table.Column(nullable: false), EndingDate = table.Column(nullable: false), Status = table.Column(nullable: false), Impact = table.Column(nullable: false), Difficulty = table.Column(nullable: false), Category = table.Column(nullable: false), CreatorId = table.Column(nullable: false), ProjectId = table.Column(nullable: true), AppUserId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Tickets", x => x.Id); table.ForeignKey( name: "FK_Tickets_AppUsers_AppUserId", column: x => x.AppUserId, principalTable: "AppUsers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Tickets_Projects_ProjectId", column: x => x.ProjectId, principalTable: "Projects", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Activities", columns: table => new { Id = table.Column(nullable: false) .Annotation("Sqlite:Autoincrement", true), Description = table.Column(nullable: true), UpdateDate = table.Column(nullable: false), ActivityType = table.Column(nullable: false), TaskId = table.Column(nullable: false), AppUserId = table.Column(nullable: true), ProjectId = table.Column(nullable: true), TicketId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Activities", x => x.Id); table.ForeignKey( name: "FK_Activities_AppUsers_AppUserId", column: x => x.AppUserId, principalTable: "AppUsers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Activities_Projects_ProjectId", column: x => x.ProjectId, principalTable: "Projects", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Activities_Tickets_TicketId", column: x => x.TicketId, principalTable: "Tickets", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Files", columns: table => new { Id = table.Column(nullable: false) .Annotation("Sqlite:Autoincrement", true), FileName = table.Column(nullable: true), Location = table.Column(nullable: true), Description = table.Column(nullable: true), Size = table.Column(nullable: false), Format = table.Column(nullable: true), AddedById = table.Column(nullable: true), UserId = table.Column(nullable: false), ProjectId = table.Column(nullable: true), TicketId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Files", x => x.Id); table.ForeignKey( name: "FK_Files_AppUsers_AddedById", column: x => x.AddedById, principalTable: "AppUsers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Files_Projects_ProjectId", column: x => x.ProjectId, principalTable: "Projects", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Files_Tickets_TicketId", column: x => x.TicketId, principalTable: "Tickets", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Notes", columns: table => new { Id = table.Column(nullable: false) .Annotation("Sqlite:Autoincrement", true), Title = table.Column(nullable: true), Description = table.Column(nullable: true), CreationDate = table.Column(nullable: false), TicketId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Notes", x => x.Id); table.ForeignKey( name: "FK_Notes_Tickets_TicketId", column: x => x.TicketId, principalTable: "Tickets", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_Activities_AppUserId", table: "Activities", column: "AppUserId"); migrationBuilder.CreateIndex( name: "IX_Activities_ProjectId", table: "Activities", column: "ProjectId"); migrationBuilder.CreateIndex( name: "IX_Activities_TicketId", table: "Activities", column: "TicketId"); migrationBuilder.CreateIndex( name: "IX_Assignments_UserId", table: "Assignments", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Files_AddedById", table: "Files", column: "AddedById"); migrationBuilder.CreateIndex( name: "IX_Files_ProjectId", table: "Files", column: "ProjectId"); migrationBuilder.CreateIndex( name: "IX_Files_TicketId", table: "Files", column: "TicketId"); migrationBuilder.CreateIndex( name: "IX_Notes_TicketId", table: "Notes", column: "TicketId"); migrationBuilder.CreateIndex( name: "IX_Projects_ManagerId", table: "Projects", column: "ManagerId"); migrationBuilder.CreateIndex( name: "IX_Tickets_AppUserId", table: "Tickets", column: "AppUserId"); migrationBuilder.CreateIndex( name: "IX_Tickets_ProjectId", table: "Tickets", column: "ProjectId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Activities"); migrationBuilder.DropTable( name: "Assignments"); migrationBuilder.DropTable( name: "Files"); migrationBuilder.DropTable( name: "Notes"); migrationBuilder.DropTable( name: "Tickets"); migrationBuilder.DropTable( name: "Projects"); migrationBuilder.DropTable( name: "AppUsers"); } } }