using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace RacePlannerApi.Data.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Email = table.Column(type: "text", nullable: false), PasswordHash = table.Column(type: "text", nullable: false), Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), Role = table.Column(type: "text", nullable: false), CreatedAt = table.Column(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(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: false), EventDate = table.Column(type: "timestamp with time zone", nullable: false), Location = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), Status = table.Column(type: "text", nullable: false), Category = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), Tags = table.Column>(type: "text[]", nullable: false), MaxParticipants = table.Column(type: "integer", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), OrganizerId = table.Column(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(type: "uuid", nullable: false), Title = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Content = table.Column(type: "character varying(5000)", maxLength: 5000, nullable: false), EventId = table.Column(type: "uuid", nullable: false), AuthorId = 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: true), IsPublished = table.Column(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(type: "uuid", nullable: false), EventId = table.Column(type: "uuid", nullable: false), ParticipantId = table.Column(type: "uuid", nullable: false), Status = table.Column(type: "text", nullable: false), Category = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), EmergencyContact = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(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(type: "uuid", nullable: false), RegistrationId = table.Column(type: "uuid", nullable: false), Amount = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), Method = table.Column(type: "text", nullable: false), TransactionId = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), Notes = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), PaymentDate = table.Column(type: "timestamp with time zone", nullable: false), CreatedAt = table.Column(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); } /// 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"); } } }