Update EF Core; create migration for previous commit

This commit is contained in:
Noi 2022-12-03 18:09:48 -08:00
parent 3dd252c353
commit b76d45a271
4 changed files with 468 additions and 25 deletions

View file

@ -0,0 +1,236 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using RegexBot.Data;
#nullable disable
namespace RegexBot.Data.Migrations
{
[DbContext(typeof(BotDatabaseContext))]
[Migration("20221204014949_LongToUlong")]
partial class LongToUlong
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "mod_log_type", new[] { "other", "note", "warn", "timeout", "kick", "ban" });
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("RegexBot.Data.CachedGuildMessage", b =>
{
b.Property<decimal>("MessageId")
.HasColumnType("numeric(20,0)")
.HasColumnName("message_id");
b.Property<List<string>>("AttachmentNames")
.IsRequired()
.HasColumnType("text[]")
.HasColumnName("attachment_names");
b.Property<decimal>("AuthorId")
.HasColumnType("numeric(20,0)")
.HasColumnName("author_id");
b.Property<decimal>("ChannelId")
.HasColumnType("numeric(20,0)")
.HasColumnName("channel_id");
b.Property<string>("Content")
.HasColumnType("text")
.HasColumnName("content");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("now()");
b.Property<DateTimeOffset?>("EditedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("edited_at");
b.Property<decimal>("GuildId")
.HasColumnType("numeric(20,0)")
.HasColumnName("guild_id");
b.HasKey("MessageId")
.HasName("pk_cache_guildmessages");
b.HasIndex("AuthorId")
.HasDatabaseName("ix_cache_guildmessages_author_id");
b.ToTable("cache_guildmessages", (string)null);
});
modelBuilder.Entity("RegexBot.Data.CachedGuildUser", b =>
{
b.Property<decimal>("GuildId")
.HasColumnType("numeric(20,0)")
.HasColumnName("guild_id");
b.Property<decimal>("UserId")
.HasColumnType("numeric(20,0)")
.HasColumnName("user_id");
b.Property<DateTimeOffset>("FirstSeenTime")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("first_seen_time")
.HasDefaultValueSql("now()");
b.Property<DateTimeOffset>("GULastUpdateTime")
.HasColumnType("timestamp with time zone")
.HasColumnName("gu_last_update_time");
b.Property<string>("Nickname")
.HasColumnType("text")
.HasColumnName("nickname");
b.HasKey("GuildId", "UserId")
.HasName("pk_cache_usersinguild");
b.HasIndex("UserId")
.HasDatabaseName("ix_cache_usersinguild_user_id");
b.ToTable("cache_usersinguild", (string)null);
});
modelBuilder.Entity("RegexBot.Data.CachedUser", b =>
{
b.Property<decimal>("UserId")
.HasColumnType("numeric(20,0)")
.HasColumnName("user_id");
b.Property<string>("AvatarUrl")
.HasColumnType("text")
.HasColumnName("avatar_url");
b.Property<string>("Discriminator")
.IsRequired()
.HasMaxLength(4)
.HasColumnType("character(4)")
.HasColumnName("discriminator")
.IsFixedLength();
b.Property<DateTimeOffset>("ULastUpdateTime")
.HasColumnType("timestamp with time zone")
.HasColumnName("u_last_update_time");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text")
.HasColumnName("username");
b.HasKey("UserId")
.HasName("pk_cache_users");
b.ToTable("cache_users", (string)null);
});
modelBuilder.Entity("RegexBot.Data.ModLogEntry", b =>
{
b.Property<int>("LogId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("log_id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("LogId"));
b.Property<decimal>("GuildId")
.HasColumnType("numeric(20,0)")
.HasColumnName("guild_id");
b.Property<string>("IssuedBy")
.IsRequired()
.HasColumnType("text")
.HasColumnName("issued_by");
b.Property<int>("LogType")
.HasColumnType("integer")
.HasColumnName("log_type");
b.Property<string>("Message")
.HasColumnType("text")
.HasColumnName("message");
b.Property<DateTimeOffset>("Timestamp")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("timestamp")
.HasDefaultValueSql("now()");
b.Property<decimal>("UserId")
.HasColumnType("numeric(20,0)")
.HasColumnName("user_id");
b.HasKey("LogId")
.HasName("pk_modlogs");
b.HasIndex("GuildId", "UserId")
.HasDatabaseName("ix_modlogs_guild_id_user_id");
b.ToTable("modlogs", (string)null);
});
modelBuilder.Entity("RegexBot.Data.CachedGuildMessage", b =>
{
b.HasOne("RegexBot.Data.CachedUser", "Author")
.WithMany("GuildMessages")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_cache_guildmessages_cache_users_author_id");
b.Navigation("Author");
});
modelBuilder.Entity("RegexBot.Data.CachedGuildUser", b =>
{
b.HasOne("RegexBot.Data.CachedUser", "User")
.WithMany("Guilds")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_cache_usersinguild_cache_users_user_id");
b.Navigation("User");
});
modelBuilder.Entity("RegexBot.Data.ModLogEntry", b =>
{
b.HasOne("RegexBot.Data.CachedGuildUser", "User")
.WithMany("Logs")
.HasForeignKey("GuildId", "UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_modlogs_cache_usersinguild_user_temp_id");
b.Navigation("User");
});
modelBuilder.Entity("RegexBot.Data.CachedGuildUser", b =>
{
b.Navigation("Logs");
});
modelBuilder.Entity("RegexBot.Data.CachedUser", b =>
{
b.Navigation("GuildMessages");
b.Navigation("Guilds");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,207 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace RegexBot.Data.Migrations
{
/// <inheritdoc />
public partial class LongToUlong : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
// NOTE: manually edited Up and Down - must drop and re-add foreign keys due to altered types
migrationBuilder.DropForeignKey(
name: "fk_modlogs_cache_usersinguild_user_temp_id",
table: "modlogs");
migrationBuilder.DropForeignKey(
name: "fk_cache_usersinguild_cache_users_user_id",
table: "cache_usersinguild");
migrationBuilder.AlterColumn<decimal>(
name: "user_id",
table: "modlogs",
type: "numeric(20,0)",
nullable: false,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.AlterColumn<decimal>(
name: "guild_id",
table: "modlogs",
type: "numeric(20,0)",
nullable: false,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.AlterColumn<decimal>(
name: "user_id",
table: "cache_usersinguild",
type: "numeric(20,0)",
nullable: false,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.AlterColumn<decimal>(
name: "guild_id",
table: "cache_usersinguild",
type: "numeric(20,0)",
nullable: false,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.AlterColumn<decimal>(
name: "user_id",
table: "cache_users",
type: "numeric(20,0)",
nullable: false,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.AlterColumn<decimal>(
name: "guild_id",
table: "cache_guildmessages",
type: "numeric(20,0)",
nullable: false,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.AlterColumn<decimal>(
name: "channel_id",
table: "cache_guildmessages",
type: "numeric(20,0)",
nullable: false,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.AlterColumn<decimal>(
name: "author_id",
table: "cache_guildmessages",
type: "numeric(20,0)",
nullable: false,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.AlterColumn<decimal>(
name: "message_id",
table: "cache_guildmessages",
type: "numeric(20,0)",
nullable: false,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.AddForeignKey(
name: "fk_modlogs_cache_usersinguild_user_temp_id",
table: "modlogs",
columns: new[] { "guild_id", "user_id" },
principalTable: "cache_usersinguild",
principalColumns: new[] { "guild_id", "user_id" },
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "fk_cache_usersinguild_cache_users_user_id",
table: "cache_usersinguild",
column: "user_id",
principalTable: "cache_users",
principalColumn: "user_id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "fk_modlogs_cache_usersinguild_user_temp_id",
table: "modlogs");
migrationBuilder.DropForeignKey(
name: "fk_cache_usersinguild_cache_users_user_id",
table: "cache_usersinguild");
migrationBuilder.AlterColumn<long>(
name: "user_id",
table: "modlogs",
type: "bigint",
nullable: false,
oldClrType: typeof(decimal),
oldType: "numeric(20,0)");
migrationBuilder.AlterColumn<long>(
name: "guild_id",
table: "modlogs",
type: "bigint",
nullable: false,
oldClrType: typeof(decimal),
oldType: "numeric(20,0)");
migrationBuilder.AlterColumn<long>(
name: "user_id",
table: "cache_usersinguild",
type: "bigint",
nullable: false,
oldClrType: typeof(decimal),
oldType: "numeric(20,0)");
migrationBuilder.AlterColumn<long>(
name: "guild_id",
table: "cache_usersinguild",
type: "bigint",
nullable: false,
oldClrType: typeof(decimal),
oldType: "numeric(20,0)");
migrationBuilder.AlterColumn<long>(
name: "user_id",
table: "cache_users",
type: "bigint",
nullable: false,
oldClrType: typeof(decimal),
oldType: "numeric(20,0)");
migrationBuilder.AlterColumn<long>(
name: "guild_id",
table: "cache_guildmessages",
type: "bigint",
nullable: false,
oldClrType: typeof(decimal),
oldType: "numeric(20,0)");
migrationBuilder.AlterColumn<long>(
name: "channel_id",
table: "cache_guildmessages",
type: "bigint",
nullable: false,
oldClrType: typeof(decimal),
oldType: "numeric(20,0)");
migrationBuilder.AlterColumn<long>(
name: "author_id",
table: "cache_guildmessages",
type: "bigint",
nullable: false,
oldClrType: typeof(decimal),
oldType: "numeric(20,0)");
migrationBuilder.AlterColumn<long>(
name: "message_id",
table: "cache_guildmessages",
type: "bigint",
nullable: false,
oldClrType: typeof(decimal),
oldType: "numeric(20,0)");
migrationBuilder.AddForeignKey(
name: "fk_modlogs_cache_usersinguild_user_temp_id",
table: "modlogs",
columns: new[] { "guild_id", "user_id" },
principalTable: "cache_usersinguild",
principalColumns: new[] { "guild_id", "user_id" },
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "fk_cache_usersinguild_cache_users_user_id",
table: "cache_usersinguild",
column: "user_id",
principalTable: "cache_users",
principalColumn: "user_id",
onDelete: ReferentialAction.Cascade);
}
}
}

View file

@ -18,7 +18,7 @@ namespace RegexBot.Data.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.7")
.HasAnnotation("ProductVersion", "7.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "mod_log_type", new[] { "other", "note", "warn", "timeout", "kick", "ban" });
@ -26,8 +26,8 @@ namespace RegexBot.Data.Migrations
modelBuilder.Entity("RegexBot.Data.CachedGuildMessage", b =>
{
b.Property<long>("MessageId")
.HasColumnType("bigint")
b.Property<decimal>("MessageId")
.HasColumnType("numeric(20,0)")
.HasColumnName("message_id");
b.Property<List<string>>("AttachmentNames")
@ -35,12 +35,12 @@ namespace RegexBot.Data.Migrations
.HasColumnType("text[]")
.HasColumnName("attachment_names");
b.Property<long>("AuthorId")
.HasColumnType("bigint")
b.Property<decimal>("AuthorId")
.HasColumnType("numeric(20,0)")
.HasColumnName("author_id");
b.Property<long>("ChannelId")
.HasColumnType("bigint")
b.Property<decimal>("ChannelId")
.HasColumnType("numeric(20,0)")
.HasColumnName("channel_id");
b.Property<string>("Content")
@ -57,8 +57,8 @@ namespace RegexBot.Data.Migrations
.HasColumnType("timestamp with time zone")
.HasColumnName("edited_at");
b.Property<long>("GuildId")
.HasColumnType("bigint")
b.Property<decimal>("GuildId")
.HasColumnType("numeric(20,0)")
.HasColumnName("guild_id");
b.HasKey("MessageId")
@ -72,12 +72,12 @@ namespace RegexBot.Data.Migrations
modelBuilder.Entity("RegexBot.Data.CachedGuildUser", b =>
{
b.Property<long>("GuildId")
.HasColumnType("bigint")
b.Property<decimal>("GuildId")
.HasColumnType("numeric(20,0)")
.HasColumnName("guild_id");
b.Property<long>("UserId")
.HasColumnType("bigint")
b.Property<decimal>("UserId")
.HasColumnType("numeric(20,0)")
.HasColumnName("user_id");
b.Property<DateTimeOffset>("FirstSeenTime")
@ -105,8 +105,8 @@ namespace RegexBot.Data.Migrations
modelBuilder.Entity("RegexBot.Data.CachedUser", b =>
{
b.Property<long>("UserId")
.HasColumnType("bigint")
b.Property<decimal>("UserId")
.HasColumnType("numeric(20,0)")
.HasColumnName("user_id");
b.Property<string>("AvatarUrl")
@ -144,8 +144,8 @@ namespace RegexBot.Data.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("LogId"));
b.Property<long>("GuildId")
.HasColumnType("bigint")
b.Property<decimal>("GuildId")
.HasColumnType("numeric(20,0)")
.HasColumnName("guild_id");
b.Property<string>("IssuedBy")
@ -167,8 +167,8 @@ namespace RegexBot.Data.Migrations
.HasColumnName("timestamp")
.HasDefaultValueSql("now()");
b.Property<long>("UserId")
.HasColumnType("bigint")
b.Property<decimal>("UserId")
.HasColumnType("numeric(20,0)")
.HasColumnName("user_id");
b.HasKey("LogId")

View file

@ -22,16 +22,16 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Discord.Net" Version="3.8.1" />
<PackageReference Include="EFCore.NamingConventions" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.7">
<PackageReference Include="EFCore.NamingConventions" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Npgsql" Version="6.0.7" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.7" />
<PackageReference Include="Npgsql" Version="7.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
</ItemGroup>