319 lines
16 KiB
C#
319 lines
16 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
|
|
#nullable disable
|
|
|
|
namespace Vanguard.Server.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitialCreate : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "booster_openings",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
IdempotencyKey = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
|
Payment = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
|
|
CardsJson = table.Column<string>(type: "text", nullable: false),
|
|
CreatedAt = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false),
|
|
PrintingId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
Count = table.Column<int>(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<Guid>(type: "uuid", nullable: false),
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Name = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
Format = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
CardsJson = table.Column<string>(type: "text", nullable: false),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
ShareCode = table.Column<string>(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<Guid>(type: "uuid", nullable: false),
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
MatchId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
Mode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
OpponentName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
Result = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
|
|
Gold = table.Column<int>(type: "integer", nullable: false),
|
|
Xp = table.Column<int>(type: "integer", nullable: false),
|
|
MmrBefore = table.Column<int>(type: "integer", nullable: false),
|
|
MmrAfter = table.Column<int>(type: "integer", nullable: false),
|
|
FinishReason = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
|
|
CreatedAt = table.Column<DateTimeOffset>(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<long>(type: "bigint", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
MatchId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
IntentId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
Seat = table.Column<int>(type: "integer", nullable: false),
|
|
Command = table.Column<string>(type: "text", nullable: false),
|
|
Accepted = table.Column<bool>(type: "boolean", nullable: false),
|
|
Code = table.Column<int>(type: "integer", nullable: false),
|
|
Reason = table.Column<string>(type: "text", nullable: true),
|
|
EventSeq = table.Column<long>(type: "bigint", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_match_intents", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "matches",
|
|
columns: table => new
|
|
{
|
|
MatchId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
Mode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
Player0Id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
Player1Id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
Deck0Json = table.Column<string>(type: "text", nullable: false),
|
|
Deck1Json = table.Column<string>(type: "text", nullable: false),
|
|
Seed = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
Started = table.Column<bool>(type: "boolean", nullable: false),
|
|
Bank0Ms = table.Column<long>(type: "bigint", nullable: false),
|
|
Bank1Ms = table.Column<long>(type: "bigint", nullable: false),
|
|
TurnDeadline = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
AbsentSince0 = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
AbsentSince1 = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
LastClockSent = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
IsFinished = table.Column<bool>(type: "boolean", nullable: false),
|
|
Winner = table.Column<int>(type: "integer", nullable: false),
|
|
FinishedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
FinishReason = table.Column<string>(type: "text", nullable: false),
|
|
EventSeq = table.Column<long>(type: "bigint", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_matches", x => x.MatchId);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "refresh_tokens",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
TokenHash = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
ExpiresAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
RevokedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
ReplacedByHash = table.Column<string>(type: "text", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_refresh_tokens", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "transactions",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Currency = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
|
|
Amount = table.Column<int>(type: "integer", nullable: false),
|
|
Reason = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
IdempotencyKey = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
MetadataJson = table.Column<string>(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<Guid>(type: "uuid", nullable: false),
|
|
DeckId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
AcquiredAt = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false),
|
|
UserName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
NormalizedUserName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
PasswordHash = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
LastLoginAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
OnboardingCompleted = table.Column<bool>(type: "boolean", nullable: false),
|
|
SelectedTrialDeckId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
RankedMmr = table.Column<int>(type: "integer", nullable: false),
|
|
CasualMmr = table.Column<int>(type: "integer", nullable: false),
|
|
Matches = table.Column<int>(type: "integer", nullable: false),
|
|
Wins = table.Column<int>(type: "integer", nullable: false),
|
|
Xp = table.Column<int>(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);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
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");
|
|
}
|
|
}
|
|
}
|