Files
CollabVMAuthServer/CollabVMAuthServer/Database/Migrations/20250505224256_InitialDbModel.cs
Elijah R 290a9a5777 major refactor:
- Now uses EntityFrameworkCore for database operations
- HTTP handlers have all been refactored to use ASP.NET MVC controllers, and generally to be more idiomatic and remove copied boilerplate ugliness
- Authentication/Authorization refactored to use native ASP.NET core handlers
- Switch to Microsoft.Extensions.Logging instead of handrolled logging method
2025-05-06 04:34:46 -04:00

158 lines
8.4 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Computernewb.CollabVMAuthServer.Database.Migrations
{
/// <inheritdoc />
public partial class InitialDbModel : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "ip_bans",
columns: table => new
{
ip = table.Column<byte[]>(type: "varbinary(16)", maxLength: 16, nullable: false),
reason = table.Column<string>(type: "text", nullable: false, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
banned_by = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
banned_at = table.Column<DateTime>(type: "timestamp", nullable: false, defaultValueSql: "current_timestamp()")
},
constraints: table =>
{
table.PrimaryKey("PRIMARY", x => x.ip);
})
.Annotation("MySql:CharSet", "utf8mb4")
.Annotation("Relational:Collation", "utf8mb4_unicode_ci");
migrationBuilder.CreateTable(
name: "users",
columns: table => new
{
id = table.Column<uint>(type: "int(10) unsigned", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
username = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
password = table.Column<string>(type: "text", nullable: false, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
email = table.Column<string>(type: "text", nullable: false, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
date_of_birth = table.Column<DateOnly>(type: "date", nullable: false),
email_verified = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false),
email_verification_code = table.Column<string>(type: "char(8)", fixedLength: true, maxLength: 8, nullable: true, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
password_reset_code = table.Column<string>(type: "char(8)", fixedLength: true, maxLength: 8, nullable: true, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
cvm_rank = table.Column<uint>(type: "int(10) unsigned", nullable: false, defaultValueSql: "'1'"),
banned = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false),
ban_reason = table.Column<string>(type: "text", nullable: true, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
registration_ip = table.Column<byte[]>(type: "varbinary(16)", maxLength: 16, nullable: false),
created = table.Column<DateTime>(type: "timestamp", nullable: false, defaultValueSql: "current_timestamp()"),
developer = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false)
},
constraints: table =>
{
table.PrimaryKey("PRIMARY", x => x.id);
table.UniqueConstraint("username", x => x.username);
table.UniqueConstraint("email", x => x.email);
})
.Annotation("MySql:CharSet", "utf8mb4")
.Annotation("Relational:Collation", "utf8mb4_unicode_ci");
migrationBuilder.CreateTable(
name: "bots",
columns: table => new
{
id = table.Column<uint>(type: "int(10) unsigned", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
username = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
token = table.Column<string>(type: "char(64)", fixedLength: true, maxLength: 64, nullable: false, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
cvm_rank = table.Column<uint>(type: "int(10) unsigned", nullable: false, defaultValueSql: "'1'"),
owner = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
created = table.Column<DateTime>(type: "timestamp", nullable: false, defaultValueSql: "current_timestamp()")
},
constraints: table =>
{
table.PrimaryKey("PRIMARY", x => x.id);
table.UniqueConstraint("username", x => x.username);
table.UniqueConstraint("token", x => x.token);
table.ForeignKey(
name: "bots_ibfk_1",
column: x => x.owner,
principalTable: "users",
principalColumn: "username",
onUpdate: ReferentialAction.Cascade,
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4")
.Annotation("Relational:Collation", "utf8mb4_unicode_ci");
migrationBuilder.CreateIndex(
name: "owner",
column: "owner",
table: "bots"
);
migrationBuilder.CreateTable(
name: "sessions",
columns: table => new
{
token = table.Column<string>(type: "char(32)", fixedLength: true, maxLength: 32, nullable: false, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
username = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false, collation: "utf8mb4_unicode_ci")
.Annotation("MySql:CharSet", "utf8mb4"),
created = table.Column<DateTime>(type: "timestamp", nullable: false, defaultValueSql: "current_timestamp()"),
last_used = table.Column<DateTime>(type: "timestamp", nullable: false, defaultValueSql: "current_timestamp()"),
last_ip = table.Column<byte[]>(type: "varbinary(16)", maxLength: 16, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PRIMARY", x => x.token);
table.ForeignKey(
name: "sessions_ibfk_1",
column: x => x.username,
principalTable: "users",
principalColumn: "username",
onUpdate: ReferentialAction.Cascade,
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4")
.Annotation("Relational:Collation", "utf8mb4_unicode_ci");
migrationBuilder.CreateIndex(
name: "username",
column: "username",
table: "sessions"
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "bots");
migrationBuilder.DropTable(
name: "ip_bans");
migrationBuilder.DropTable(
name: "sessions");
migrationBuilder.DropTable(
name: "users");
}
}
}