using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace WebApp.Migrations { /// public partial class EventSkillsUsersOrganisations : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.RenameColumn( name: "Place", table: "Events", newName: "Location"); migrationBuilder.RenameColumn( name: "Name", table: "Events", newName: "Title"); migrationBuilder.RenameColumn( name: "Date", table: "Events", newName: "EventDate"); migrationBuilder.RenameColumn( name: "Id", table: "Events", newName: "EventId"); migrationBuilder.AddColumn( name: "OrganisationId", table: "Events", type: "integer", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "CreatedAt", table: "AspNetUsers", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "FirstName", table: "AspNetUsers", type: "text", nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "IsOrganisation", table: "AspNetUsers", type: "boolean", nullable: false, defaultValue: false); migrationBuilder.AddColumn( name: "LastName", table: "AspNetUsers", type: "text", nullable: false, defaultValue: ""); migrationBuilder.CreateTable( name: "EventRegistrations", columns: table => new { EventId = table.Column(type: "integer", nullable: false), UserId = table.Column(type: "text", nullable: false), RegisteredAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_EventRegistrations", x => new { x.UserId, x.EventId }); table.ForeignKey( name: "FK_EventRegistrations_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_EventRegistrations_Events_EventId", column: x => x.EventId, principalTable: "Events", principalColumn: "EventId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Organisations", columns: table => new { OrganisationId = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: false), Description = table.Column(type: "text", nullable: true), Website = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Organisations", x => x.OrganisationId); table.ForeignKey( name: "FK_Organisations_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Skills", columns: table => new { SkillId = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Skills", x => x.SkillId); }); migrationBuilder.CreateTable( name: "EventSkills", columns: table => new { EventId = table.Column(type: "integer", nullable: false), SkillId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_EventSkills", x => new { x.EventId, x.SkillId }); table.ForeignKey( name: "FK_EventSkills_Events_EventId", column: x => x.EventId, principalTable: "Events", principalColumn: "EventId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_EventSkills_Skills_SkillId", column: x => x.SkillId, principalTable: "Skills", principalColumn: "SkillId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "VolunteerSkills", columns: table => new { UserId = table.Column(type: "text", nullable: false), SkillId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_VolunteerSkills", x => new { x.UserId, x.SkillId }); table.ForeignKey( name: "FK_VolunteerSkills_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_VolunteerSkills_Skills_SkillId", column: x => x.SkillId, principalTable: "Skills", principalColumn: "SkillId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Events_OrganisationId", table: "Events", column: "OrganisationId"); migrationBuilder.CreateIndex( name: "IX_EventRegistrations_EventId", table: "EventRegistrations", column: "EventId"); migrationBuilder.CreateIndex( name: "IX_EventSkills_SkillId", table: "EventSkills", column: "SkillId"); migrationBuilder.CreateIndex( name: "IX_Organisations_UserId", table: "Organisations", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_VolunteerSkills_SkillId", table: "VolunteerSkills", column: "SkillId"); migrationBuilder.AddForeignKey( name: "FK_Events_Organisations_OrganisationId", table: "Events", column: "OrganisationId", principalTable: "Organisations", principalColumn: "OrganisationId", onDelete: ReferentialAction.Cascade); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Events_Organisations_OrganisationId", table: "Events"); migrationBuilder.DropTable( name: "EventRegistrations"); migrationBuilder.DropTable( name: "EventSkills"); migrationBuilder.DropTable( name: "Organisations"); migrationBuilder.DropTable( name: "VolunteerSkills"); migrationBuilder.DropTable( name: "Skills"); migrationBuilder.DropIndex( name: "IX_Events_OrganisationId", table: "Events"); migrationBuilder.DropColumn( name: "OrganisationId", table: "Events"); migrationBuilder.DropColumn( name: "CreatedAt", table: "AspNetUsers"); migrationBuilder.DropColumn( name: "FirstName", table: "AspNetUsers"); migrationBuilder.DropColumn( name: "IsOrganisation", table: "AspNetUsers"); migrationBuilder.DropColumn( name: "LastName", table: "AspNetUsers"); migrationBuilder.RenameColumn( name: "Title", table: "Events", newName: "Name"); migrationBuilder.RenameColumn( name: "Location", table: "Events", newName: "Place"); migrationBuilder.RenameColumn( name: "EventDate", table: "Events", newName: "Date"); migrationBuilder.RenameColumn( name: "EventId", table: "Events", newName: "Id"); } } }