Skip to content

Commit

Permalink
Workaround for bogus tables generated by keyless entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakenVeina committed Feb 22, 2020
1 parent a34fce0 commit 6c80d44
Show file tree
Hide file tree
Showing 11 changed files with 1,198 additions and 143 deletions.
1,032 changes: 1,032 additions & 0 deletions Modix.Data/Migrations/20200222024643_RemoveBogusKeylessEntityTables.Designer.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Modix.Data.Migrations
{
public partial class RemoveBogusKeylessEntityTables : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
// EmojiStatsDto table was never actually create in any prior migration, even though the ModelSnapshots say it should be there.

// GuildEmojiStats table was never actually create in any prior migration, even though the ModelSnapshots say it should be there.

// GuildUserParticipationStatistics table was never actually create in any prior migration, even though the ModelSnapshots say it should be there.

migrationBuilder.DropTable(
name: "MessageCountByDate");

migrationBuilder.DropTable(
name: "MessageCountPerChannel");

// PerUserMessageCount table was never actually create in any prior migration, even though the ModelSnapshots say it should be there.

// SingleEmojiStatsDto table was never actually create in any prior migration, even though the ModelSnapshots say it should be there.
}

protected override void Down(MigrationBuilder migrationBuilder)
{
// EmojiStatsDto table was never actually create in any prior migration, even though the ModelSnapshots say it should be there.

// GuildEmojiStats table was never actually create in any prior migration, even though the ModelSnapshots say it should be there.

// GuildUserParticipationStatistics table was never actually create in any prior migration, even though the ModelSnapshots say it should be there.

migrationBuilder.CreateTable(
name: "MessageCountByDate",
columns: table => new
{
Date = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
MessageCount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
});

migrationBuilder.CreateTable(
name: "MessageCountPerChannel",
columns: table => new
{
ChannelId = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
ChannelName = table.Column<string>(type: "text", nullable: false),
MessageCount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
});

// PerUserMessageCount table was never actually create in any prior migration, even though the ModelSnapshots say it should be there.

// SingleEmojiStatsDto table was never actually create in any prior migration, even though the ModelSnapshots say it should be there.
}
}
}
130 changes: 0 additions & 130 deletions Modix.Data/Migrations/ModixContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,52 +259,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("GuildUsers");
});

modelBuilder.Entity("Modix.Data.Models.Core.GuildUserParticipationStatistics", b =>
{
b.Property<decimal>("AveragePerDay")
.HasColumnType("numeric");
b.Property<decimal>("GuildId")
.HasColumnType("numeric(20,0)");
b.Property<int>("Percentile")
.HasColumnType("integer");
b.Property<int>("Rank")
.HasColumnType("integer");
b.Property<decimal>("UserId")
.HasColumnType("numeric(20,0)");
b.ToTable("GuildUserParticipationStatistics");
});

modelBuilder.Entity("Modix.Data.Models.Core.MessageCountByDate", b =>
{
b.Property<DateTime>("Date")
.HasColumnType("timestamp without time zone");
b.Property<int>("MessageCount")
.HasColumnType("integer");
b.ToTable("MessageCountByDate");
});

modelBuilder.Entity("Modix.Data.Models.Core.MessageCountPerChannel", b =>
{
b.Property<decimal>("ChannelId")
.HasColumnType("numeric(20,0)");
b.Property<string>("ChannelName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("MessageCount")
.HasColumnType("integer");
b.ToTable("MessageCountPerChannel");
});

modelBuilder.Entity("Modix.Data.Models.Core.MessageEntity", b =>
{
b.Property<long>("Id")
Expand Down Expand Up @@ -336,28 +290,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Messages");
});

modelBuilder.Entity("Modix.Data.Models.Core.PerUserMessageCount", b =>
{
b.Property<string>("Discriminator")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsCurrentUser")
.HasColumnType("boolean");
b.Property<int>("MessageCount")
.HasColumnType("integer");
b.Property<int>("Rank")
.HasColumnType("integer");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.ToTable("PerUserMessageCount");
});

modelBuilder.Entity("Modix.Data.Models.Core.UserEntity", b =>
{
b.Property<long>("Id")
Expand Down Expand Up @@ -431,68 +363,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Emoji");
});

modelBuilder.Entity("Modix.Data.Models.Emoji.EmojiStatsDto", b =>
{
b.Property<decimal?>("EmojiId")
.HasColumnType("numeric(20,0)");
b.Property<string>("EmojiName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsAnimated")
.HasColumnType("boolean");
b.Property<int>("Rank")
.HasColumnType("integer");
b.Property<int>("Uses")
.HasColumnType("integer");
b.ToTable("EmojiStatsDto");
});

modelBuilder.Entity("Modix.Data.Models.Emoji.GuildEmojiStats", b =>
{
b.Property<DateTimeOffset>("OldestTimestamp")
.HasColumnType("timestamp with time zone");
b.Property<int>("TotalUses")
.HasColumnType("integer");
b.Property<int>("UniqueEmojis")
.HasColumnType("integer");
b.ToTable("GuildEmojiStats");
});

modelBuilder.Entity("Modix.Data.Models.Emoji.SingleEmojiStatsDto", b =>
{
b.Property<decimal?>("EmojiId")
.HasColumnType("numeric(20,0)");
b.Property<string>("EmojiName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsAnimated")
.HasColumnType("boolean");
b.Property<int>("Rank")
.HasColumnType("integer");
b.Property<decimal>("TopUserId")
.HasColumnType("numeric(20,0)");
b.Property<int>("TopUserUses")
.HasColumnType("integer");
b.Property<int>("Uses")
.HasColumnType("integer");
b.ToTable("SingleEmojiStatsDto");
});

modelBuilder.Entity("Modix.Data.Models.Moderation.DeletedMessageBatchEntity", b =>
{
b.Property<long>("Id")
Expand Down
16 changes: 15 additions & 1 deletion Modix.Data/Models/Core/GuildUserParticipationStatistics.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Modix.Data.Models.Core
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Modix.Data.Models.Core
{
public class GuildUserParticipationStatistics
{
Expand All @@ -12,4 +15,15 @@ public class GuildUserParticipationStatistics

public int Percentile { get; set; }
}

public class GuildUserParticipationStatisticsConfiguration
: IEntityTypeConfiguration<GuildUserParticipationStatistics>
{
public void Configure(
EntityTypeBuilder<GuildUserParticipationStatistics> entityTypeBuilder)
=> entityTypeBuilder
.HasNoKey()
// Workaround until .NET 5: https://github.com/dotnet/efcore/issues/19972
.ToView("No table or view exists for entity type GuildUserParticipationStatistics: This type can only be queried with raw SQL (.FromSqlXXX())");
}
}
14 changes: 14 additions & 0 deletions Modix.Data/Models/Core/MessageCountByDate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Diagnostics;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Modix.Data.Models.Core
{
[DebuggerDisplay("({Date}: {MessageCount})")]
Expand All @@ -9,4 +12,15 @@ public class MessageCountByDate
public DateTime Date { get; set; }
public int MessageCount { get; set; }
}

public class MessageCountByDateConfiguration
: IEntityTypeConfiguration<MessageCountByDate>
{
public void Configure(
EntityTypeBuilder<MessageCountByDate> entityTypeBuilder)
=> entityTypeBuilder
.HasNoKey()
// Workaround until .NET 5: https://github.com/dotnet/efcore/issues/19972
.ToView("No table or view exists for entity type MessageCountByDate: This type can only be queried with raw SQL (.FromSqlXXX())");
}
}
16 changes: 15 additions & 1 deletion Modix.Data/Models/Core/MessageCountPerChannel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
namespace Modix.Data.Models.Core
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Modix.Data.Models.Core
{
public class MessageCountPerChannel
{
public ulong ChannelId { get; set; }
public string ChannelName { get; set; } = null!;
public int MessageCount { get; set; }
}

public class MessageCountPerChannelConfiguration
: IEntityTypeConfiguration<MessageCountPerChannel>
{
public void Configure(
EntityTypeBuilder<MessageCountPerChannel> entityTypeBuilder)
=> entityTypeBuilder
.HasNoKey()
// Workaround until .NET 5: https://github.com/dotnet/efcore/issues/19972
.ToView("No table or view exists for entity type MessageCountPerChannel: This type can only be queried with raw SQL (.FromSqlXXX())");
}
}
16 changes: 15 additions & 1 deletion Modix.Data/Models/Core/PerUserMessageCount.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Modix.Data.Models.Core
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Modix.Data.Models.Core
{
public class PerUserMessageCount
{
Expand All @@ -12,4 +15,15 @@ public class PerUserMessageCount

public bool IsCurrentUser { get; set; }
}

public class PerUserMessageCountConfiguration
: IEntityTypeConfiguration<PerUserMessageCount>
{
public void Configure(
EntityTypeBuilder<PerUserMessageCount> entityTypeBuilder)
=> entityTypeBuilder
.HasNoKey()
// Workaround until .NET 5: https://github.com/dotnet/efcore/issues/19972
.ToView("No table or view exists for entity type PerUserMessageCount: This type can only be queried with raw SQL (.FromSqlXXX())");
}
}
16 changes: 15 additions & 1 deletion Modix.Data/Models/Emoji/EmojiStatsDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Modix.Data.Models.Emoji
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Modix.Data.Models.Emoji
{
internal class EmojiStatsDto
{
Expand All @@ -12,4 +15,15 @@ internal class EmojiStatsDto

public int Uses { get; set; }
}

internal class EmojiStatsDtoConfiguration
: IEntityTypeConfiguration<EmojiStatsDto>
{
public void Configure(
EntityTypeBuilder<EmojiStatsDto> entityTypeBuilder)
=> entityTypeBuilder
.HasNoKey()
// Workaround until .NET 5: https://github.com/dotnet/efcore/issues/19972
.ToView("No table or view exists for entity type EmojiStatsDto: This type can only be queried with raw SQL (.FromSqlXXX())");
}
}
14 changes: 14 additions & 0 deletions Modix.Data/Models/Emoji/GuildEmojiStats.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Modix.Data.Models.Emoji
{
public class GuildEmojiStats
Expand All @@ -10,4 +13,15 @@ public class GuildEmojiStats

public DateTimeOffset OldestTimestamp { get; set; }
}

public class GuildEmojiStatsConfiguration
: IEntityTypeConfiguration<GuildEmojiStats>
{
public void Configure(
EntityTypeBuilder<GuildEmojiStats> entityTypeBuilder)
=> entityTypeBuilder
.HasNoKey()
// Workaround until .NET 5: https://github.com/dotnet/efcore/issues/19972
.ToView("No table or view exists for entity type GuildEmojiStats: This type can only be queried with raw SQL (.FromSqlXXX())");
}
}
16 changes: 15 additions & 1 deletion Modix.Data/Models/Emoji/SingleEmojiStatsDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Modix.Data.Models.Emoji
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Modix.Data.Models.Emoji
{
internal class SingleEmojiStatsDto
{
Expand All @@ -16,4 +19,15 @@ internal class SingleEmojiStatsDto

public int TopUserUses { get; set; }
}

internal class SingleEmojiStatsDtoConfiguration
: IEntityTypeConfiguration<SingleEmojiStatsDto>
{
public void Configure(
EntityTypeBuilder<SingleEmojiStatsDto> entityTypeBuilder)
=> entityTypeBuilder
.HasNoKey()
// Workaround until .NET 5: https://github.com/dotnet/efcore/issues/19972
.ToView("No table or view exists for entity type SingleEmojiStatsDto: This type can only be queried with raw SQL (.FromSqlXXX())");
}
}
Loading

0 comments on commit 6c80d44

Please sign in to comment.