diff --git a/CentCom.Common/CentCom.Common.csproj b/CentCom.Common/CentCom.Common.csproj index d74378e..a6266b7 100644 --- a/CentCom.Common/CentCom.Common.csproj +++ b/CentCom.Common/CentCom.Common.csproj @@ -1,10 +1,11 @@ - + netstandard2.0 + diff --git a/CentCom.Common/Data/NpgsqlDbContext.cs b/CentCom.Common/Data/NpgsqlDbContext.cs index ccc8cea..4c0dcfe 100644 --- a/CentCom.Common/Data/NpgsqlDbContext.cs +++ b/CentCom.Common/Data/NpgsqlDbContext.cs @@ -12,7 +12,8 @@ public NpgsqlDbContext(IConfiguration configuration) : base(configuration) protected override void OnConfiguring(DbContextOptionsBuilder options) { - options.UseNpgsql(Configuration.GetSection("dbConfig")["connectionString"]); + options.UseNpgsql(Configuration.GetSection("dbConfig")["connectionString"]) + .UseSnakeCaseNamingConvention(); } } } diff --git a/CentCom.Common/Migrations/Postgres/20200730054811_AddSnakeCaseNamingConvention.Designer.cs b/CentCom.Common/Migrations/Postgres/20200730054811_AddSnakeCaseNamingConvention.Designer.cs new file mode 100644 index 0000000..7786b65 --- /dev/null +++ b/CentCom.Common/Migrations/Postgres/20200730054811_AddSnakeCaseNamingConvention.Designer.cs @@ -0,0 +1,158 @@ +// +using System; +using System.Net; +using CentCom.Common.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace CentCom.Common.Migrations.Postgres +{ + [DbContext(typeof(NpgsqlDbContext))] + [Migration("20200730054811_AddSnakeCaseNamingConvention")] + partial class AddSnakeCaseNamingConvention + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + .HasAnnotation("ProductVersion", "3.1.6") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + modelBuilder.Entity("CentCom.Common.Models.Ban", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnName("id") + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn); + + b.Property("BanID") + .HasColumnName("ban_id") + .HasColumnType("text"); + + b.Property("BanType") + .HasColumnName("ban_type") + .HasColumnType("bigint"); + + b.Property("BannedBy") + .IsRequired() + .HasColumnName("banned_by") + .HasColumnType("character varying(32)") + .HasMaxLength(32); + + b.Property("BannedOn") + .HasColumnName("banned_on") + .HasColumnType("timestamp without time zone"); + + b.Property("CID") + .HasColumnName("cid") + .HasColumnType("bigint"); + + b.Property("CKey") + .IsRequired() + .HasColumnName("c_key") + .HasColumnType("character varying(32)") + .HasMaxLength(32); + + b.Property("Expires") + .HasColumnName("expires") + .HasColumnType("timestamp without time zone"); + + b.Property("IP") + .HasColumnName("ip") + .HasColumnType("inet"); + + b.Property("Reason") + .HasColumnName("reason") + .HasColumnType("text"); + + b.Property("Source") + .HasColumnName("source") + .HasColumnType("integer"); + + b.Property("UnbannedBy") + .HasColumnName("unbanned_by") + .HasColumnType("character varying(32)") + .HasMaxLength(32); + + b.HasKey("Id") + .HasName("pk_bans"); + + b.HasIndex("CKey") + .HasName("ix_bans_c_key"); + + b.HasIndex("Source") + .HasName("ix_bans_source"); + + b.ToTable("bans"); + }); + + modelBuilder.Entity("CentCom.Common.Models.BanSource", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnName("id") + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn); + + b.Property("Display") + .HasColumnName("display") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnName("name") + .HasColumnType("text"); + + b.Property("RoleplayLevel") + .HasColumnName("roleplay_level") + .HasColumnType("bigint"); + + b.HasKey("Id") + .HasName("pk_ban_sources"); + + b.ToTable("ban_sources"); + }); + + modelBuilder.Entity("CentCom.Common.Models.JobBan", b => + { + b.Property("BanId") + .HasColumnName("ban_id") + .HasColumnType("integer"); + + b.Property("Job") + .HasColumnName("job") + .HasColumnType("text"); + + b.HasKey("BanId", "Job") + .HasName("pk_job_bans"); + + b.ToTable("job_bans"); + }); + + modelBuilder.Entity("CentCom.Common.Models.Ban", b => + { + b.HasOne("CentCom.Common.Models.BanSource", "SourceNavigation") + .WithMany("Bans") + .HasForeignKey("Source") + .HasConstraintName("fk_bans_ban_sources_source_navigation_id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CentCom.Common.Models.JobBan", b => + { + b.HasOne("CentCom.Common.Models.Ban", "BanNavigation") + .WithMany("JobBans") + .HasForeignKey("BanId") + .HasConstraintName("fk_job_bans_bans_ban_id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CentCom.Common/Migrations/Postgres/20200730054811_AddSnakeCaseNamingConvention.cs b/CentCom.Common/Migrations/Postgres/20200730054811_AddSnakeCaseNamingConvention.cs new file mode 100644 index 0000000..b5f087e --- /dev/null +++ b/CentCom.Common/Migrations/Postgres/20200730054811_AddSnakeCaseNamingConvention.cs @@ -0,0 +1,339 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace CentCom.Common.Migrations.Postgres +{ + public partial class AddSnakeCaseNamingConvention : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Bans_BanSources_Source", + table: "Bans"); + + migrationBuilder.DropForeignKey( + name: "FK_JobBans_Bans_BanId", + table: "JobBans"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Bans", + table: "Bans"); + + migrationBuilder.DropPrimaryKey( + name: "PK_JobBans", + table: "JobBans"); + + migrationBuilder.DropPrimaryKey( + name: "PK_BanSources", + table: "BanSources"); + + migrationBuilder.RenameTable( + name: "Bans", + newName: "bans"); + + migrationBuilder.RenameTable( + name: "JobBans", + newName: "job_bans"); + + migrationBuilder.RenameTable( + name: "BanSources", + newName: "ban_sources"); + + migrationBuilder.RenameColumn( + name: "Source", + table: "bans", + newName: "source"); + + migrationBuilder.RenameColumn( + name: "Reason", + table: "bans", + newName: "reason"); + + migrationBuilder.RenameColumn( + name: "IP", + table: "bans", + newName: "ip"); + + migrationBuilder.RenameColumn( + name: "Expires", + table: "bans", + newName: "expires"); + + migrationBuilder.RenameColumn( + name: "CID", + table: "bans", + newName: "cid"); + + migrationBuilder.RenameColumn( + name: "Id", + table: "bans", + newName: "id"); + + migrationBuilder.RenameColumn( + name: "UnbannedBy", + table: "bans", + newName: "unbanned_by"); + + migrationBuilder.RenameColumn( + name: "CKey", + table: "bans", + newName: "c_key"); + + migrationBuilder.RenameColumn( + name: "BannedOn", + table: "bans", + newName: "banned_on"); + + migrationBuilder.RenameColumn( + name: "BannedBy", + table: "bans", + newName: "banned_by"); + + migrationBuilder.RenameColumn( + name: "BanType", + table: "bans", + newName: "ban_type"); + + migrationBuilder.RenameColumn( + name: "BanID", + table: "bans", + newName: "ban_id"); + + migrationBuilder.RenameIndex( + name: "IX_Bans_Source", + table: "bans", + newName: "ix_bans_source"); + + migrationBuilder.RenameIndex( + name: "IX_Bans_CKey", + table: "bans", + newName: "ix_bans_c_key"); + + migrationBuilder.RenameColumn( + name: "Job", + table: "job_bans", + newName: "job"); + + migrationBuilder.RenameColumn( + name: "BanId", + table: "job_bans", + newName: "ban_id"); + + migrationBuilder.RenameColumn( + name: "Name", + table: "ban_sources", + newName: "name"); + + migrationBuilder.RenameColumn( + name: "Display", + table: "ban_sources", + newName: "display"); + + migrationBuilder.RenameColumn( + name: "Id", + table: "ban_sources", + newName: "id"); + + migrationBuilder.RenameColumn( + name: "RoleplayLevel", + table: "ban_sources", + newName: "roleplay_level"); + + migrationBuilder.AddPrimaryKey( + name: "pk_bans", + table: "bans", + column: "id"); + + migrationBuilder.AddPrimaryKey( + name: "pk_job_bans", + table: "job_bans", + columns: new[] { "ban_id", "job" }); + + migrationBuilder.AddPrimaryKey( + name: "pk_ban_sources", + table: "ban_sources", + column: "id"); + + migrationBuilder.AddForeignKey( + name: "fk_bans_ban_sources_source_navigation_id", + table: "bans", + column: "source", + principalTable: "ban_sources", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "fk_job_bans_bans_ban_id", + table: "job_bans", + column: "ban_id", + principalTable: "bans", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "fk_bans_ban_sources_source_navigation_id", + table: "bans"); + + migrationBuilder.DropForeignKey( + name: "fk_job_bans_bans_ban_id", + table: "job_bans"); + + migrationBuilder.DropPrimaryKey( + name: "pk_bans", + table: "bans"); + + migrationBuilder.DropPrimaryKey( + name: "pk_job_bans", + table: "job_bans"); + + migrationBuilder.DropPrimaryKey( + name: "pk_ban_sources", + table: "ban_sources"); + + migrationBuilder.RenameTable( + name: "bans", + newName: "Bans"); + + migrationBuilder.RenameTable( + name: "job_bans", + newName: "JobBans"); + + migrationBuilder.RenameTable( + name: "ban_sources", + newName: "BanSources"); + + migrationBuilder.RenameColumn( + name: "source", + table: "Bans", + newName: "Source"); + + migrationBuilder.RenameColumn( + name: "reason", + table: "Bans", + newName: "Reason"); + + migrationBuilder.RenameColumn( + name: "ip", + table: "Bans", + newName: "IP"); + + migrationBuilder.RenameColumn( + name: "expires", + table: "Bans", + newName: "Expires"); + + migrationBuilder.RenameColumn( + name: "cid", + table: "Bans", + newName: "CID"); + + migrationBuilder.RenameColumn( + name: "id", + table: "Bans", + newName: "Id"); + + migrationBuilder.RenameColumn( + name: "unbanned_by", + table: "Bans", + newName: "UnbannedBy"); + + migrationBuilder.RenameColumn( + name: "c_key", + table: "Bans", + newName: "CKey"); + + migrationBuilder.RenameColumn( + name: "banned_on", + table: "Bans", + newName: "BannedOn"); + + migrationBuilder.RenameColumn( + name: "banned_by", + table: "Bans", + newName: "BannedBy"); + + migrationBuilder.RenameColumn( + name: "ban_type", + table: "Bans", + newName: "BanType"); + + migrationBuilder.RenameColumn( + name: "ban_id", + table: "Bans", + newName: "BanID"); + + migrationBuilder.RenameIndex( + name: "ix_bans_source", + table: "Bans", + newName: "IX_Bans_Source"); + + migrationBuilder.RenameIndex( + name: "ix_bans_c_key", + table: "Bans", + newName: "IX_Bans_CKey"); + + migrationBuilder.RenameColumn( + name: "job", + table: "JobBans", + newName: "Job"); + + migrationBuilder.RenameColumn( + name: "ban_id", + table: "JobBans", + newName: "BanId"); + + migrationBuilder.RenameColumn( + name: "name", + table: "BanSources", + newName: "Name"); + + migrationBuilder.RenameColumn( + name: "display", + table: "BanSources", + newName: "Display"); + + migrationBuilder.RenameColumn( + name: "id", + table: "BanSources", + newName: "Id"); + + migrationBuilder.RenameColumn( + name: "roleplay_level", + table: "BanSources", + newName: "RoleplayLevel"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Bans", + table: "Bans", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_JobBans", + table: "JobBans", + columns: new[] { "BanId", "Job" }); + + migrationBuilder.AddPrimaryKey( + name: "PK_BanSources", + table: "BanSources", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Bans_BanSources_Source", + table: "Bans", + column: "Source", + principalTable: "BanSources", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_JobBans_Bans_BanId", + table: "JobBans", + column: "BanId", + principalTable: "Bans", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/CentCom.Common/Migrations/Postgres/NpgsqlDbContextModelSnapshot.cs b/CentCom.Common/Migrations/Postgres/NpgsqlDbContextModelSnapshot.cs index 9e4921a..3e505fd 100644 --- a/CentCom.Common/Migrations/Postgres/NpgsqlDbContextModelSnapshot.cs +++ b/CentCom.Common/Migrations/Postgres/NpgsqlDbContextModelSnapshot.cs @@ -24,88 +24,111 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() + .HasColumnName("id") .HasColumnType("integer") .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn); b.Property("BanID") + .HasColumnName("ban_id") .HasColumnType("text"); b.Property("BanType") + .HasColumnName("ban_type") .HasColumnType("bigint"); b.Property("BannedBy") .IsRequired() + .HasColumnName("banned_by") .HasColumnType("character varying(32)") .HasMaxLength(32); b.Property("BannedOn") + .HasColumnName("banned_on") .HasColumnType("timestamp without time zone"); b.Property("CID") + .HasColumnName("cid") .HasColumnType("bigint"); b.Property("CKey") .IsRequired() + .HasColumnName("c_key") .HasColumnType("character varying(32)") .HasMaxLength(32); b.Property("Expires") + .HasColumnName("expires") .HasColumnType("timestamp without time zone"); b.Property("IP") + .HasColumnName("ip") .HasColumnType("inet"); b.Property("Reason") + .HasColumnName("reason") .HasColumnType("text"); b.Property("Source") + .HasColumnName("source") .HasColumnType("integer"); b.Property("UnbannedBy") + .HasColumnName("unbanned_by") .HasColumnType("character varying(32)") .HasMaxLength(32); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_bans"); - b.HasIndex("CKey"); + b.HasIndex("CKey") + .HasName("ix_bans_c_key"); - b.HasIndex("Source"); + b.HasIndex("Source") + .HasName("ix_bans_source"); - b.ToTable("Bans"); + b.ToTable("bans"); }); modelBuilder.Entity("CentCom.Common.Models.BanSource", b => { b.Property("Id") .ValueGeneratedOnAdd() + .HasColumnName("id") .HasColumnType("integer") .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn); b.Property("Display") + .HasColumnName("display") .HasColumnType("text"); b.Property("Name") + .HasColumnName("name") .HasColumnType("text"); b.Property("RoleplayLevel") + .HasColumnName("roleplay_level") .HasColumnType("bigint"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_ban_sources"); - b.ToTable("BanSources"); + b.ToTable("ban_sources"); }); modelBuilder.Entity("CentCom.Common.Models.JobBan", b => { b.Property("BanId") + .HasColumnName("ban_id") .HasColumnType("integer"); b.Property("Job") + .HasColumnName("job") .HasColumnType("text"); - b.HasKey("BanId", "Job"); + b.HasKey("BanId", "Job") + .HasName("pk_job_bans"); - b.ToTable("JobBans"); + b.ToTable("job_bans"); }); modelBuilder.Entity("CentCom.Common.Models.Ban", b => @@ -113,6 +136,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("CentCom.Common.Models.BanSource", "SourceNavigation") .WithMany("Bans") .HasForeignKey("Source") + .HasConstraintName("fk_bans_ban_sources_source_navigation_id") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); @@ -122,6 +146,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("CentCom.Common.Models.Ban", "BanNavigation") .WithMany("JobBans") .HasForeignKey("BanId") + .HasConstraintName("fk_job_bans_bans_ban_id") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); });