using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace SystemRevivalServer.Migrations { /// public partial class InitialGameSchema : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterDatabase() .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "accounts", columns: table => new { Id = table.Column(type: "bigint unsigned", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Username = table.Column(type: "varchar(32)", maxLength: 32, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Email = table.Column(type: "varchar(255)", maxLength: 255, nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), PasswordHash = table.Column(type: "varbinary(64)", nullable: false), PasswordSalt = table.Column(type: "varbinary(32)", nullable: false), IsBanned = table.Column(type: "tinyint(1)", nullable: false), BannedUntil = table.Column(type: "datetime(6)", nullable: true), CreatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"), UpdatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)") .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn) }, constraints: table => { table.PrimaryKey("PK_accounts", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "item_templates", columns: table => new { Id = table.Column(type: "bigint unsigned", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(type: "varchar(64)", maxLength: 64, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), ItemType = table.Column(type: "tinyint unsigned", nullable: false), Rarity = table.Column(type: "tinyint unsigned", nullable: false), MaxStack = table.Column(type: "int unsigned", nullable: false), Weight = table.Column(type: "int unsigned", nullable: false), StatsJson = table.Column(type: "json", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), CreatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"), UpdatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)") .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn) }, constraints: table => { table.PrimaryKey("PK_item_templates", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "zones", columns: table => new { Id = table.Column(type: "bigint unsigned", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(type: "varchar(64)", maxLength: 64, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), MinX = table.Column(type: "double", nullable: false), MinY = table.Column(type: "double", nullable: false), MinZ = table.Column(type: "double", nullable: false), MaxX = table.Column(type: "double", nullable: false), MaxY = table.Column(type: "double", nullable: false), MaxZ = table.Column(type: "double", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"), UpdatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)") .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn) }, constraints: table => { table.PrimaryKey("PK_zones", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "sessions", columns: table => new { Id = table.Column(type: "bigint unsigned", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), AccountId = table.Column(type: "bigint unsigned", nullable: false), Token = table.Column(type: "varchar(64)", maxLength: 64, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), ExpiresAt = table.Column(type: "datetime(6)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)") }, constraints: table => { table.PrimaryKey("PK_sessions", x => x.Id); table.ForeignKey( name: "FK_sessions_accounts_AccountId", column: x => x.AccountId, principalTable: "accounts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "characters", columns: table => new { Id = table.Column(type: "bigint unsigned", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), AccountId = table.Column(type: "bigint unsigned", nullable: false), Name = table.Column(type: "varchar(32)", maxLength: 32, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Level = table.Column(type: "int unsigned", nullable: false), Xp = table.Column(type: "bigint unsigned", nullable: false), StatStrength = table.Column(type: "int unsigned", nullable: false), StatDexterity = table.Column(type: "int unsigned", nullable: false), StatWisdom = table.Column(type: "int unsigned", nullable: false), StatIntelligence = table.Column(type: "int unsigned", nullable: false), StatEndurance = table.Column(type: "int unsigned", nullable: false), HpCurrent = table.Column(type: "int unsigned", nullable: false), HpMax = table.Column(type: "int unsigned", nullable: false), MpCurrent = table.Column(type: "int unsigned", nullable: false), MpMax = table.Column(type: "int unsigned", nullable: false), StaminaCurrent = table.Column(type: "int unsigned", nullable: false), StaminaMax = table.Column(type: "int unsigned", nullable: false), ZoneId = table.Column(type: "bigint unsigned", nullable: false), PosX = table.Column(type: "double", nullable: false), PosY = table.Column(type: "double", nullable: false), PosZ = table.Column(type: "double", nullable: false), FacingDeg = table.Column(type: "float", nullable: false), AppearanceJson = table.Column(type: "json", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), CreatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"), UpdatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)") .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn) }, constraints: table => { table.PrimaryKey("PK_characters", x => x.Id); table.ForeignKey( name: "FK_characters_accounts_AccountId", column: x => x.AccountId, principalTable: "accounts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_characters_zones_ZoneId", column: x => x.ZoneId, principalTable: "zones", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "equipment", columns: table => new { Id = table.Column(type: "bigint unsigned", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), CharacterId = table.Column(type: "bigint unsigned", nullable: false), SlotCode = table.Column(type: "tinyint unsigned", nullable: false), ItemTemplateId = table.Column(type: "bigint unsigned", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"), UpdatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)") .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn) }, constraints: table => { table.PrimaryKey("PK_equipment", x => x.Id); table.ForeignKey( name: "FK_equipment_characters_CharacterId", column: x => x.CharacterId, principalTable: "characters", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_equipment_item_templates_ItemTemplateId", column: x => x.ItemTemplateId, principalTable: "item_templates", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "inventories", columns: table => new { Id = table.Column(type: "bigint unsigned", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), CharacterId = table.Column(type: "bigint unsigned", nullable: false), SlotIndex = table.Column(type: "int unsigned", nullable: false), ItemTemplateId = table.Column(type: "bigint unsigned", nullable: false), Quantity = table.Column(type: "int unsigned", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"), UpdatedAt = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)") .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn) }, constraints: table => { table.PrimaryKey("PK_inventories", x => x.Id); table.ForeignKey( name: "FK_inventories_characters_CharacterId", column: x => x.CharacterId, principalTable: "characters", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_inventories_item_templates_ItemTemplateId", column: x => x.ItemTemplateId, principalTable: "item_templates", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_accounts_Email", table: "accounts", column: "Email", unique: true); migrationBuilder.CreateIndex( name: "IX_accounts_Username", table: "accounts", column: "Username", unique: true); migrationBuilder.CreateIndex( name: "IX_characters_AccountId", table: "characters", column: "AccountId", unique: true); migrationBuilder.CreateIndex( name: "IX_characters_ZoneId", table: "characters", column: "ZoneId"); migrationBuilder.CreateIndex( name: "IX_equipment_CharacterId_SlotCode", table: "equipment", columns: new[] { "CharacterId", "SlotCode" }, unique: true); migrationBuilder.CreateIndex( name: "IX_equipment_ItemTemplateId", table: "equipment", column: "ItemTemplateId"); migrationBuilder.CreateIndex( name: "IX_inventories_CharacterId", table: "inventories", column: "CharacterId"); migrationBuilder.CreateIndex( name: "IX_inventories_CharacterId_SlotIndex", table: "inventories", columns: new[] { "CharacterId", "SlotIndex" }, unique: true); migrationBuilder.CreateIndex( name: "IX_inventories_ItemTemplateId", table: "inventories", column: "ItemTemplateId"); migrationBuilder.CreateIndex( name: "IX_item_templates_Name", table: "item_templates", column: "Name", unique: true); migrationBuilder.CreateIndex( name: "IX_sessions_AccountId", table: "sessions", column: "AccountId"); migrationBuilder.CreateIndex( name: "IX_sessions_Token", table: "sessions", column: "Token", unique: true); migrationBuilder.CreateIndex( name: "IX_zones_Name", table: "zones", column: "Name", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "equipment"); migrationBuilder.DropTable( name: "inventories"); migrationBuilder.DropTable( name: "sessions"); migrationBuilder.DropTable( name: "characters"); migrationBuilder.DropTable( name: "item_templates"); migrationBuilder.DropTable( name: "accounts"); migrationBuilder.DropTable( name: "zones"); } } }