Files

231 lines
10 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace RacePlannerApi.Data.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
PasswordHash = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
Role = table.Column<string>(type: "text", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Events",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
Description = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: false),
EventDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Location = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
Status = table.Column<string>(type: "text", nullable: false),
Category = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
Tags = table.Column<List<string>>(type: "text[]", nullable: false),
MaxParticipants = table.Column<int>(type: "integer", nullable: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
OrganizerId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Events", x => x.Id);
table.ForeignKey(
name: "FK_Events_Users_OrganizerId",
column: x => x.OrganizerId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Announcements",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Title = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
Content = table.Column<string>(type: "character varying(5000)", maxLength: 5000, nullable: false),
EventId = table.Column<Guid>(type: "uuid", nullable: false),
AuthorId = table.Column<Guid>(type: "uuid", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
IsPublished = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Announcements", x => x.Id);
table.ForeignKey(
name: "FK_Announcements_Events_EventId",
column: x => x.EventId,
principalTable: "Events",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Announcements_Users_AuthorId",
column: x => x.AuthorId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Registrations",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
EventId = table.Column<Guid>(type: "uuid", nullable: false),
ParticipantId = table.Column<Guid>(type: "uuid", nullable: false),
Status = table.Column<string>(type: "text", nullable: false),
Category = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
EmergencyContact = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Registrations", x => x.Id);
table.ForeignKey(
name: "FK_Registrations_Events_EventId",
column: x => x.EventId,
principalTable: "Events",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Registrations_Users_ParticipantId",
column: x => x.ParticipantId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Payments",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
RegistrationId = table.Column<Guid>(type: "uuid", nullable: false),
Amount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
Method = table.Column<string>(type: "text", nullable: false),
TransactionId = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
Notes = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
PaymentDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Payments", x => x.Id);
table.ForeignKey(
name: "FK_Payments_Registrations_RegistrationId",
column: x => x.RegistrationId,
principalTable: "Registrations",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Announcements_AuthorId",
table: "Announcements",
column: "AuthorId");
migrationBuilder.CreateIndex(
name: "IX_Announcements_CreatedAt",
table: "Announcements",
column: "CreatedAt");
migrationBuilder.CreateIndex(
name: "IX_Announcements_EventId",
table: "Announcements",
column: "EventId");
migrationBuilder.CreateIndex(
name: "IX_Events_Category",
table: "Events",
column: "Category");
migrationBuilder.CreateIndex(
name: "IX_Events_EventDate",
table: "Events",
column: "EventDate");
migrationBuilder.CreateIndex(
name: "IX_Events_OrganizerId",
table: "Events",
column: "OrganizerId");
migrationBuilder.CreateIndex(
name: "IX_Events_Status",
table: "Events",
column: "Status");
migrationBuilder.CreateIndex(
name: "IX_Payments_PaymentDate",
table: "Payments",
column: "PaymentDate");
migrationBuilder.CreateIndex(
name: "IX_Payments_RegistrationId",
table: "Payments",
column: "RegistrationId");
migrationBuilder.CreateIndex(
name: "IX_Registrations_EventId_ParticipantId",
table: "Registrations",
columns: new[] { "EventId", "ParticipantId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Registrations_ParticipantId",
table: "Registrations",
column: "ParticipantId");
migrationBuilder.CreateIndex(
name: "IX_Registrations_Status",
table: "Registrations",
column: "Status");
migrationBuilder.CreateIndex(
name: "IX_Users_Email",
table: "Users",
column: "Email",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Announcements");
migrationBuilder.DropTable(
name: "Payments");
migrationBuilder.DropTable(
name: "Registrations");
migrationBuilder.DropTable(
name: "Events");
migrationBuilder.DropTable(
name: "Users");
}
}
}