355 lines
16 KiB
C#
355 lines
16 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
|
|
#nullable disable
|
|
|
|
namespace BlueLaminate.EFCore.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitialCreate : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "steam_users",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
steam_id = table.Column<string>(type: "text", nullable: false),
|
|
display_name = table.Column<string>(type: "text", nullable: true),
|
|
last_synced_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_steam_users", x => x.id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "weapons",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
name = table.Column<string>(type: "text", nullable: false),
|
|
type = table.Column<string>(type: "text", nullable: false),
|
|
team = table.Column<string>(type: "text", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_weapons", x => x.id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "trades",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
from_user_id = table.Column<int>(type: "integer", nullable: false),
|
|
to_user_id = table.Column<int>(type: "integer", nullable: false),
|
|
traded_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
steam_trade_id = table.Column<string>(type: "text", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_trades", x => x.id);
|
|
table.ForeignKey(
|
|
name: "fk_trades_steam_users_from_user_id",
|
|
column: x => x.from_user_id,
|
|
principalTable: "steam_users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_trades_steam_users_to_user_id",
|
|
column: x => x.to_user_id,
|
|
principalTable: "steam_users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "skins",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
weapon_id = table.Column<int>(type: "integer", nullable: false),
|
|
name = table.Column<string>(type: "text", nullable: false),
|
|
rarity = table.Column<string>(type: "text", nullable: false),
|
|
description = table.Column<string>(type: "text", nullable: true),
|
|
image_url = table.Column<string>(type: "text", nullable: true),
|
|
float_min = table.Column<decimal>(type: "numeric(10,9)", nullable: false, defaultValue: 0.0m),
|
|
float_max = table.Column<decimal>(type: "numeric(10,9)", nullable: false, defaultValue: 1.0m),
|
|
true_float = table.Column<bool>(type: "boolean", nullable: false, computedColumnSql: "float_min = 0.0 AND float_max = 1.0", stored: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_skins", x => x.id);
|
|
table.ForeignKey(
|
|
name: "fk_skins_weapons_weapon_id",
|
|
column: x => x.weapon_id,
|
|
principalTable: "weapons",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "skin_conditions",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
skin_id = table.Column<int>(type: "integer", nullable: false),
|
|
condition = table.Column<string>(type: "text", nullable: false),
|
|
min_float = table.Column<decimal>(type: "numeric(10,9)", nullable: false),
|
|
max_float = table.Column<decimal>(type: "numeric(10,9)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_skin_conditions", x => x.id);
|
|
table.ForeignKey(
|
|
name: "fk_skin_conditions_skins_skin_id",
|
|
column: x => x.skin_id,
|
|
principalTable: "skins",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "price_histories",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
skin_id = table.Column<int>(type: "integer", nullable: false),
|
|
condition_id = table.Column<int>(type: "integer", nullable: false),
|
|
price = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
|
|
currency = table.Column<string>(type: "text", nullable: false),
|
|
recorded_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
source = table.Column<string>(type: "text", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_price_histories", x => x.id);
|
|
table.ForeignKey(
|
|
name: "fk_price_histories_skin_conditions_condition_id",
|
|
column: x => x.condition_id,
|
|
principalTable: "skin_conditions",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_price_histories_skins_skin_id",
|
|
column: x => x.skin_id,
|
|
principalTable: "skins",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "skin_instances",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
skin_id = table.Column<int>(type: "integer", nullable: false),
|
|
condition_id = table.Column<int>(type: "integer", nullable: false),
|
|
float_value = table.Column<decimal>(type: "numeric(10,9)", nullable: false),
|
|
paint_seed = table.Column<string>(type: "text", nullable: false),
|
|
stat_trak = table.Column<bool>(type: "boolean", nullable: false),
|
|
souvenir = table.Column<bool>(type: "boolean", nullable: false),
|
|
first_seen_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_skin_instances", x => x.id);
|
|
table.ForeignKey(
|
|
name: "fk_skin_instances_skin_conditions_condition_id",
|
|
column: x => x.condition_id,
|
|
principalTable: "skin_conditions",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_skin_instances_skins_skin_id",
|
|
column: x => x.skin_id,
|
|
principalTable: "skins",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "inventory_items",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
user_id = table.Column<int>(type: "integer", nullable: false),
|
|
skin_instance_id = table.Column<int>(type: "integer", nullable: false),
|
|
asset_id = table.Column<string>(type: "text", nullable: false),
|
|
acquired_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_inventory_items", x => x.id);
|
|
table.ForeignKey(
|
|
name: "fk_inventory_items_skin_instances_skin_instance_id",
|
|
column: x => x.skin_instance_id,
|
|
principalTable: "skin_instances",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_inventory_items_steam_users_user_id",
|
|
column: x => x.user_id,
|
|
principalTable: "steam_users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "trade_items",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
trade_id = table.Column<int>(type: "integer", nullable: false),
|
|
inventory_item_id = table.Column<int>(type: "integer", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_trade_items", x => x.id);
|
|
table.ForeignKey(
|
|
name: "fk_trade_items_inventory_items_inventory_item_id",
|
|
column: x => x.inventory_item_id,
|
|
principalTable: "inventory_items",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_trade_items_trades_trade_id",
|
|
column: x => x.trade_id,
|
|
principalTable: "trades",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_inventory_items_asset_id",
|
|
table: "inventory_items",
|
|
column: "asset_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_inventory_items_skin_instance_id",
|
|
table: "inventory_items",
|
|
column: "skin_instance_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_inventory_items_user_id",
|
|
table: "inventory_items",
|
|
column: "user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_price_histories_condition_id",
|
|
table: "price_histories",
|
|
column: "condition_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_price_histories_skin_id_condition_id_recorded_at",
|
|
table: "price_histories",
|
|
columns: new[] { "skin_id", "condition_id", "recorded_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_skin_conditions_skin_id",
|
|
table: "skin_conditions",
|
|
column: "skin_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_skin_instances_condition_id",
|
|
table: "skin_instances",
|
|
column: "condition_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_skin_instances_float_value",
|
|
table: "skin_instances",
|
|
column: "float_value");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_skin_instances_paint_seed",
|
|
table: "skin_instances",
|
|
column: "paint_seed");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_skin_instances_skin_id",
|
|
table: "skin_instances",
|
|
column: "skin_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_skins_true_float",
|
|
table: "skins",
|
|
column: "true_float");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_skins_weapon_id",
|
|
table: "skins",
|
|
column: "weapon_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_steam_users_steam_id",
|
|
table: "steam_users",
|
|
column: "steam_id",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_trade_items_inventory_item_id",
|
|
table: "trade_items",
|
|
column: "inventory_item_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_trade_items_trade_id",
|
|
table: "trade_items",
|
|
column: "trade_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_trades_from_user_id",
|
|
table: "trades",
|
|
column: "from_user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_trades_to_user_id",
|
|
table: "trades",
|
|
column: "to_user_id");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "price_histories");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "trade_items");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "inventory_items");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "trades");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "skin_instances");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "steam_users");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "skin_conditions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "skins");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "weapons");
|
|
}
|
|
}
|
|
}
|