using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace Vanguard.Server.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "booster_openings", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), IdempotencyKey = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), Payment = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), CardsJson = table.Column(type: "text", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_booster_openings", x => x.Id); }); migrationBuilder.CreateTable( name: "collection", columns: table => new { UserId = table.Column(type: "uuid", nullable: false), PrintingId = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), Count = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_collection", x => new { x.UserId, x.PrintingId }); }); migrationBuilder.CreateTable( name: "decks", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Format = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), CardsJson = table.Column(type: "text", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), ShareCode = table.Column(type: "character varying(16)", maxLength: 16, nullable: true) }, constraints: table => { table.PrimaryKey("PK_decks", x => x.Id); }); migrationBuilder.CreateTable( name: "match_history", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), MatchId = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Mode = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), OpponentName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Result = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), Gold = table.Column(type: "integer", nullable: false), Xp = table.Column(type: "integer", nullable: false), MmrBefore = table.Column(type: "integer", nullable: false), MmrAfter = table.Column(type: "integer", nullable: false), FinishReason = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_match_history", x => x.Id); }); migrationBuilder.CreateTable( name: "match_intents", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), MatchId = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), IntentId = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Seat = table.Column(type: "integer", nullable: false), Command = table.Column(type: "text", nullable: false), Accepted = table.Column(type: "boolean", nullable: false), Code = table.Column(type: "integer", nullable: false), Reason = table.Column(type: "text", nullable: true), EventSeq = table.Column(type: "bigint", nullable: false) }, constraints: table => { table.PrimaryKey("PK_match_intents", x => x.Id); }); migrationBuilder.CreateTable( name: "matches", columns: table => new { MatchId = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Mode = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), Player0Id = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Player1Id = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Deck0Json = table.Column(type: "text", nullable: false), Deck1Json = table.Column(type: "text", nullable: false), Seed = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), Started = table.Column(type: "boolean", nullable: false), Bank0Ms = table.Column(type: "bigint", nullable: false), Bank1Ms = table.Column(type: "bigint", nullable: false), TurnDeadline = table.Column(type: "timestamp with time zone", nullable: true), AbsentSince0 = table.Column(type: "timestamp with time zone", nullable: true), AbsentSince1 = table.Column(type: "timestamp with time zone", nullable: true), LastClockSent = table.Column(type: "timestamp with time zone", nullable: false), IsFinished = table.Column(type: "boolean", nullable: false), Winner = table.Column(type: "integer", nullable: false), FinishedAt = table.Column(type: "timestamp with time zone", nullable: true), FinishReason = table.Column(type: "text", nullable: false), EventSeq = table.Column(type: "bigint", nullable: false) }, constraints: table => { table.PrimaryKey("PK_matches", x => x.MatchId); }); migrationBuilder.CreateTable( name: "refresh_tokens", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), TokenHash = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), ExpiresAt = table.Column(type: "timestamp with time zone", nullable: false), RevokedAt = table.Column(type: "timestamp with time zone", nullable: true), ReplacedByHash = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_refresh_tokens", x => x.Id); }); migrationBuilder.CreateTable( name: "transactions", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), Currency = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), Amount = table.Column(type: "integer", nullable: false), Reason = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), IdempotencyKey = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), MetadataJson = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_transactions", x => x.Id); }); migrationBuilder.CreateTable( name: "trial_deck_ownership", columns: table => new { UserId = table.Column(type: "uuid", nullable: false), DeckId = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), AcquiredAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_trial_deck_ownership", x => new { x.UserId, x.DeckId }); }); migrationBuilder.CreateTable( name: "users", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), NormalizedUserName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), PasswordHash = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), LastLoginAt = table.Column(type: "timestamp with time zone", nullable: true), OnboardingCompleted = table.Column(type: "boolean", nullable: false), SelectedTrialDeckId = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), RankedMmr = table.Column(type: "integer", nullable: false), CasualMmr = table.Column(type: "integer", nullable: false), Matches = table.Column(type: "integer", nullable: false), Wins = table.Column(type: "integer", nullable: false), Xp = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_users", x => x.Id); }); migrationBuilder.CreateIndex( name: "IX_booster_openings_UserId_IdempotencyKey", table: "booster_openings", columns: new[] { "UserId", "IdempotencyKey" }, unique: true); migrationBuilder.CreateIndex( name: "IX_collection_UserId", table: "collection", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_decks_ShareCode", table: "decks", column: "ShareCode", unique: true); migrationBuilder.CreateIndex( name: "IX_decks_UserId", table: "decks", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_decks_UserId_Name", table: "decks", columns: new[] { "UserId", "Name" }, unique: true); migrationBuilder.CreateIndex( name: "IX_match_history_UserId_CreatedAt", table: "match_history", columns: new[] { "UserId", "CreatedAt" }); migrationBuilder.CreateIndex( name: "IX_match_history_UserId_MatchId", table: "match_history", columns: new[] { "UserId", "MatchId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_match_intents_MatchId", table: "match_intents", column: "MatchId"); migrationBuilder.CreateIndex( name: "IX_matches_IsFinished_UpdatedAt", table: "matches", columns: new[] { "IsFinished", "UpdatedAt" }); migrationBuilder.CreateIndex( name: "IX_refresh_tokens_TokenHash", table: "refresh_tokens", column: "TokenHash", unique: true); migrationBuilder.CreateIndex( name: "IX_refresh_tokens_UserId", table: "refresh_tokens", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_transactions_UserId_Currency", table: "transactions", columns: new[] { "UserId", "Currency" }); migrationBuilder.CreateIndex( name: "IX_transactions_UserId_IdempotencyKey", table: "transactions", columns: new[] { "UserId", "IdempotencyKey" }, unique: true); migrationBuilder.CreateIndex( name: "IX_users_NormalizedUserName", table: "users", column: "NormalizedUserName", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "booster_openings"); migrationBuilder.DropTable( name: "collection"); migrationBuilder.DropTable( name: "decks"); migrationBuilder.DropTable( name: "match_history"); migrationBuilder.DropTable( name: "match_intents"); migrationBuilder.DropTable( name: "matches"); migrationBuilder.DropTable( name: "refresh_tokens"); migrationBuilder.DropTable( name: "transactions"); migrationBuilder.DropTable( name: "trial_deck_ownership"); migrationBuilder.DropTable( name: "users"); } } }