Commit d4198727 authored by Robert Rudman's avatar Robert Rudman

Initial schema setup

parent ce7545b2
using Microsoft.EntityFrameworkCore;
using Rodgort.Data.Tables;
namespace Rodgort.Data
{
......@@ -7,5 +8,105 @@ namespace Rodgort.Data
public RodgortContext(DbContextOptions<RodgortContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder
.Entity<DbMetaAnswer>()
.HasKey(ma => ma.Id);
modelBuilder
.Entity<DbMetaAnswer>()
.Property(rt => rt.Id)
.ValueGeneratedNever();
modelBuilder
.Entity<DbMetaAnswer>()
.HasOne(ma => ma.MetaQuestion)
.WithMany(mq => mq.MetaAnswers)
.HasForeignKey(ma => ma.MetaQuestionId);
modelBuilder
.Entity<DbMetaAnswerStatistics>()
.HasKey(mas => mas.Id);
modelBuilder
.Entity<DbMetaAnswerStatistics>()
.HasOne(mas => mas.MetaAnswer)
.WithMany(ma => ma.Statistics)
.HasForeignKey(mas => mas.MetaAnswerId);
modelBuilder
.Entity<DbMetaQuestion>()
.HasKey(mqs => mqs.Id);
modelBuilder
.Entity<DbMetaQuestion>()
.Property(rt => rt.Id)
.ValueGeneratedNever();
modelBuilder
.Entity<DbMetaQuestionStatistics>()
.HasKey(mqs => mqs.Id);
modelBuilder
.Entity<DbMetaQuestionStatistics>()
.HasOne(mqs => mqs.MetaQuestion)
.WithMany(mq => mq.Statistics)
.HasForeignKey(mqs => mqs.MetaQuestionId);
modelBuilder
.Entity<DbMetaQuestionTag>()
.HasKey(mqt => new { mqt.MetaQuestionId, mqt.TagName });
modelBuilder
.Entity<DbMetaQuestionTag>()
.HasOne(mqt => mqt.RequestType)
.WithMany(rt => rt.MetaQuestionTags)
.HasForeignKey(mqt => mqt.RequestTypeId);
modelBuilder
.Entity<DbMetaQuestionTag>()
.HasOne(mqt => mqt.Tag)
.WithMany(t => t.MetaQuestionTags)
.HasForeignKey(mqt => mqt.TagName);
modelBuilder
.Entity<DbMetaQuestionTag>()
.HasOne(mqt => mqt.MetaQuestion)
.WithMany(mq => mq.MetaQuestionTags)
.HasForeignKey(mqt => mqt.MetaQuestionId);
modelBuilder
.Entity<DbMetaQuestionTag>()
.HasOne(mqt => mqt.SecondaryTag)
.WithMany(t => t.MetaQuestionSecondaryTags)
.IsRequired(false)
.HasForeignKey(mqt => mqt.SecondaryTagName);
modelBuilder
.Entity<DbRequestType>()
.HasKey(rt => rt.Id);
modelBuilder
.Entity<DbRequestType>()
.Property(rt => rt.Id)
.ValueGeneratedNever();
modelBuilder
.Entity<DbTag>()
.HasKey(tag => tag.Name);
modelBuilder
.Entity<DbTagStatistics>()
.HasKey(ts => ts.Id);
modelBuilder
.Entity<DbTagStatistics>()
.HasOne(ts => ts.Tag)
.WithMany(t => t.Statistics)
.HasForeignKey(ts => ts.TagName);
modelBuilder
.Entity<DbRequestType>()
.HasData(
new DbRequestType {Id = DbRequestType.UNKNOWN, Name = "Unknown"},
new DbRequestType {Id = DbRequestType.SYNONYM, Name = "Synonym"},
new DbRequestType {Id = DbRequestType.MERGE, Name = "Merge"},
new DbRequestType {Id = DbRequestType.BURNINATE, Name = "Burninate"}
);
}
}
}
using System.Collections.Generic;
namespace Rodgort.Data.Tables
{
public class DbMetaAnswer
{
public int Id { get; set; }
public int MetaQuestionId { get; set; }
public string Body { get; set; }
public DbMetaQuestion MetaQuestion { get; set; }
public List<DbMetaAnswerStatistics> Statistics { get; set; }
}
}
using System;
using System.Collections.Generic;
namespace Rodgort.Data.Tables
{
public class DbMetaAnswerStatistics
{
public int Id { get; set; }
public int MetaAnswerId { get; set; }
public int Score { get; set; }
public DateTime DateTime { get; set; }
public DbMetaAnswer MetaAnswer { get; set; }
}
}
using System.Collections.Generic;
namespace Rodgort.Data.Tables
{
public class DbMetaQuestion
{
public int Id { get; set; }
public string Body { get; set; }
public string Title { get; set; }
public string Link { get; set; }
public List<DbMetaAnswer> MetaAnswers { get; set; }
public List<DbMetaQuestionTag> MetaQuestionTags { get; set; }
public List<DbMetaQuestionStatistics> Statistics { get; set; }
}
}
using System;
namespace Rodgort.Data.Tables
{
public class DbMetaQuestionStatistics
{
public int Id { get; set; }
public int MetaQuestionId { get; set; }
public int Score { get; set; }
public DateTime DateTime { get; set; }
public DbMetaQuestion MetaQuestion { get; set; }
}
}
namespace Rodgort.Data.Tables
{
public class DbMetaQuestionTag
{
public int MetaQuestionId { get; set; }
public string TagName { get; set; }
public int RequestTypeId { get; set; }
public string SecondaryTagName { get; set; }
public DbMetaQuestion MetaQuestion { get; set; }
public DbTag Tag { get; set; }
public DbRequestType RequestType { get; set; }
public DbTag SecondaryTag { get; set; }
}
}
using System.Collections.Generic;
namespace Rodgort.Data.Tables
{
public class DbRequestType
{
public const int UNKNOWN = 0;
public const int SYNONYM = 1;
public const int MERGE = 2;
public const int BURNINATE = 3;
public int Id { get; set; }
public string Name { get; set; }
public List<DbMetaQuestionTag> MetaQuestionTags { get; set; }
}
}

using System.Collections.Generic;
namespace Rodgort.Data.Tables
{
public class DbTag
{
public string Name { get; set; }
public List<DbMetaQuestionTag> MetaQuestionTags { get; set; }
public List<DbMetaQuestionTag> MetaQuestionSecondaryTags { get; set; }
public List<DbTagStatistics> Statistics { get; set; }
}
}
using System;
namespace Rodgort.Data.Tables
{
public class DbTagStatistics
{
public int Id { get; set; }
public string TagName { get; set; }
public int QuestionCount { get; set; }
public int AnswerCount { get; set; }
public DateTime DateTime { get; set; }
public DbTag Tag { get; set; }
}
}
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Rodgort.Data;
namespace Rodgort.Migrations
{
[DbContext(typeof(RodgortContext))]
[Migration("20181204062134_InitialMigration")]
partial class InitialMigration
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
.HasAnnotation("ProductVersion", "2.1.4-rtm-31024")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaAnswer", b =>
{
b.Property<int>("Id");
b.Property<string>("Body");
b.Property<int>("MetaQuestionId");
b.HasKey("Id");
b.HasIndex("MetaQuestionId");
b.ToTable("DbMetaAnswer");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaAnswerStatistics", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("DateTime");
b.Property<int>("MetaAnswerId");
b.Property<int>("Score");
b.HasKey("Id");
b.HasIndex("MetaAnswerId");
b.ToTable("DbMetaAnswerStatistics");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaQuestion", b =>
{
b.Property<int>("Id");
b.Property<string>("Body");
b.Property<string>("Link");
b.Property<string>("Title");
b.HasKey("Id");
b.ToTable("DbMetaQuestion");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaQuestionStatistics", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("DateTime");
b.Property<int>("MetaQuestionId");
b.Property<int>("Score");
b.HasKey("Id");
b.HasIndex("MetaQuestionId");
b.ToTable("DbMetaQuestionStatistics");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaQuestionTag", b =>
{
b.Property<int>("MetaQuestionId");
b.Property<string>("TagName");
b.Property<int>("RequestTypeId");
b.Property<string>("SecondaryTagName");
b.HasKey("MetaQuestionId", "TagName");
b.HasIndex("RequestTypeId");
b.HasIndex("SecondaryTagName");
b.HasIndex("TagName");
b.ToTable("DbMetaQuestionTag");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbRequestType", b =>
{
b.Property<int>("Id");
b.Property<string>("Name");
b.HasKey("Id");
b.ToTable("DbRequestType");
b.HasData(
new { Id = 0, Name = "Unknown" },
new { Id = 1, Name = "Synonym" },
new { Id = 2, Name = "Merge" },
new { Id = 3, Name = "Burninate" }
);
});
modelBuilder.Entity("Rodgort.Data.Tables.DbTag", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd();
b.HasKey("Name");
b.ToTable("DbTag");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbTagStatistics", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AnswerCount");
b.Property<DateTime>("DateTime");
b.Property<int>("QuestionCount");
b.Property<string>("TagName");
b.HasKey("Id");
b.HasIndex("TagName");
b.ToTable("DbTagStatistics");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaAnswer", b =>
{
b.HasOne("Rodgort.Data.Tables.DbMetaQuestion", "MetaQuestion")
.WithMany("MetaAnswers")
.HasForeignKey("MetaQuestionId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaAnswerStatistics", b =>
{
b.HasOne("Rodgort.Data.Tables.DbMetaAnswer", "MetaAnswer")
.WithMany("Statistics")
.HasForeignKey("MetaAnswerId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaQuestionStatistics", b =>
{
b.HasOne("Rodgort.Data.Tables.DbMetaQuestion", "MetaQuestion")
.WithMany("Statistics")
.HasForeignKey("MetaQuestionId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaQuestionTag", b =>
{
b.HasOne("Rodgort.Data.Tables.DbMetaQuestion", "MetaQuestion")
.WithMany("MetaQuestionTags")
.HasForeignKey("MetaQuestionId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Rodgort.Data.Tables.DbRequestType", "RequestType")
.WithMany("MetaQuestionTags")
.HasForeignKey("RequestTypeId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Rodgort.Data.Tables.DbTag", "SecondaryTag")
.WithMany("MetaQuestionSecondaryTags")
.HasForeignKey("SecondaryTagName");
b.HasOne("Rodgort.Data.Tables.DbTag", "Tag")
.WithMany("MetaQuestionTags")
.HasForeignKey("TagName")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Rodgort.Data.Tables.DbTagStatistics", b =>
{
b.HasOne("Rodgort.Data.Tables.DbTag", "Tag")
.WithMany("Statistics")
.HasForeignKey("TagName");
});
#pragma warning restore 612, 618
}
}
}
This diff is collapsed.
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Rodgort.Data;
namespace Rodgort.Migrations
{
[DbContext(typeof(RodgortContext))]
partial class RodgortContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
.HasAnnotation("ProductVersion", "2.1.4-rtm-31024")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaAnswer", b =>
{
b.Property<int>("Id");
b.Property<string>("Body");
b.Property<int>("MetaQuestionId");
b.HasKey("Id");
b.HasIndex("MetaQuestionId");
b.ToTable("DbMetaAnswer");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaAnswerStatistics", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("DateTime");
b.Property<int>("MetaAnswerId");
b.Property<int>("Score");
b.HasKey("Id");
b.HasIndex("MetaAnswerId");
b.ToTable("DbMetaAnswerStatistics");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaQuestion", b =>
{
b.Property<int>("Id");
b.Property<string>("Body");
b.Property<string>("Link");
b.Property<string>("Title");
b.HasKey("Id");
b.ToTable("DbMetaQuestion");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaQuestionStatistics", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("DateTime");
b.Property<int>("MetaQuestionId");
b.Property<int>("Score");
b.HasKey("Id");
b.HasIndex("MetaQuestionId");
b.ToTable("DbMetaQuestionStatistics");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaQuestionTag", b =>
{
b.Property<int>("MetaQuestionId");
b.Property<string>("TagName");
b.Property<int>("RequestTypeId");
b.Property<string>("SecondaryTagName");
b.HasKey("MetaQuestionId", "TagName");
b.HasIndex("RequestTypeId");
b.HasIndex("SecondaryTagName");
b.HasIndex("TagName");
b.ToTable("DbMetaQuestionTag");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbRequestType", b =>
{
b.Property<int>("Id");
b.Property<string>("Name");
b.HasKey("Id");
b.ToTable("DbRequestType");
b.HasData(
new { Id = 0, Name = "Unknown" },
new { Id = 1, Name = "Synonym" },
new { Id = 2, Name = "Merge" },
new { Id = 3, Name = "Burninate" }
);
});
modelBuilder.Entity("Rodgort.Data.Tables.DbTag", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd();
b.HasKey("Name");
b.ToTable("DbTag");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbTagStatistics", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AnswerCount");
b.Property<DateTime>("DateTime");
b.Property<int>("QuestionCount");
b.Property<string>("TagName");
b.HasKey("Id");
b.HasIndex("TagName");
b.ToTable("DbTagStatistics");
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaAnswer", b =>
{
b.HasOne("Rodgort.Data.Tables.DbMetaQuestion", "MetaQuestion")
.WithMany("MetaAnswers")
.HasForeignKey("MetaQuestionId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaAnswerStatistics", b =>
{
b.HasOne("Rodgort.Data.Tables.DbMetaAnswer", "MetaAnswer")
.WithMany("Statistics")
.HasForeignKey("MetaAnswerId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaQuestionStatistics", b =>
{
b.HasOne("Rodgort.Data.Tables.DbMetaQuestion", "MetaQuestion")
.WithMany("Statistics")
.HasForeignKey("MetaQuestionId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Rodgort.Data.Tables.DbMetaQuestionTag", b =>
{
b.HasOne("Rodgort.Data.Tables.DbMetaQuestion", "MetaQuestion")
.WithMany("MetaQuestionTags")
.HasForeignKey("MetaQuestionId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Rodgort.Data.Tables.DbRequestType", "RequestType")
.WithMany("MetaQuestionTags")
.HasForeignKey("RequestTypeId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Rodgort.Data.Tables.DbTag", "SecondaryTag")
.WithMany("MetaQuestionSecondaryTags")
.HasForeignKey("SecondaryTagName");
b.HasOne("Rodgort.Data.Tables.DbTag", "Tag")
.WithMany("MetaQuestionTags")
.HasForeignKey("TagName")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Rodgort.Data.Tables.DbTagStatistics", b =>
{
b.HasOne("Rodgort.Data.Tables.DbTag", "Tag")
.WithMany("Statistics")
.HasForeignKey("TagName");
});
#pragma warning restore 612, 618
}
}
}
......@@ -54,19 +54,19 @@ namespace StackExchangeChat.Console
var chatClient = serviceProvider.GetService<ChatClient>();
var events = chatClient.SubscribeToEvents(ChatSite.StackExchange, 86421);
events.Subscribe(System.Console.WriteLine);
events
chatClient
.SubscribeToEvents(ChatSite.StackExchange, 86421)
.OnlyMessages()
.SameRoomOnly()
.SkipMyMessages()
.Subscribe(async chatEvent =>
{
try