Holy crap auth works (#2099)

* Holy crap auth works

* Fix some usages of UserID instead of UserName

* Refactor preferences.

They be non-async now. Also faster.

* Rename DbContext.

* Guest username assignment.

* Fix saving of profiles.

* Don't store data for guests.

* Fix generating invalid random colors.

* Don't allow dumb garbage for char preferences.

* Bans.

* Lol forgot to fill out the command description.

* Connection log.

* Rename all the tables and columns to be snake_case.

* Re-do migrations.

* Fixing tests and warnings.

* Update submodule
This commit is contained in:
Pieter-Jan Briers
2020-09-29 14:26:00 +02:00
committed by GitHub
parent 8a33e0a9bd
commit 66c8a68891
72 changed files with 4144 additions and 2642 deletions

View File

@@ -1,85 +0,0 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Npgsql;
namespace Content.Server.Database
{
public interface IDatabaseConfiguration
{
DbContextOptions<PreferencesDbContext> Options { get; }
}
public class PostgresConfiguration : IDatabaseConfiguration
{
private readonly string _database;
private readonly string _host;
private readonly string _password;
private readonly int _port;
private readonly string _username;
public PostgresConfiguration(string host,
int port,
string database,
string username,
string password)
{
_host = host;
_port = port;
_database = database;
_username = username;
_password = password;
}
public DbContextOptions<PreferencesDbContext> Options
{
get
{
var optionsBuilder = new DbContextOptionsBuilder<PreferencesDbContext>();
var connectionString = new NpgsqlConnectionStringBuilder
{
Host = _host,
Port = _port,
Database = _database,
Username = _username,
Password = _password
}.ConnectionString;
optionsBuilder.UseNpgsql(connectionString);
return optionsBuilder.Options;
}
}
}
public class SqliteConfiguration : IDatabaseConfiguration
{
private readonly string? _databaseFilePath;
/// <param name="databaseFilePath">If null, an in-memory database is used.</param>
public SqliteConfiguration(string? databaseFilePath)
{
_databaseFilePath = databaseFilePath;
}
public DbContextOptions<PreferencesDbContext> Options
{
get
{
var optionsBuilder = new DbContextOptionsBuilder<PreferencesDbContext>();
SqliteConnection connection;
if (_databaseFilePath != null)
{
connection = new SqliteConnection($"Data Source={_databaseFilePath}");
}
else
{
connection = new SqliteConnection("Data Source=:memory:");
// When using an in-memory DB we have to open it manually
// so EFCore doesn't open, close and wipe it.
connection.Open();
}
optionsBuilder.UseSqlite(connection);
return optionsBuilder.Options;
}
}
}
}

View File

@@ -21,4 +21,9 @@
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\Postgres" />
<Folder Include="Migrations\Sqlite" />
</ItemGroup>
</Project>

View File

@@ -1,151 +0,0 @@
// <auto-generated />
using Content.Server.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Content.Server.Database.Migrations.Postgres
{
[DbContext(typeof(PostgresPreferencesDbContext))]
[Migration("20200124133512_InitialPg")]
partial class InitialPg
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.Property<int>("HumanoidProfileId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("Age")
.HasColumnType("integer");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("HairName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("PreferenceUnavailable")
.HasColumnType("integer");
b.Property<int>("PrefsId")
.HasColumnType("integer");
b.Property<string>("Sex")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Slot")
.HasColumnType("integer");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("text");
b.HasKey("HumanoidProfileId");
b.HasIndex("PrefsId");
b.ToTable("HumanoidProfile");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("JobId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("JobName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Priority")
.HasColumnType("integer");
b.Property<int>("ProfileHumanoidProfileId")
.HasColumnType("integer");
b.HasKey("JobId");
b.HasIndex("ProfileHumanoidProfileId");
b.ToTable("Job");
});
modelBuilder.Entity("Content.Server.Database.Prefs", b =>
{
b.Property<int>("PrefsId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("SelectedCharacterSlot")
.HasColumnType("integer");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.HasKey("PrefsId");
b.HasIndex("Username")
.IsUnique();
b.ToTable("Preferences");
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.HasOne("Content.Server.Database.Prefs", "Prefs")
.WithMany("HumanoidProfiles")
.HasForeignKey("PrefsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileHumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,105 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Content.Server.Database.Migrations.Postgres
{
public partial class InitialPg : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Preferences",
columns: table => new
{
PrefsId = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Username = table.Column<string>(nullable: false),
SelectedCharacterSlot = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Preferences", x => x.PrefsId);
});
migrationBuilder.CreateTable(
name: "HumanoidProfile",
columns: table => new
{
HumanoidProfileId = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Slot = table.Column<int>(nullable: false),
SlotName = table.Column<string>(nullable: false),
CharacterName = table.Column<string>(nullable: false),
Age = table.Column<int>(nullable: false),
Sex = table.Column<string>(nullable: false),
HairName = table.Column<string>(nullable: false),
HairColor = table.Column<string>(nullable: false),
FacialHairName = table.Column<string>(nullable: false),
FacialHairColor = table.Column<string>(nullable: false),
EyeColor = table.Column<string>(nullable: false),
SkinColor = table.Column<string>(nullable: false),
PreferenceUnavailable = table.Column<int>(nullable: false),
PrefsId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_HumanoidProfile", x => x.HumanoidProfileId);
table.ForeignKey(
name: "FK_HumanoidProfile_Preferences_PrefsId",
column: x => x.PrefsId,
principalTable: "Preferences",
principalColumn: "PrefsId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Job",
columns: table => new
{
JobId = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ProfileHumanoidProfileId = table.Column<int>(nullable: false),
JobName = table.Column<string>(nullable: false),
Priority = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Job", x => x.JobId);
table.ForeignKey(
name: "FK_Job_HumanoidProfile_ProfileHumanoidProfileId",
column: x => x.ProfileHumanoidProfileId,
principalTable: "HumanoidProfile",
principalColumn: "HumanoidProfileId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_HumanoidProfile_PrefsId",
table: "HumanoidProfile",
column: "PrefsId");
migrationBuilder.CreateIndex(
name: "IX_Job_ProfileHumanoidProfileId",
table: "Job",
column: "ProfileHumanoidProfileId");
migrationBuilder.CreateIndex(
name: "IX_Preferences_Username",
table: "Preferences",
column: "Username",
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Job");
migrationBuilder.DropTable(
name: "HumanoidProfile");
migrationBuilder.DropTable(
name: "Preferences");
}
}
}

View File

@@ -1,154 +0,0 @@
// <auto-generated />
using Content.Server.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Content.Server.Database.Migrations.Postgres
{
[DbContext(typeof(PostgresPreferencesDbContext))]
[Migration("20200625230829_AddSlotPrefsIdIndex")]
partial class AddSlotPrefsIdIndex
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.Property<int>("HumanoidProfileId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("Age")
.HasColumnType("integer");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("HairName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("PreferenceUnavailable")
.HasColumnType("integer");
b.Property<int>("PrefsId")
.HasColumnType("integer");
b.Property<string>("Sex")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Slot")
.HasColumnType("integer");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("text");
b.HasKey("HumanoidProfileId");
b.HasIndex("PrefsId");
b.HasIndex("Slot", "PrefsId")
.IsUnique();
b.ToTable("HumanoidProfile");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("JobId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("JobName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Priority")
.HasColumnType("integer");
b.Property<int>("ProfileHumanoidProfileId")
.HasColumnType("integer");
b.HasKey("JobId");
b.HasIndex("ProfileHumanoidProfileId");
b.ToTable("Job");
});
modelBuilder.Entity("Content.Server.Database.Prefs", b =>
{
b.Property<int>("PrefsId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("SelectedCharacterSlot")
.HasColumnType("integer");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.HasKey("PrefsId");
b.HasIndex("Username")
.IsUnique();
b.ToTable("Preferences");
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.HasOne("Content.Server.Database.Prefs", "Prefs")
.WithMany("HumanoidProfiles")
.HasForeignKey("PrefsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileHumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,23 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Postgres
{
public partial class AddSlotPrefsIdIndex : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_HumanoidProfile_Slot_PrefsId",
table: "HumanoidProfile",
columns: new[] { "Slot", "PrefsId" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_HumanoidProfile_Slot_PrefsId",
table: "HumanoidProfile");
}
}
}

View File

@@ -1,185 +0,0 @@
// <auto-generated />
using Content.Server.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Content.Server.Database.Migrations.Postgres
{
[DbContext(typeof(PostgresPreferencesDbContext))]
[Migration("20200706172726_Antags")]
partial class Antags
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.Property<int>("AntagId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("AntagName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("HumanoidProfileId")
.HasColumnType("integer");
b.HasKey("AntagId");
b.HasIndex("HumanoidProfileId", "AntagName")
.IsUnique();
b.ToTable("Antag");
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.Property<int>("HumanoidProfileId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("Age")
.HasColumnType("integer");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("HairName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("PreferenceUnavailable")
.HasColumnType("integer");
b.Property<int>("PrefsId")
.HasColumnType("integer");
b.Property<string>("Sex")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Slot")
.HasColumnType("integer");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("text");
b.HasKey("HumanoidProfileId");
b.HasIndex("PrefsId");
b.HasIndex("Slot", "PrefsId")
.IsUnique();
b.ToTable("HumanoidProfile");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("JobId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("JobName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Priority")
.HasColumnType("integer");
b.Property<int>("ProfileHumanoidProfileId")
.HasColumnType("integer");
b.HasKey("JobId");
b.HasIndex("ProfileHumanoidProfileId");
b.ToTable("Job");
});
modelBuilder.Entity("Content.Server.Database.Prefs", b =>
{
b.Property<int>("PrefsId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("SelectedCharacterSlot")
.HasColumnType("integer");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.HasKey("PrefsId");
b.HasIndex("Username")
.IsUnique();
b.ToTable("Preferences");
});
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Antags")
.HasForeignKey("HumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.HasOne("Content.Server.Database.Prefs", "Prefs")
.WithMany("HumanoidProfiles")
.HasForeignKey("PrefsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileHumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,43 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Content.Server.Database.Migrations.Postgres
{
public partial class Antags : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Antag",
columns: table => new
{
AntagId = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
HumanoidProfileId = table.Column<int>(nullable: false),
AntagName = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Antag", x => x.AntagId);
table.ForeignKey(
name: "FK_Antag_HumanoidProfile_HumanoidProfileId",
column: x => x.HumanoidProfileId,
principalTable: "HumanoidProfile",
principalColumn: "HumanoidProfileId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Antag_HumanoidProfileId_AntagName",
table: "Antag",
columns: new[] { "HumanoidProfileId", "AntagName" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Antag");
}
}
}

View File

@@ -0,0 +1,391 @@
// <auto-generated />
using System;
using System.Net;
using Content.Server.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Content.Server.Database.Migrations.Postgres
{
[DbContext(typeof(PostgresServerDbContext))]
[Migration("20200929113117_Init")]
partial class Init
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("antag_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("AntagName")
.IsRequired()
.HasColumnName("antag_name")
.HasColumnType("text");
b.Property<int>("ProfileId")
.HasColumnName("profile_id")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ProfileId", "AntagName")
.IsUnique();
b.ToTable("antag");
});
modelBuilder.Entity("Content.Server.Database.AssignedUserId", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("assigned_user_id_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("uuid");
b.Property<string>("UserName")
.IsRequired()
.HasColumnName("user_name")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.HasIndex("UserName")
.IsUnique();
b.ToTable("assigned_user_id");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("job_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("JobName")
.IsRequired()
.HasColumnName("job_name")
.HasColumnType("text");
b.Property<int>("Priority")
.HasColumnName("priority")
.HasColumnType("integer");
b.Property<int>("ProfileId")
.HasColumnName("profile_id")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ProfileId");
b.ToTable("job");
});
modelBuilder.Entity("Content.Server.Database.PostgresConnectionLog", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("connection_log_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<IPAddress>("Address")
.IsRequired()
.HasColumnName("address")
.HasColumnType("inet");
b.Property<DateTime>("Time")
.HasColumnName("time")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("uuid");
b.Property<string>("UserName")
.IsRequired()
.HasColumnName("user_name")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("connection_log");
b.HasCheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
});
modelBuilder.Entity("Content.Server.Database.PostgresPlayer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("player_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<DateTime>("FirstSeenTime")
.HasColumnName("first_seen_time")
.HasColumnType("timestamp with time zone");
b.Property<IPAddress>("LastSeenAddress")
.IsRequired()
.HasColumnName("last_seen_address")
.HasColumnType("inet");
b.Property<DateTime>("LastSeenTime")
.HasColumnName("last_seen_time")
.HasColumnType("timestamp with time zone");
b.Property<string>("LastSeenUserName")
.IsRequired()
.HasColumnName("last_seen_user_name")
.HasColumnType("text");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("player");
b.HasCheckConstraint("LastSeenAddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= last_seen_address");
});
modelBuilder.Entity("Content.Server.Database.PostgresServerBan", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("server_ban_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<ValueTuple<IPAddress, int>?>("Address")
.HasColumnName("address")
.HasColumnType("inet");
b.Property<DateTime>("BanTime")
.HasColumnName("ban_time")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("BanningAdmin")
.HasColumnName("banning_admin")
.HasColumnType("uuid");
b.Property<DateTime?>("ExpirationTime")
.HasColumnName("expiration_time")
.HasColumnType("timestamp with time zone");
b.Property<string>("Reason")
.IsRequired()
.HasColumnName("reason")
.HasColumnType("text");
b.Property<Guid?>("UserId")
.HasColumnName("user_id")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("Address");
b.HasIndex("UserId");
b.ToTable("server_ban");
b.HasCheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
b.HasCheckConstraint("HaveEitherAddressOrUserId", "address IS NOT NULL OR user_id IS NOT NULL");
});
modelBuilder.Entity("Content.Server.Database.PostgresServerUnban", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("unban_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("BanId")
.HasColumnName("ban_id")
.HasColumnType("integer");
b.Property<DateTime>("UnbanTime")
.HasColumnName("unban_time")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("UnbanningAdmin")
.HasColumnName("unbanning_admin")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("BanId")
.IsUnique();
b.ToTable("server_unban");
});
modelBuilder.Entity("Content.Server.Database.Preference", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("preference_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("SelectedCharacterSlot")
.HasColumnName("selected_character_slot")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("preference");
});
modelBuilder.Entity("Content.Server.Database.Profile", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("profile_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("Age")
.HasColumnName("age")
.HasColumnType("integer");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnName("char_name")
.HasColumnType("text");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnName("eye_color")
.HasColumnType("text");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnName("facial_hair_color")
.HasColumnType("text");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnName("facial_hair_name")
.HasColumnType("text");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnName("hair_color")
.HasColumnType("text");
b.Property<string>("HairName")
.IsRequired()
.HasColumnName("hair_name")
.HasColumnType("text");
b.Property<int>("PreferenceId")
.HasColumnName("preference_id")
.HasColumnType("integer");
b.Property<int>("PreferenceUnavailable")
.HasColumnName("pref_unavailable")
.HasColumnType("integer");
b.Property<string>("Sex")
.IsRequired()
.HasColumnName("sex")
.HasColumnType("text");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnName("skin_color")
.HasColumnType("text");
b.Property<int>("Slot")
.HasColumnName("slot")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("PreferenceId");
b.HasIndex("Slot", "PreferenceId")
.IsUnique();
b.ToTable("profile");
});
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.HasOne("Content.Server.Database.Profile", "Profile")
.WithMany("Antags")
.HasForeignKey("ProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.Profile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.PostgresServerUnban", b =>
{
b.HasOne("Content.Server.Database.PostgresServerBan", "Ban")
.WithOne("Unban")
.HasForeignKey("Content.Server.Database.PostgresServerUnban", "BanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Profile", b =>
{
b.HasOne("Content.Server.Database.Preference", "Preference")
.WithMany("Profiles")
.HasForeignKey("PreferenceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,285 @@
using System;
using System.Net;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Content.Server.Database.Migrations.Postgres
{
public partial class Init : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "assigned_user_id",
columns: table => new
{
assigned_user_id_id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
user_name = table.Column<string>(nullable: false),
user_id = table.Column<Guid>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_assigned_user_id", x => x.assigned_user_id_id);
});
migrationBuilder.CreateTable(
name: "connection_log",
columns: table => new
{
connection_log_id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
user_id = table.Column<Guid>(nullable: false),
user_name = table.Column<string>(nullable: false),
time = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
address = table.Column<IPAddress>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_connection_log", x => x.connection_log_id);
table.CheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
});
migrationBuilder.CreateTable(
name: "player",
columns: table => new
{
player_id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
user_id = table.Column<Guid>(nullable: false),
first_seen_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
last_seen_user_name = table.Column<string>(nullable: false),
last_seen_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
last_seen_address = table.Column<IPAddress>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_player", x => x.player_id);
table.CheckConstraint("LastSeenAddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= last_seen_address");
});
migrationBuilder.CreateTable(
name: "preference",
columns: table => new
{
preference_id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
user_id = table.Column<Guid>(nullable: false),
selected_character_slot = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_preference", x => x.preference_id);
});
migrationBuilder.CreateTable(
name: "server_ban",
columns: table => new
{
server_ban_id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
user_id = table.Column<Guid>(nullable: true),
address = table.Column<ValueTuple<IPAddress, int>>(type: "inet", nullable: true),
ban_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
expiration_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
reason = table.Column<string>(nullable: false),
banning_admin = table.Column<Guid>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_server_ban", x => x.server_ban_id);
table.CheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
table.CheckConstraint("HaveEitherAddressOrUserId", "address IS NOT NULL OR user_id IS NOT NULL");
});
migrationBuilder.CreateTable(
name: "profile",
columns: table => new
{
profile_id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slot = table.Column<int>(nullable: false),
char_name = table.Column<string>(nullable: false),
age = table.Column<int>(nullable: false),
sex = table.Column<string>(nullable: false),
hair_name = table.Column<string>(nullable: false),
hair_color = table.Column<string>(nullable: false),
facial_hair_name = table.Column<string>(nullable: false),
facial_hair_color = table.Column<string>(nullable: false),
eye_color = table.Column<string>(nullable: false),
skin_color = table.Column<string>(nullable: false),
pref_unavailable = table.Column<int>(nullable: false),
preference_id = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_profile", x => x.profile_id);
table.ForeignKey(
name: "FK_profile_preference_preference_id",
column: x => x.preference_id,
principalTable: "preference",
principalColumn: "preference_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "server_unban",
columns: table => new
{
unban_id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ban_id = table.Column<int>(nullable: false),
unbanning_admin = table.Column<Guid>(nullable: true),
unban_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_server_unban", x => x.unban_id);
table.ForeignKey(
name: "FK_server_unban_server_ban_ban_id",
column: x => x.ban_id,
principalTable: "server_ban",
principalColumn: "server_ban_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "antag",
columns: table => new
{
antag_id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
profile_id = table.Column<int>(nullable: false),
antag_name = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_antag", x => x.antag_id);
table.ForeignKey(
name: "FK_antag_profile_profile_id",
column: x => x.profile_id,
principalTable: "profile",
principalColumn: "profile_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "job",
columns: table => new
{
job_id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
profile_id = table.Column<int>(nullable: false),
job_name = table.Column<string>(nullable: false),
priority = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_job", x => x.job_id);
table.ForeignKey(
name: "FK_job_profile_profile_id",
column: x => x.profile_id,
principalTable: "profile",
principalColumn: "profile_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_antag_profile_id_antag_name",
table: "antag",
columns: new[] { "profile_id", "antag_name" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_assigned_user_id_user_id",
table: "assigned_user_id",
column: "user_id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_assigned_user_id_user_name",
table: "assigned_user_id",
column: "user_name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_connection_log_user_id",
table: "connection_log",
column: "user_id");
migrationBuilder.CreateIndex(
name: "IX_job_profile_id",
table: "job",
column: "profile_id");
migrationBuilder.CreateIndex(
name: "IX_player_user_id",
table: "player",
column: "user_id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_preference_user_id",
table: "preference",
column: "user_id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_profile_preference_id",
table: "profile",
column: "preference_id");
migrationBuilder.CreateIndex(
name: "IX_profile_slot_preference_id",
table: "profile",
columns: new[] { "slot", "preference_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_server_ban_address",
table: "server_ban",
column: "address");
migrationBuilder.CreateIndex(
name: "IX_server_ban_user_id",
table: "server_ban",
column: "user_id");
migrationBuilder.CreateIndex(
name: "IX_server_unban_ban_id",
table: "server_unban",
column: "ban_id",
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "antag");
migrationBuilder.DropTable(
name: "assigned_user_id");
migrationBuilder.DropTable(
name: "connection_log");
migrationBuilder.DropTable(
name: "job");
migrationBuilder.DropTable(
name: "player");
migrationBuilder.DropTable(
name: "server_unban");
migrationBuilder.DropTable(
name: "profile");
migrationBuilder.DropTable(
name: "server_ban");
migrationBuilder.DropTable(
name: "preference");
}
}
}

View File

@@ -1,182 +0,0 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Content.Server.Database.Migrations.Postgres
{
[DbContext(typeof(PostgresPreferencesDbContext))]
partial class PostgresPreferencesDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.Property<int>("AntagId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("AntagName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("HumanoidProfileId")
.HasColumnType("integer");
b.HasKey("AntagId");
b.HasIndex("HumanoidProfileId", "AntagName")
.IsUnique();
b.ToTable("Antag");
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.Property<int>("HumanoidProfileId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("Age")
.HasColumnType("integer");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnType("text");
b.Property<string>("HairName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("PreferenceUnavailable")
.HasColumnType("integer");
b.Property<int>("PrefsId")
.HasColumnType("integer");
b.Property<string>("Sex")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Slot")
.HasColumnType("integer");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("text");
b.HasKey("HumanoidProfileId");
b.HasIndex("PrefsId");
b.HasIndex("Slot", "PrefsId")
.IsUnique();
b.ToTable("HumanoidProfile");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("JobId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("JobName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Priority")
.HasColumnType("integer");
b.Property<int>("ProfileHumanoidProfileId")
.HasColumnType("integer");
b.HasKey("JobId");
b.HasIndex("ProfileHumanoidProfileId");
b.ToTable("Job");
});
modelBuilder.Entity("Content.Server.Database.Prefs", b =>
{
b.Property<int>("PrefsId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("SelectedCharacterSlot")
.HasColumnType("integer");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.HasKey("PrefsId");
b.HasIndex("Username")
.IsUnique();
b.ToTable("Preferences");
});
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Antags")
.HasForeignKey("HumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.HasOne("Content.Server.Database.Prefs", "Prefs")
.WithMany("HumanoidProfiles")
.HasForeignKey("PrefsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileHumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,389 @@
// <auto-generated />
using System;
using System.Net;
using Content.Server.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Content.Server.Database.Migrations.Postgres
{
[DbContext(typeof(PostgresServerDbContext))]
partial class PostgresServerDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("antag_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("AntagName")
.IsRequired()
.HasColumnName("antag_name")
.HasColumnType("text");
b.Property<int>("ProfileId")
.HasColumnName("profile_id")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ProfileId", "AntagName")
.IsUnique();
b.ToTable("antag");
});
modelBuilder.Entity("Content.Server.Database.AssignedUserId", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("assigned_user_id_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("uuid");
b.Property<string>("UserName")
.IsRequired()
.HasColumnName("user_name")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.HasIndex("UserName")
.IsUnique();
b.ToTable("assigned_user_id");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("job_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("JobName")
.IsRequired()
.HasColumnName("job_name")
.HasColumnType("text");
b.Property<int>("Priority")
.HasColumnName("priority")
.HasColumnType("integer");
b.Property<int>("ProfileId")
.HasColumnName("profile_id")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ProfileId");
b.ToTable("job");
});
modelBuilder.Entity("Content.Server.Database.PostgresConnectionLog", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("connection_log_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<IPAddress>("Address")
.IsRequired()
.HasColumnName("address")
.HasColumnType("inet");
b.Property<DateTime>("Time")
.HasColumnName("time")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("uuid");
b.Property<string>("UserName")
.IsRequired()
.HasColumnName("user_name")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("connection_log");
b.HasCheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
});
modelBuilder.Entity("Content.Server.Database.PostgresPlayer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("player_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<DateTime>("FirstSeenTime")
.HasColumnName("first_seen_time")
.HasColumnType("timestamp with time zone");
b.Property<IPAddress>("LastSeenAddress")
.IsRequired()
.HasColumnName("last_seen_address")
.HasColumnType("inet");
b.Property<DateTime>("LastSeenTime")
.HasColumnName("last_seen_time")
.HasColumnType("timestamp with time zone");
b.Property<string>("LastSeenUserName")
.IsRequired()
.HasColumnName("last_seen_user_name")
.HasColumnType("text");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("player");
b.HasCheckConstraint("LastSeenAddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= last_seen_address");
});
modelBuilder.Entity("Content.Server.Database.PostgresServerBan", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("server_ban_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<ValueTuple<IPAddress, int>?>("Address")
.HasColumnName("address")
.HasColumnType("inet");
b.Property<DateTime>("BanTime")
.HasColumnName("ban_time")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("BanningAdmin")
.HasColumnName("banning_admin")
.HasColumnType("uuid");
b.Property<DateTime?>("ExpirationTime")
.HasColumnName("expiration_time")
.HasColumnType("timestamp with time zone");
b.Property<string>("Reason")
.IsRequired()
.HasColumnName("reason")
.HasColumnType("text");
b.Property<Guid?>("UserId")
.HasColumnName("user_id")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("Address");
b.HasIndex("UserId");
b.ToTable("server_ban");
b.HasCheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
b.HasCheckConstraint("HaveEitherAddressOrUserId", "address IS NOT NULL OR user_id IS NOT NULL");
});
modelBuilder.Entity("Content.Server.Database.PostgresServerUnban", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("unban_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("BanId")
.HasColumnName("ban_id")
.HasColumnType("integer");
b.Property<DateTime>("UnbanTime")
.HasColumnName("unban_time")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("UnbanningAdmin")
.HasColumnName("unbanning_admin")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("BanId")
.IsUnique();
b.ToTable("server_unban");
});
modelBuilder.Entity("Content.Server.Database.Preference", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("preference_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("SelectedCharacterSlot")
.HasColumnName("selected_character_slot")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("preference");
});
modelBuilder.Entity("Content.Server.Database.Profile", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("profile_id")
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("Age")
.HasColumnName("age")
.HasColumnType("integer");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnName("char_name")
.HasColumnType("text");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnName("eye_color")
.HasColumnType("text");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnName("facial_hair_color")
.HasColumnType("text");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnName("facial_hair_name")
.HasColumnType("text");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnName("hair_color")
.HasColumnType("text");
b.Property<string>("HairName")
.IsRequired()
.HasColumnName("hair_name")
.HasColumnType("text");
b.Property<int>("PreferenceId")
.HasColumnName("preference_id")
.HasColumnType("integer");
b.Property<int>("PreferenceUnavailable")
.HasColumnName("pref_unavailable")
.HasColumnType("integer");
b.Property<string>("Sex")
.IsRequired()
.HasColumnName("sex")
.HasColumnType("text");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnName("skin_color")
.HasColumnType("text");
b.Property<int>("Slot")
.HasColumnName("slot")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("PreferenceId");
b.HasIndex("Slot", "PreferenceId")
.IsUnique();
b.ToTable("profile");
});
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.HasOne("Content.Server.Database.Profile", "Profile")
.WithMany("Antags")
.HasForeignKey("ProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.Profile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.PostgresServerUnban", b =>
{
b.HasOne("Content.Server.Database.PostgresServerBan", "Ban")
.WithOne("Unban")
.HasForeignKey("Content.Server.Database.PostgresServerUnban", "BanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Profile", b =>
{
b.HasOne("Content.Server.Database.Preference", "Preference")
.WithMany("Profiles")
.HasForeignKey("PreferenceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,109 +0,0 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Sqlite
{
[DbContext(typeof(SqlitePreferencesDbContext))]
[Migration("20200118020532_initial")]
partial class initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.0");
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.Property<int>("HumanoidProfileId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("PrefsId")
.HasColumnType("INTEGER");
b.Property<string>("Sex")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Slot")
.HasColumnType("INTEGER");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("HumanoidProfileId");
b.HasIndex("PrefsId");
b.ToTable("HumanoidProfile");
});
modelBuilder.Entity("Content.Server.Database.Prefs", b =>
{
b.Property<int>("PrefsId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("SelectedCharacterSlot")
.HasColumnType("INTEGER");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PrefsId");
b.HasIndex("Username")
.IsUnique();
b.ToTable("Preferences");
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.HasOne("Content.Server.Database.Prefs", "Prefs")
.WithMany("HumanoidProfiles")
.HasForeignKey("PrefsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,74 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Sqlite
{
public partial class initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Preferences",
columns: table => new
{
PrefsId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Username = table.Column<string>(nullable: false),
SelectedCharacterSlot = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Preferences", x => x.PrefsId);
});
migrationBuilder.CreateTable(
name: "HumanoidProfile",
columns: table => new
{
HumanoidProfileId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Slot = table.Column<int>(nullable: false),
SlotName = table.Column<string>(nullable: false),
CharacterName = table.Column<string>(nullable: false),
Age = table.Column<int>(nullable: false),
Sex = table.Column<string>(nullable: false),
HairName = table.Column<string>(nullable: false),
HairColor = table.Column<string>(nullable: false),
FacialHairName = table.Column<string>(nullable: false),
FacialHairColor = table.Column<string>(nullable: false),
EyeColor = table.Column<string>(nullable: false),
SkinColor = table.Column<string>(nullable: false),
PrefsId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_HumanoidProfile", x => x.HumanoidProfileId);
table.ForeignKey(
name: "FK_HumanoidProfile_Preferences_PrefsId",
column: x => x.PrefsId,
principalTable: "Preferences",
principalColumn: "PrefsId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_HumanoidProfile_PrefsId",
table: "HumanoidProfile",
column: "PrefsId");
migrationBuilder.CreateIndex(
name: "IX_Preferences_Username",
table: "Preferences",
column: "Username",
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "HumanoidProfile");
migrationBuilder.DropTable(
name: "Preferences");
}
}
}

View File

@@ -1,141 +0,0 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Sqlite
{
[DbContext(typeof(SqlitePreferencesDbContext))]
[Migration("20200118195640_jobs")]
partial class jobs
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.0");
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.Property<int>("HumanoidProfileId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("PrefsId")
.HasColumnType("INTEGER");
b.Property<string>("Sex")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Slot")
.HasColumnType("INTEGER");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("HumanoidProfileId");
b.HasIndex("PrefsId");
b.ToTable("HumanoidProfile");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("JobId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("JobName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Priority")
.HasColumnType("INTEGER");
b.Property<int>("ProfileHumanoidProfileId")
.HasColumnType("INTEGER");
b.HasKey("JobId");
b.HasIndex("ProfileHumanoidProfileId");
b.ToTable("Job");
});
modelBuilder.Entity("Content.Server.Database.Prefs", b =>
{
b.Property<int>("PrefsId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("SelectedCharacterSlot")
.HasColumnType("INTEGER");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PrefsId");
b.HasIndex("Username")
.IsUnique();
b.ToTable("Preferences");
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.HasOne("Content.Server.Database.Prefs", "Prefs")
.WithMany("HumanoidProfiles")
.HasForeignKey("PrefsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileHumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,42 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Sqlite
{
public partial class jobs : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Job",
columns: table => new
{
JobId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
ProfileHumanoidProfileId = table.Column<int>(nullable: false),
JobName = table.Column<string>(nullable: false),
Priority = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Job", x => x.JobId);
table.ForeignKey(
name: "FK_Job_HumanoidProfile_ProfileHumanoidProfileId",
column: x => x.ProfileHumanoidProfileId,
principalTable: "HumanoidProfile",
principalColumn: "HumanoidProfileId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Job_ProfileHumanoidProfileId",
table: "Job",
column: "ProfileHumanoidProfileId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Job");
}
}
}

View File

@@ -1,144 +0,0 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Sqlite
{
[DbContext(typeof(SqlitePreferencesDbContext))]
[Migration("20200119103426_preferenceUnavailable")]
partial class preferenceUnavailable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.0");
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.Property<int>("HumanoidProfileId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("PreferenceUnavailable")
.HasColumnType("INTEGER");
b.Property<int>("PrefsId")
.HasColumnType("INTEGER");
b.Property<string>("Sex")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Slot")
.HasColumnType("INTEGER");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("HumanoidProfileId");
b.HasIndex("PrefsId");
b.ToTable("HumanoidProfile");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("JobId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("JobName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Priority")
.HasColumnType("INTEGER");
b.Property<int>("ProfileHumanoidProfileId")
.HasColumnType("INTEGER");
b.HasKey("JobId");
b.HasIndex("ProfileHumanoidProfileId");
b.ToTable("Job");
});
modelBuilder.Entity("Content.Server.Database.Prefs", b =>
{
b.Property<int>("PrefsId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("SelectedCharacterSlot")
.HasColumnType("INTEGER");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PrefsId");
b.HasIndex("Username")
.IsUnique();
b.ToTable("Preferences");
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.HasOne("Content.Server.Database.Prefs", "Prefs")
.WithMany("HumanoidProfiles")
.HasForeignKey("PrefsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileHumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,23 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Sqlite
{
public partial class preferenceUnavailable : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "PreferenceUnavailable",
table: "HumanoidProfile",
nullable: false,
defaultValue: 0);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "PreferenceUnavailable",
table: "HumanoidProfile");
}
}
}

View File

@@ -1,148 +0,0 @@
// <auto-generated />
using Content.Server.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Content.Server.Database.Migrations.Sqlite
{
[DbContext(typeof(SqlitePreferencesDbContext))]
[Migration("20200625230839_AddSlotPrefsIdIndex")]
partial class AddSlotPrefsIdIndex
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.4");
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.Property<int>("HumanoidProfileId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("PreferenceUnavailable")
.HasColumnType("INTEGER");
b.Property<int>("PrefsId")
.HasColumnType("INTEGER");
b.Property<string>("Sex")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Slot")
.HasColumnType("INTEGER");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("HumanoidProfileId");
b.HasIndex("PrefsId");
b.HasIndex("Slot", "PrefsId")
.IsUnique();
b.ToTable("HumanoidProfile");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("JobId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("JobName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Priority")
.HasColumnType("INTEGER");
b.Property<int>("ProfileHumanoidProfileId")
.HasColumnType("INTEGER");
b.HasKey("JobId");
b.HasIndex("ProfileHumanoidProfileId");
b.ToTable("Job");
});
modelBuilder.Entity("Content.Server.Database.Prefs", b =>
{
b.Property<int>("PrefsId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("SelectedCharacterSlot")
.HasColumnType("INTEGER");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PrefsId");
b.HasIndex("Username")
.IsUnique();
b.ToTable("Preferences");
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.HasOne("Content.Server.Database.Prefs", "Prefs")
.WithMany("HumanoidProfiles")
.HasForeignKey("PrefsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileHumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,23 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Sqlite
{
public partial class AddSlotPrefsIdIndex : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_HumanoidProfile_Slot_PrefsId",
table: "HumanoidProfile",
columns: new[] { "Slot", "PrefsId" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_HumanoidProfile_Slot_PrefsId",
table: "HumanoidProfile");
}
}
}

View File

@@ -1,178 +0,0 @@
// <auto-generated />
using Content.Server.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Content.Server.Database.Migrations.Sqlite
{
[DbContext(typeof(SqlitePreferencesDbContext))]
[Migration("20200706172741_Antags")]
partial class Antags
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.4");
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.Property<int>("AntagId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AntagName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("HumanoidProfileId")
.HasColumnType("INTEGER");
b.HasKey("AntagId");
b.HasIndex("HumanoidProfileId", "AntagName")
.IsUnique();
b.ToTable("Antag");
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.Property<int>("HumanoidProfileId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("PreferenceUnavailable")
.HasColumnType("INTEGER");
b.Property<int>("PrefsId")
.HasColumnType("INTEGER");
b.Property<string>("Sex")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Slot")
.HasColumnType("INTEGER");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("HumanoidProfileId");
b.HasIndex("PrefsId");
b.HasIndex("Slot", "PrefsId")
.IsUnique();
b.ToTable("HumanoidProfile");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("JobId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("JobName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Priority")
.HasColumnType("INTEGER");
b.Property<int>("ProfileHumanoidProfileId")
.HasColumnType("INTEGER");
b.HasKey("JobId");
b.HasIndex("ProfileHumanoidProfileId");
b.ToTable("Job");
});
modelBuilder.Entity("Content.Server.Database.Prefs", b =>
{
b.Property<int>("PrefsId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("SelectedCharacterSlot")
.HasColumnType("INTEGER");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PrefsId");
b.HasIndex("Username")
.IsUnique();
b.ToTable("Preferences");
});
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Antags")
.HasForeignKey("HumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.HasOne("Content.Server.Database.Prefs", "Prefs")
.WithMany("HumanoidProfiles")
.HasForeignKey("PrefsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileHumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,42 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Sqlite
{
public partial class Antags : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Antag",
columns: table => new
{
AntagId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
HumanoidProfileId = table.Column<int>(nullable: false),
AntagName = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Antag", x => x.AntagId);
table.ForeignKey(
name: "FK_Antag_HumanoidProfile_HumanoidProfileId",
column: x => x.HumanoidProfileId,
principalTable: "HumanoidProfile",
principalColumn: "HumanoidProfileId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Antag_HumanoidProfileId_AntagName",
table: "Antag",
columns: new[] { "HumanoidProfileId", "AntagName" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Antag");
}
}
}

View File

@@ -0,0 +1,361 @@
// <auto-generated />
using System;
using Content.Server.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Content.Server.Database.Migrations.Sqlite
{
[DbContext(typeof(SqliteServerDbContext))]
[Migration("20200929113112_Init")]
partial class Init
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.4");
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("antag_id")
.HasColumnType("INTEGER");
b.Property<string>("AntagName")
.IsRequired()
.HasColumnName("antag_name")
.HasColumnType("TEXT");
b.Property<int>("ProfileId")
.HasColumnName("profile_id")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProfileId", "AntagName")
.IsUnique();
b.ToTable("antag");
});
modelBuilder.Entity("Content.Server.Database.AssignedUserId", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("assigned_user_id_id")
.HasColumnType("INTEGER");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("TEXT");
b.Property<string>("UserName")
.IsRequired()
.HasColumnName("user_name")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.HasIndex("UserName")
.IsUnique();
b.ToTable("assigned_user_id");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("job_id")
.HasColumnType("INTEGER");
b.Property<string>("JobName")
.IsRequired()
.HasColumnName("job_name")
.HasColumnType("TEXT");
b.Property<int>("Priority")
.HasColumnName("priority")
.HasColumnType("INTEGER");
b.Property<int>("ProfileId")
.HasColumnName("profile_id")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProfileId");
b.ToTable("job");
});
modelBuilder.Entity("Content.Server.Database.Preference", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("preference_id")
.HasColumnType("INTEGER");
b.Property<int>("SelectedCharacterSlot")
.HasColumnName("selected_character_slot")
.HasColumnType("INTEGER");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("preference");
});
modelBuilder.Entity("Content.Server.Database.Profile", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("profile_id")
.HasColumnType("INTEGER");
b.Property<int>("Age")
.HasColumnName("age")
.HasColumnType("INTEGER");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnName("char_name")
.HasColumnType("TEXT");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnName("eye_color")
.HasColumnType("TEXT");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnName("facial_hair_color")
.HasColumnType("TEXT");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnName("facial_hair_name")
.HasColumnType("TEXT");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnName("hair_color")
.HasColumnType("TEXT");
b.Property<string>("HairName")
.IsRequired()
.HasColumnName("hair_name")
.HasColumnType("TEXT");
b.Property<int>("PreferenceId")
.HasColumnName("preference_id")
.HasColumnType("INTEGER");
b.Property<int>("PreferenceUnavailable")
.HasColumnName("pref_unavailable")
.HasColumnType("INTEGER");
b.Property<string>("Sex")
.IsRequired()
.HasColumnName("sex")
.HasColumnType("TEXT");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnName("skin_color")
.HasColumnType("TEXT");
b.Property<int>("Slot")
.HasColumnName("slot")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("PreferenceId");
b.HasIndex("Slot", "PreferenceId")
.IsUnique();
b.ToTable("profile");
});
modelBuilder.Entity("Content.Server.Database.SqliteConnectionLog", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("connection_log_id")
.HasColumnType("INTEGER");
b.Property<string>("Address")
.IsRequired()
.HasColumnName("address")
.HasColumnType("TEXT");
b.Property<DateTime>("Time")
.HasColumnName("time")
.HasColumnType("TEXT");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("TEXT");
b.Property<string>("UserName")
.IsRequired()
.HasColumnName("user_name")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("connection_log");
});
modelBuilder.Entity("Content.Server.Database.SqlitePlayer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("player_id")
.HasColumnType("INTEGER");
b.Property<DateTime>("FirstSeenTime")
.HasColumnName("first_seen_time")
.HasColumnType("TEXT");
b.Property<string>("LastSeenAddress")
.IsRequired()
.HasColumnName("last_seen_address")
.HasColumnType("TEXT");
b.Property<DateTime>("LastSeenTime")
.HasColumnName("last_seen_time")
.HasColumnType("TEXT");
b.Property<string>("LastSeenUserName")
.IsRequired()
.HasColumnName("last_seen_user_name")
.HasColumnType("TEXT");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("player");
});
modelBuilder.Entity("Content.Server.Database.SqliteServerBan", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("ban_id")
.HasColumnType("INTEGER");
b.Property<string>("Address")
.HasColumnName("address")
.HasColumnType("TEXT");
b.Property<DateTime>("BanTime")
.HasColumnName("ban_time")
.HasColumnType("TEXT");
b.Property<Guid?>("BanningAdmin")
.HasColumnName("banning_admin")
.HasColumnType("TEXT");
b.Property<DateTime?>("ExpirationTime")
.HasColumnName("expiration_time")
.HasColumnType("TEXT");
b.Property<string>("Reason")
.IsRequired()
.HasColumnName("reason")
.HasColumnType("TEXT");
b.Property<Guid?>("UserId")
.HasColumnName("user_id")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("ban");
});
modelBuilder.Entity("Content.Server.Database.SqliteServerUnban", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("unban_id")
.HasColumnType("INTEGER");
b.Property<int>("BanId")
.HasColumnName("ban_id")
.HasColumnType("INTEGER");
b.Property<DateTime>("UnbanTime")
.HasColumnName("unban_time")
.HasColumnType("TEXT");
b.Property<Guid?>("UnbanningAdmin")
.HasColumnName("unbanning_admin")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("BanId")
.IsUnique();
b.ToTable("unban");
});
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.HasOne("Content.Server.Database.Profile", "Profile")
.WithMany("Antags")
.HasForeignKey("ProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.Profile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Profile", b =>
{
b.HasOne("Content.Server.Database.Preference", "Preference")
.WithMany("Profiles")
.HasForeignKey("PreferenceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.SqliteServerUnban", b =>
{
b.HasOne("Content.Server.Database.SqliteServerBan", "Ban")
.WithOne("Unban")
.HasForeignKey("Content.Server.Database.SqliteServerUnban", "BanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,258 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Sqlite
{
public partial class Init : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "assigned_user_id",
columns: table => new
{
assigned_user_id_id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
user_name = table.Column<string>(nullable: false),
user_id = table.Column<Guid>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_assigned_user_id", x => x.assigned_user_id_id);
});
migrationBuilder.CreateTable(
name: "ban",
columns: table => new
{
ban_id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
user_id = table.Column<Guid>(nullable: true),
address = table.Column<string>(nullable: true),
ban_time = table.Column<DateTime>(nullable: false),
expiration_time = table.Column<DateTime>(nullable: true),
reason = table.Column<string>(nullable: false),
banning_admin = table.Column<Guid>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ban", x => x.ban_id);
});
migrationBuilder.CreateTable(
name: "connection_log",
columns: table => new
{
connection_log_id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
user_id = table.Column<Guid>(nullable: false),
user_name = table.Column<string>(nullable: false),
time = table.Column<DateTime>(nullable: false),
address = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_connection_log", x => x.connection_log_id);
});
migrationBuilder.CreateTable(
name: "player",
columns: table => new
{
player_id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
user_id = table.Column<Guid>(nullable: false),
first_seen_time = table.Column<DateTime>(nullable: false),
last_seen_user_name = table.Column<string>(nullable: false),
last_seen_time = table.Column<DateTime>(nullable: false),
last_seen_address = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_player", x => x.player_id);
});
migrationBuilder.CreateTable(
name: "preference",
columns: table => new
{
preference_id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
user_id = table.Column<Guid>(nullable: false),
selected_character_slot = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_preference", x => x.preference_id);
});
migrationBuilder.CreateTable(
name: "unban",
columns: table => new
{
unban_id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
ban_id = table.Column<int>(nullable: false),
unbanning_admin = table.Column<Guid>(nullable: true),
unban_time = table.Column<DateTime>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_unban", x => x.unban_id);
table.ForeignKey(
name: "FK_unban_ban_ban_id",
column: x => x.ban_id,
principalTable: "ban",
principalColumn: "ban_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "profile",
columns: table => new
{
profile_id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
slot = table.Column<int>(nullable: false),
char_name = table.Column<string>(nullable: false),
age = table.Column<int>(nullable: false),
sex = table.Column<string>(nullable: false),
hair_name = table.Column<string>(nullable: false),
hair_color = table.Column<string>(nullable: false),
facial_hair_name = table.Column<string>(nullable: false),
facial_hair_color = table.Column<string>(nullable: false),
eye_color = table.Column<string>(nullable: false),
skin_color = table.Column<string>(nullable: false),
pref_unavailable = table.Column<int>(nullable: false),
preference_id = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_profile", x => x.profile_id);
table.ForeignKey(
name: "FK_profile_preference_preference_id",
column: x => x.preference_id,
principalTable: "preference",
principalColumn: "preference_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "antag",
columns: table => new
{
antag_id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
profile_id = table.Column<int>(nullable: false),
antag_name = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_antag", x => x.antag_id);
table.ForeignKey(
name: "FK_antag_profile_profile_id",
column: x => x.profile_id,
principalTable: "profile",
principalColumn: "profile_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "job",
columns: table => new
{
job_id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
profile_id = table.Column<int>(nullable: false),
job_name = table.Column<string>(nullable: false),
priority = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_job", x => x.job_id);
table.ForeignKey(
name: "FK_job_profile_profile_id",
column: x => x.profile_id,
principalTable: "profile",
principalColumn: "profile_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_antag_profile_id_antag_name",
table: "antag",
columns: new[] { "profile_id", "antag_name" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_assigned_user_id_user_id",
table: "assigned_user_id",
column: "user_id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_assigned_user_id_user_name",
table: "assigned_user_id",
column: "user_name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_job_profile_id",
table: "job",
column: "profile_id");
migrationBuilder.CreateIndex(
name: "IX_preference_user_id",
table: "preference",
column: "user_id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_profile_preference_id",
table: "profile",
column: "preference_id");
migrationBuilder.CreateIndex(
name: "IX_profile_slot_preference_id",
table: "profile",
columns: new[] { "slot", "preference_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_unban_ban_id",
table: "unban",
column: "ban_id",
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "antag");
migrationBuilder.DropTable(
name: "assigned_user_id");
migrationBuilder.DropTable(
name: "connection_log");
migrationBuilder.DropTable(
name: "job");
migrationBuilder.DropTable(
name: "player");
migrationBuilder.DropTable(
name: "unban");
migrationBuilder.DropTable(
name: "profile");
migrationBuilder.DropTable(
name: "ban");
migrationBuilder.DropTable(
name: "preference");
}
}
}

View File

@@ -1,175 +0,0 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace Content.Server.Database.Migrations.Sqlite
{
[DbContext(typeof(SqlitePreferencesDbContext))]
partial class SqlitePreferencesDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.4");
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.Property<int>("AntagId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AntagName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("HumanoidProfileId")
.HasColumnType("INTEGER");
b.HasKey("AntagId");
b.HasIndex("HumanoidProfileId", "AntagName")
.IsUnique();
b.ToTable("Antag");
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.Property<int>("HumanoidProfileId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HairName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("PreferenceUnavailable")
.HasColumnType("INTEGER");
b.Property<int>("PrefsId")
.HasColumnType("INTEGER");
b.Property<string>("Sex")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Slot")
.HasColumnType("INTEGER");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("HumanoidProfileId");
b.HasIndex("PrefsId");
b.HasIndex("Slot", "PrefsId")
.IsUnique();
b.ToTable("HumanoidProfile");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("JobId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("JobName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Priority")
.HasColumnType("INTEGER");
b.Property<int>("ProfileHumanoidProfileId")
.HasColumnType("INTEGER");
b.HasKey("JobId");
b.HasIndex("ProfileHumanoidProfileId");
b.ToTable("Job");
});
modelBuilder.Entity("Content.Server.Database.Prefs", b =>
{
b.Property<int>("PrefsId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("SelectedCharacterSlot")
.HasColumnType("INTEGER");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PrefsId");
b.HasIndex("Username")
.IsUnique();
b.ToTable("Preferences");
});
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Antags")
.HasForeignKey("HumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.HumanoidProfile", b =>
{
b.HasOne("Content.Server.Database.Prefs", "Prefs")
.WithMany("HumanoidProfiles")
.HasForeignKey("PrefsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.HumanoidProfile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileHumanoidProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,359 @@
// <auto-generated />
using System;
using Content.Server.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Content.Server.Database.Migrations.Sqlite
{
[DbContext(typeof(SqliteServerDbContext))]
partial class SqliteServerDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.4");
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("antag_id")
.HasColumnType("INTEGER");
b.Property<string>("AntagName")
.IsRequired()
.HasColumnName("antag_name")
.HasColumnType("TEXT");
b.Property<int>("ProfileId")
.HasColumnName("profile_id")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProfileId", "AntagName")
.IsUnique();
b.ToTable("antag");
});
modelBuilder.Entity("Content.Server.Database.AssignedUserId", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("assigned_user_id_id")
.HasColumnType("INTEGER");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("TEXT");
b.Property<string>("UserName")
.IsRequired()
.HasColumnName("user_name")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.HasIndex("UserName")
.IsUnique();
b.ToTable("assigned_user_id");
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("job_id")
.HasColumnType("INTEGER");
b.Property<string>("JobName")
.IsRequired()
.HasColumnName("job_name")
.HasColumnType("TEXT");
b.Property<int>("Priority")
.HasColumnName("priority")
.HasColumnType("INTEGER");
b.Property<int>("ProfileId")
.HasColumnName("profile_id")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProfileId");
b.ToTable("job");
});
modelBuilder.Entity("Content.Server.Database.Preference", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("preference_id")
.HasColumnType("INTEGER");
b.Property<int>("SelectedCharacterSlot")
.HasColumnName("selected_character_slot")
.HasColumnType("INTEGER");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("preference");
});
modelBuilder.Entity("Content.Server.Database.Profile", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("profile_id")
.HasColumnType("INTEGER");
b.Property<int>("Age")
.HasColumnName("age")
.HasColumnType("INTEGER");
b.Property<string>("CharacterName")
.IsRequired()
.HasColumnName("char_name")
.HasColumnType("TEXT");
b.Property<string>("EyeColor")
.IsRequired()
.HasColumnName("eye_color")
.HasColumnType("TEXT");
b.Property<string>("FacialHairColor")
.IsRequired()
.HasColumnName("facial_hair_color")
.HasColumnType("TEXT");
b.Property<string>("FacialHairName")
.IsRequired()
.HasColumnName("facial_hair_name")
.HasColumnType("TEXT");
b.Property<string>("HairColor")
.IsRequired()
.HasColumnName("hair_color")
.HasColumnType("TEXT");
b.Property<string>("HairName")
.IsRequired()
.HasColumnName("hair_name")
.HasColumnType("TEXT");
b.Property<int>("PreferenceId")
.HasColumnName("preference_id")
.HasColumnType("INTEGER");
b.Property<int>("PreferenceUnavailable")
.HasColumnName("pref_unavailable")
.HasColumnType("INTEGER");
b.Property<string>("Sex")
.IsRequired()
.HasColumnName("sex")
.HasColumnType("TEXT");
b.Property<string>("SkinColor")
.IsRequired()
.HasColumnName("skin_color")
.HasColumnType("TEXT");
b.Property<int>("Slot")
.HasColumnName("slot")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("PreferenceId");
b.HasIndex("Slot", "PreferenceId")
.IsUnique();
b.ToTable("profile");
});
modelBuilder.Entity("Content.Server.Database.SqliteConnectionLog", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("connection_log_id")
.HasColumnType("INTEGER");
b.Property<string>("Address")
.IsRequired()
.HasColumnName("address")
.HasColumnType("TEXT");
b.Property<DateTime>("Time")
.HasColumnName("time")
.HasColumnType("TEXT");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("TEXT");
b.Property<string>("UserName")
.IsRequired()
.HasColumnName("user_name")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("connection_log");
});
modelBuilder.Entity("Content.Server.Database.SqlitePlayer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("player_id")
.HasColumnType("INTEGER");
b.Property<DateTime>("FirstSeenTime")
.HasColumnName("first_seen_time")
.HasColumnType("TEXT");
b.Property<string>("LastSeenAddress")
.IsRequired()
.HasColumnName("last_seen_address")
.HasColumnType("TEXT");
b.Property<DateTime>("LastSeenTime")
.HasColumnName("last_seen_time")
.HasColumnType("TEXT");
b.Property<string>("LastSeenUserName")
.IsRequired()
.HasColumnName("last_seen_user_name")
.HasColumnType("TEXT");
b.Property<Guid>("UserId")
.HasColumnName("user_id")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("player");
});
modelBuilder.Entity("Content.Server.Database.SqliteServerBan", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("ban_id")
.HasColumnType("INTEGER");
b.Property<string>("Address")
.HasColumnName("address")
.HasColumnType("TEXT");
b.Property<DateTime>("BanTime")
.HasColumnName("ban_time")
.HasColumnType("TEXT");
b.Property<Guid?>("BanningAdmin")
.HasColumnName("banning_admin")
.HasColumnType("TEXT");
b.Property<DateTime?>("ExpirationTime")
.HasColumnName("expiration_time")
.HasColumnType("TEXT");
b.Property<string>("Reason")
.IsRequired()
.HasColumnName("reason")
.HasColumnType("TEXT");
b.Property<Guid?>("UserId")
.HasColumnName("user_id")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("ban");
});
modelBuilder.Entity("Content.Server.Database.SqliteServerUnban", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("unban_id")
.HasColumnType("INTEGER");
b.Property<int>("BanId")
.HasColumnName("ban_id")
.HasColumnType("INTEGER");
b.Property<DateTime>("UnbanTime")
.HasColumnName("unban_time")
.HasColumnType("TEXT");
b.Property<Guid?>("UnbanningAdmin")
.HasColumnName("unbanning_admin")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("BanId")
.IsUnique();
b.ToTable("unban");
});
modelBuilder.Entity("Content.Server.Database.Antag", b =>
{
b.HasOne("Content.Server.Database.Profile", "Profile")
.WithMany("Antags")
.HasForeignKey("ProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
{
b.HasOne("Content.Server.Database.Profile", "Profile")
.WithMany("Jobs")
.HasForeignKey("ProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.Profile", b =>
{
b.HasOne("Content.Server.Database.Preference", "Preference")
.WithMany("Profiles")
.HasForeignKey("PreferenceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Content.Server.Database.SqliteServerUnban", b =>
{
b.HasOne("Content.Server.Database.SqliteServerBan", "Ban")
.WithOne("Unban")
.HasForeignKey("Content.Server.Database.SqliteServerUnban", "BanId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,42 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Content.Server.Database
{
public class PostgresPreferencesDbContext : PreferencesDbContext
{
// This is used by the "dotnet ef" CLI tool.
public PostgresPreferencesDbContext()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if(!InitializedWithOptions)
options.UseNpgsql("dummy connection string");
}
public PostgresPreferencesDbContext(DbContextOptions<PreferencesDbContext> options) : base(options)
{
}
}
public class SqlitePreferencesDbContext : PreferencesDbContext
{
public SqlitePreferencesDbContext()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (!InitializedWithOptions)
options.UseSqlite("dummy connection string");
}
public SqlitePreferencesDbContext(DbContextOptions<PreferencesDbContext> options) : base(options)
{
}
}
public abstract class PreferencesDbContext : DbContext
public abstract class ServerDbContext : DbContext
{
/// <summary>
/// The "dotnet ef" CLI tool uses the parameter-less constructor.
@@ -44,70 +13,86 @@ namespace Content.Server.Database
/// To use the context within the application, the options need to be passed the constructor instead.
/// </summary>
protected readonly bool InitializedWithOptions;
public PreferencesDbContext()
public ServerDbContext()
{
}
public PreferencesDbContext(DbContextOptions<PreferencesDbContext> options) : base(options)
public ServerDbContext(DbContextOptions<ServerDbContext> options) : base(options)
{
InitializedWithOptions = true;
}
public DbSet<Prefs> Preferences { get; set; } = null!;
public DbSet<HumanoidProfile> HumanoidProfile { get; set; } = null!;
public DbSet<Preference> Preference { get; set; } = null!;
public DbSet<Profile> Profile { get; set; } = null!;
public DbSet<AssignedUserId> AssignedUserId { get; set; } = null!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Prefs>()
.HasIndex(p => p.Username)
modelBuilder.Entity<Preference>()
.HasIndex(p => p.UserId)
.IsUnique();
modelBuilder.Entity<HumanoidProfile>()
.HasIndex(p => new {p.Slot, p.PrefsId})
modelBuilder.Entity<Profile>()
.HasIndex(p => new {p.Slot, PrefsId = p.PreferenceId})
.IsUnique();
modelBuilder.Entity<Antag>()
.HasIndex(p => new {p.HumanoidProfileId , p.AntagName})
.HasIndex(p => new {HumanoidProfileId = p.ProfileId, p.AntagName})
.IsUnique();
modelBuilder.Entity<AssignedUserId>()
.HasIndex(p => p.UserName)
.IsUnique();
// Can't have two usernames with the same user ID.
modelBuilder.Entity<AssignedUserId>()
.HasIndex(p => p.UserId)
.IsUnique();
}
}
public class Prefs
[Table("preference")]
public class Preference
{
public int PrefsId { get; set; }
public string Username { get; set; } = null!;
public int SelectedCharacterSlot { get; set; }
public List<HumanoidProfile> HumanoidProfiles { get; } = new List<HumanoidProfile>();
[Column("preference_id")] public int Id { get; set; }
[Column("user_id")] public Guid UserId { get; set; }
[Column("selected_character_slot")] public int SelectedCharacterSlot { get; set; }
public List<Profile> Profiles { get; } = new List<Profile>();
}
public class HumanoidProfile
[Table("profile")]
public class Profile
{
public int HumanoidProfileId { get; set; }
public int Slot { get; set; }
public string SlotName { get; set; } = null!;
public string CharacterName { get; set; } = null!;
public int Age { get; set; }
public string Sex { get; set; } = null!;
public string HairName { get; set; } = null!;
public string HairColor { get; set; } = null!;
public string FacialHairName { get; set; } = null!;
public string FacialHairColor { get; set; } = null!;
public string EyeColor { get; set; } = null!;
public string SkinColor { get; set; } = null!;
[Column("profile_id")] public int Id { get; set; }
[Column("slot")] public int Slot { get; set; }
[Column("char_name")] public string CharacterName { get; set; } = null!;
[Column("age")] public int Age { get; set; }
[Column("sex")] public string Sex { get; set; } = null!;
[Column("hair_name")] public string HairName { get; set; } = null!;
[Column("hair_color")] public string HairColor { get; set; } = null!;
[Column("facial_hair_name")] public string FacialHairName { get; set; } = null!;
[Column("facial_hair_color")] public string FacialHairColor { get; set; } = null!;
[Column("eye_color")] public string EyeColor { get; set; } = null!;
[Column("skin_color")] public string SkinColor { get; set; } = null!;
public List<Job> Jobs { get; } = new List<Job>();
public List<Antag> Antags { get; } = new List<Antag>();
public DbPreferenceUnavailableMode PreferenceUnavailable { get; set; }
public int PrefsId { get; set; }
public Prefs Prefs { get; set; } = null!;
[Column("pref_unavailable")] public DbPreferenceUnavailableMode PreferenceUnavailable { get; set; }
[Column("preference_id")] public int PreferenceId { get; set; }
public Preference Preference { get; set; } = null!;
}
[Table("job")]
public class Job
{
public int JobId { get; set; }
public HumanoidProfile Profile { get; set; } = null!;
[Column("job_id")] public int Id { get; set; }
public Profile Profile { get; set; } = null!;
[Column("profile_id")] public int ProfileId { get; set; }
public string JobName { get; set; } = null!;
public DbJobPriority Priority { get; set; }
[Column("job_name")] public string JobName { get; set; } = null!;
[Column("priority")] public DbJobPriority Priority { get; set; }
}
public enum DbJobPriority
@@ -119,13 +104,14 @@ namespace Content.Server.Database
High = 3
}
[Table("antag")]
public class Antag
{
public int AntagId { get; set; }
public HumanoidProfile Profile { get; set; } = null!;
public int HumanoidProfileId { get; set; }
[Column("antag_id")] public int Id { get; set; }
public Profile Profile { get; set; } = null!;
[Column("profile_id")] public int ProfileId { get; set; }
public string AntagName { get; set; } = null!;
[Column("antag_name")] public string AntagName { get; set; } = null!;
}
public enum DbPreferenceUnavailableMode
@@ -134,4 +120,13 @@ namespace Content.Server.Database
StayInLobby = 0,
SpawnAsOverflow,
}
[Table("assigned_user_id")]
public class AssignedUserId
{
[Column("assigned_user_id_id")] public int Id { get; set; }
[Column("user_name")] public string UserName { get; set; } = null!;
[Column("user_id")] public Guid UserId { get; set; }
}
}

View File

@@ -0,0 +1,144 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Net;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
namespace Content.Server.Database
{
public sealed class PostgresServerDbContext : ServerDbContext
{
// This is used by the "dotnet ef" CLI tool.
public PostgresServerDbContext()
{
}
public DbSet<PostgresServerBan> Ban { get; set; } = default!;
public DbSet<PostgresServerUnban> Unban { get; set; } = default!;
public DbSet<PostgresPlayer> Player { get; set; } = default!;
public DbSet<PostgresConnectionLog> ConnectionLog { get; set; } = default!;
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (!InitializedWithOptions)
options.UseNpgsql("dummy connection string");
options.ReplaceService<IRelationalTypeMappingSource, CustomNpgsqlTypeMappingSource>();
}
public PostgresServerDbContext(DbContextOptions<ServerDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<PostgresServerBan>()
.HasIndex(p => p.UserId);
modelBuilder.Entity<PostgresServerBan>()
.HasIndex(p => p.Address);
modelBuilder.Entity<PostgresServerBan>()
.HasIndex(p => p.UserId);
modelBuilder.Entity<PostgresServerUnban>()
.HasIndex(p => p.BanId)
.IsUnique();
// ReSharper disable once CommentTypo
// ReSharper disable once StringLiteralTypo
// Enforce that an address cannot be IPv6-mapped IPv4.
// So that IPv4 addresses are consistent between separate-socket and dual-stack socket modes.
modelBuilder.Entity<PostgresServerBan>()
.HasCheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address")
.HasCheckConstraint("HaveEitherAddressOrUserId", "address IS NOT NULL OR user_id IS NOT NULL");
modelBuilder.Entity<PostgresPlayer>()
.HasIndex(p => p.UserId)
.IsUnique();
// ReSharper disable once StringLiteralTypo
modelBuilder.Entity<PostgresPlayer>()
.HasCheckConstraint("LastSeenAddressNotIPv6MappedIPv4",
"NOT inet '::ffff:0.0.0.0/96' >>= last_seen_address");
modelBuilder.Entity<PostgresConnectionLog>()
.HasIndex(p => p.UserId);
modelBuilder.Entity<PostgresConnectionLog>()
.HasCheckConstraint("AddressNotIPv6MappedIPv4",
"NOT inet '::ffff:0.0.0.0/96' >>= address");
}
}
[Table("server_ban")]
public class PostgresServerBan
{
[Column("server_ban_id")] public int Id { get; set; }
[Column("user_id")] public Guid? UserId { get; set; }
[Column("address", TypeName = "inet")] public (IPAddress, int)? Address { get; set; }
[Column("ban_time", TypeName = "timestamp with time zone")]
public DateTime BanTime { get; set; }
[Column("expiration_time", TypeName = "timestamp with time zone")]
public DateTime? ExpirationTime { get; set; }
[Column("reason")] public string Reason { get; set; } = null!;
[Column("banning_admin")] public Guid? BanningAdmin { get; set; }
public PostgresServerUnban? Unban { get; set; }
}
[Table("server_unban")]
public class PostgresServerUnban
{
[Column("unban_id")] public int Id { get; set; }
[Column("ban_id")] public int BanId { get; set; }
[Column("ban")] public PostgresServerBan Ban { get; set; } = null!;
[Column("unbanning_admin")] public Guid? UnbanningAdmin { get; set; }
[Column("unban_time", TypeName = "timestamp with time zone")]
public DateTime UnbanTime { get; set; }
}
[Table("player")]
public class PostgresPlayer
{
[Column("player_id")] public int Id { get; set; }
// Permanent data
[Column("user_id")] public Guid UserId { get; set; }
[Column("first_seen_time", TypeName = "timestamp with time zone")]
public DateTime FirstSeenTime { get; set; }
// Data that gets updated on each join.
[Column("last_seen_user_name")] public string LastSeenUserName { get; set; } = null!;
[Column("last_seen_time", TypeName = "timestamp with time zone")]
public DateTime LastSeenTime { get; set; }
[Column("last_seen_address")] public IPAddress LastSeenAddress { get; set; } = null!;
}
[Table("connection_log")]
public class PostgresConnectionLog
{
[Column("connection_log_id")] public int Id { get; set; }
[Column("user_id")] public Guid UserId { get; set; }
[Column("user_name")] public string UserName { get; set; } = null!;
[Column("time", TypeName = "timestamp with time zone")]
public DateTime Time { get; set; }
[Column("address")] public IPAddress Address { get; set; } = null!;
}
}

View File

@@ -0,0 +1,82 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Content.Server.Database
{
public sealed class SqliteServerDbContext : ServerDbContext
{
public DbSet<SqliteServerBan> Ban { get; set; } = default!;
public DbSet<SqliteServerUnban> Unban { get; set; } = default!;
public DbSet<SqlitePlayer> Player { get; set; } = default!;
public DbSet<SqliteConnectionLog> ConnectionLog { get; set; } = default!;
public SqliteServerDbContext()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (!InitializedWithOptions)
options.UseSqlite("dummy connection string");
}
public SqliteServerDbContext(DbContextOptions<ServerDbContext> options) : base(options)
{
}
}
[Table("ban")]
public class SqliteServerBan
{
[Column("ban_id")] public int Id { get; set; }
[Column("user_id")] public Guid? UserId { get; set; }
[Column("address")] public string? Address { get; set; }
[Column("ban_time")] public DateTime BanTime { get; set; }
[Column("expiration_time")] public DateTime? ExpirationTime { get; set; }
[Column("reason")] public string Reason { get; set; } = null!;
[Column("banning_admin")] public Guid? BanningAdmin { get; set; }
public SqliteServerUnban? Unban { get; set; }
}
[Table("unban")]
public class SqliteServerUnban
{
[Column("unban_id")] public int Id { get; set; }
[Column("ban_id")] public int BanId { get; set; }
public SqliteServerBan Ban { get; set; } = null!;
[Column("unbanning_admin")] public Guid? UnbanningAdmin { get; set; }
[Column("unban_time")] public DateTime UnbanTime { get; set; }
}
[Table("player")]
public class SqlitePlayer
{
[Column("player_id")] public int Id { get; set; }
// Permanent data
[Column("user_id")] public Guid UserId { get; set; }
[Column("first_seen_time")] public DateTime FirstSeenTime { get; set; }
// Data that gets updated on each join.
[Column("last_seen_user_name")] public string LastSeenUserName { get; set; } = null!;
[Column("last_seen_time")] public DateTime LastSeenTime { get; set; }
[Column("last_seen_address")] public string LastSeenAddress { get; set; } = null!;
}
[Table("connection_log")]
public class SqliteConnectionLog
{
[Column("connection_log_id")] public int Id { get; set; }
[Column("user_id")] public Guid UserId { get; set; }
[Column("user_name")] public string UserName { get; set; } = null!;
[Column("time")] public DateTime Time { get; set; }
[Column("address")] public string Address { get; set; } = null!;
}
}

View File

@@ -0,0 +1,68 @@
using System.Linq.Expressions;
using System.Net;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Storage;
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping;
namespace Content.Server.Database
{
// Taken from https://github.com/npgsql/efcore.pg/issues/1158
// To support inet -> (IPAddress, int) mapping.
#pragma warning disable EF1001
public class CustomNpgsqlTypeMappingSource : NpgsqlTypeMappingSource
#pragma warning restore EF1001
{
public CustomNpgsqlTypeMappingSource(
TypeMappingSourceDependencies dependencies,
RelationalTypeMappingSourceDependencies relationalDependencies,
ISqlGenerationHelper sqlGenerationHelper,
INpgsqlOptions? npgsqlOptions = null)
: base(dependencies, relationalDependencies, sqlGenerationHelper, npgsqlOptions)
{
StoreTypeMappings["inet"] =
new RelationalTypeMapping[]
{
new NpgsqlInetWithMaskTypeMapping(),
new NpgsqlInetTypeMapping()
};
}
}
// Basically copied from NpgsqlCidrTypeMapping
public class NpgsqlInetWithMaskTypeMapping : NpgsqlTypeMapping
{
public NpgsqlInetWithMaskTypeMapping() : base("inet", typeof((IPAddress, int)), NpgsqlTypes.NpgsqlDbType.Inet)
{
}
protected NpgsqlInetWithMaskTypeMapping(RelationalTypeMappingParameters parameters)
: base(parameters, NpgsqlTypes.NpgsqlDbType.Inet)
{
}
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters)
=> new NpgsqlInetWithMaskTypeMapping(parameters);
protected override string GenerateNonNullSqlLiteral(object value)
{
var cidr = ((IPAddress Address, int Subnet)) value;
return $"INET '{cidr.Address}/{cidr.Subnet}'";
}
public override Expression GenerateCodeLiteral(object value)
{
var cidr = ((IPAddress Address, int Subnet)) value;
return Expression.New(
Constructor,
Expression.Call(ParseMethod, Expression.Constant(cidr.Address.ToString())),
Expression.Constant(cidr.Subnet));
}
static readonly MethodInfo ParseMethod = typeof(IPAddress).GetMethod("Parse", new[] {typeof(string)})!;
static readonly ConstructorInfo Constructor =
typeof((IPAddress, int)).GetConstructor(new[] {typeof(IPAddress), typeof(int)})!;
}
}

View File

@@ -1,84 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace Content.Server.Database
{
public class PrefsDb
{
private readonly PreferencesDbContext _prefsCtx;
public PrefsDb(IDatabaseConfiguration dbConfig)
{
_prefsCtx = dbConfig switch
{
SqliteConfiguration sqlite => (PreferencesDbContext) new SqlitePreferencesDbContext(
sqlite.Options),
PostgresConfiguration postgres => new PostgresPreferencesDbContext(postgres.Options),
_ => throw new NotImplementedException()
};
_prefsCtx.Database.Migrate();
}
public async Task<Prefs?> GetPlayerPreferences(string username)
{
return await _prefsCtx
.Preferences
.Include(p => p.HumanoidProfiles).ThenInclude(h => h.Jobs)
.Include(p => p.HumanoidProfiles).ThenInclude(h => h.Antags)
.SingleOrDefaultAsync(p => p.Username == username);
}
public async Task SaveSelectedCharacterIndex(string username, int slot)
{
var prefs = _prefsCtx.Preferences.SingleOrDefault(p => p.Username == username);
if (prefs is null)
_prefsCtx.Preferences.Add(new Prefs
{
Username = username,
SelectedCharacterSlot = slot
});
else
prefs.SelectedCharacterSlot = slot;
await _prefsCtx.SaveChangesAsync();
}
public async Task SaveCharacterSlotAsync(string username, HumanoidProfile newProfile)
{
var prefs = _prefsCtx
.Preferences
.Single(p => p.Username == username);
var oldProfile = prefs
.HumanoidProfiles
.SingleOrDefault(h => h.Slot == newProfile.Slot);
if (!(oldProfile is null)) prefs.HumanoidProfiles.Remove(oldProfile);
prefs.HumanoidProfiles.Add(newProfile);
await _prefsCtx.SaveChangesAsync();
}
public async Task DeleteCharacterSlotAsync(string username, int slot)
{
var profile = _prefsCtx
.Preferences
.Single(p => p.Username == username)
.HumanoidProfiles
.RemoveAll(h => h.Slot == slot);
await _prefsCtx.SaveChangesAsync();
}
public async Task<Dictionary<string, HumanoidProfile>> GetProfilesForPlayersAsync(List<string> usernames)
{
return await _prefsCtx.HumanoidProfile
.Include(p => p.Jobs)
.Include(a => a.Antags)
.Join(_prefsCtx.Preferences,
profile => new {profile.Slot, profile.PrefsId},
prefs => new {Slot = prefs.SelectedCharacterSlot, prefs.PrefsId},
(profile, prefs) => new {prefs.Username, profile})
.Where(p => usernames.Contains(p.Username))
.ToDictionaryAsync(arg => arg.Username, arg => arg.profile);
}
}
}

View File

@@ -0,0 +1,12 @@
#!/usr/bin/env pwsh
param([String]$name)
if ($name -eq "")
{
Write-Error "must specify migration name"
exit
}
dotnet ef migrations add --context SqliteServerDbContext -o Migrations/Sqlite $name
dotnet ef migrations add --context PostgresServerDbContext -o Migrations/Postgres $name