auto.bus_api/Server/Migrations/20221124184433_Add_TicketGroups.cs
2022-11-27 16:08:33 +02:00

130 lines
4.3 KiB
C#

using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Server.Migrations
{
public partial class Add_TicketGroups : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Tickets_AspNetUsers_UserId",
table: "Tickets");
migrationBuilder.DropIndex(
name: "IX_Tickets_UserId",
table: "Tickets");
migrationBuilder.DropColumn(
name: "UserId",
table: "Tickets");
migrationBuilder.AddColumn<int>(
name: "FirstRouteAddressId",
table: "Tickets",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "LastRouteAddressId",
table: "Tickets",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "TicketGroupId",
table: "Tickets",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateTable(
name: "TicketGroups",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TicketGroups", x => x.Id);
table.ForeignKey(
name: "FK_TicketGroups_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Tickets_TicketGroupId",
table: "Tickets",
column: "TicketGroupId");
migrationBuilder.CreateIndex(
name: "IX_TicketGroups_UserId",
table: "TicketGroups",
column: "UserId");
migrationBuilder.AddForeignKey(
name: "FK_Tickets_TicketGroups_TicketGroupId",
table: "Tickets",
column: "TicketGroupId",
principalTable: "TicketGroups",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Tickets_TicketGroups_TicketGroupId",
table: "Tickets");
migrationBuilder.DropTable(
name: "TicketGroups");
migrationBuilder.DropIndex(
name: "IX_Tickets_TicketGroupId",
table: "Tickets");
migrationBuilder.DropColumn(
name: "FirstRouteAddressId",
table: "Tickets");
migrationBuilder.DropColumn(
name: "LastRouteAddressId",
table: "Tickets");
migrationBuilder.DropColumn(
name: "TicketGroupId",
table: "Tickets");
migrationBuilder.AddColumn<string>(
name: "UserId",
table: "Tickets",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.CreateIndex(
name: "IX_Tickets_UserId",
table: "Tickets",
column: "UserId");
migrationBuilder.AddForeignKey(
name: "FK_Tickets_AspNetUsers_UserId",
table: "Tickets",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}