diff --git a/Cocotte/Migrations/20230325153626_InitialCreate.Designer.cs b/Cocotte/Migrations/20230325153626_InitialCreate.Designer.cs new file mode 100644 index 0000000..f50c741 --- /dev/null +++ b/Cocotte/Migrations/20230325153626_InitialCreate.Designer.cs @@ -0,0 +1,152 @@ +// +using Cocotte.Services; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Cocotte.Migrations +{ + [DbContext(typeof(CocotteDbContext))] + [Migration("20230325153626_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.4"); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.Activity", b => + { + b.Property("GuildId") + .HasColumnType("INTEGER"); + + b.Property("ChannelId") + .HasColumnType("INTEGER"); + + b.Property("MessageId") + .HasColumnType("INTEGER"); + + b.Property("AreRolesEnabled") + .HasColumnType("INTEGER"); + + b.Property("CreatorDisplayName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("CreatorUserId") + .HasColumnType("INTEGER"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("MaxPlayers") + .HasColumnType("INTEGER"); + + b.Property("Name") + .HasColumnType("INTEGER"); + + b.Property("ThreadId") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("GuildId", "ChannelId", "MessageId"); + + b.HasIndex("ThreadId"); + + b.ToTable("Activities"); + + b.HasDiscriminator("Discriminator").HasValue("Activity"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.ActivityPlayer", b => + { + b.Property("GuildId") + .HasColumnType("INTEGER"); + + b.Property("ChannelId") + .HasColumnType("INTEGER"); + + b.Property("MessageId") + .HasColumnType("INTEGER"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("GuildId", "ChannelId", "MessageId", "UserId"); + + b.ToTable("ActivityPlayers"); + + b.HasDiscriminator("Discriminator").HasValue("ActivityPlayer"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.InterstellarActivity", b => + { + b.HasBaseType("Cocotte.Modules.Activities.Models.Activity"); + + b.Property("Color") + .HasColumnType("INTEGER"); + + b.HasDiscriminator().HasValue("InterstellarActivity"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.StagedActivity", b => + { + b.HasBaseType("Cocotte.Modules.Activities.Models.Activity"); + + b.Property("Stage") + .HasColumnType("INTEGER"); + + b.HasDiscriminator().HasValue("StagedActivity"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.ActivityRolePlayer", b => + { + b.HasBaseType("Cocotte.Modules.Activities.Models.ActivityPlayer"); + + b.Property("Roles") + .HasColumnType("INTEGER"); + + b.HasDiscriminator().HasValue("ActivityRolePlayer"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.ActivityPlayer", b => + { + b.HasOne("Cocotte.Modules.Activities.Models.Activity", "Activity") + .WithMany("ActivityPlayers") + .HasForeignKey("GuildId", "ChannelId", "MessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Activity"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.Activity", b => + { + b.Navigation("ActivityPlayers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Cocotte/Migrations/20230325153626_InitialCreate.cs b/Cocotte/Migrations/20230325153626_InitialCreate.cs new file mode 100644 index 0000000..86ed844 --- /dev/null +++ b/Cocotte/Migrations/20230325153626_InitialCreate.cs @@ -0,0 +1,76 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Cocotte.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Activities", + columns: table => new + { + GuildId = table.Column(type: "INTEGER", nullable: false), + ChannelId = table.Column(type: "INTEGER", nullable: false), + MessageId = table.Column(type: "INTEGER", nullable: false), + ThreadId = table.Column(type: "INTEGER", nullable: false), + CreatorUserId = table.Column(type: "INTEGER", nullable: false), + CreatorDisplayName = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: true), + Type = table.Column(type: "INTEGER", nullable: false), + Name = table.Column(type: "INTEGER", nullable: false), + AreRolesEnabled = table.Column(type: "INTEGER", nullable: false), + MaxPlayers = table.Column(type: "INTEGER", nullable: false), + Discriminator = table.Column(type: "TEXT", nullable: false), + Color = table.Column(type: "INTEGER", nullable: true), + Stage = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Activities", x => new { x.GuildId, x.ChannelId, x.MessageId }); + }); + + migrationBuilder.CreateTable( + name: "ActivityPlayers", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false), + GuildId = table.Column(type: "INTEGER", nullable: false), + ChannelId = table.Column(type: "INTEGER", nullable: false), + MessageId = table.Column(type: "INTEGER", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + Discriminator = table.Column(type: "TEXT", nullable: false), + Roles = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ActivityPlayers", x => new { x.GuildId, x.ChannelId, x.MessageId, x.UserId }); + table.ForeignKey( + name: "FK_ActivityPlayers_Activities_GuildId_ChannelId_MessageId", + columns: x => new { x.GuildId, x.ChannelId, x.MessageId }, + principalTable: "Activities", + principalColumns: new[] { "GuildId", "ChannelId", "MessageId" }, + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Activities_ThreadId", + table: "Activities", + column: "ThreadId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ActivityPlayers"); + + migrationBuilder.DropTable( + name: "Activities"); + } + } +} diff --git a/Cocotte/Migrations/20230325184735_AddActivityCreationDate.Designer.cs b/Cocotte/Migrations/20230325184735_AddActivityCreationDate.Designer.cs new file mode 100644 index 0000000..1e8caee --- /dev/null +++ b/Cocotte/Migrations/20230325184735_AddActivityCreationDate.Designer.cs @@ -0,0 +1,156 @@ +// +using System; +using Cocotte.Services; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Cocotte.Migrations +{ + [DbContext(typeof(CocotteDbContext))] + [Migration("20230325184735_AddActivityCreationDate")] + partial class AddActivityCreationDate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.4"); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.Activity", b => + { + b.Property("GuildId") + .HasColumnType("INTEGER"); + + b.Property("ChannelId") + .HasColumnType("INTEGER"); + + b.Property("MessageId") + .HasColumnType("INTEGER"); + + b.Property("AreRolesEnabled") + .HasColumnType("INTEGER"); + + b.Property("CreationDate") + .HasColumnType("TEXT"); + + b.Property("CreatorDisplayName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("CreatorUserId") + .HasColumnType("INTEGER"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("MaxPlayers") + .HasColumnType("INTEGER"); + + b.Property("Name") + .HasColumnType("INTEGER"); + + b.Property("ThreadId") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("GuildId", "ChannelId", "MessageId"); + + b.HasIndex("ThreadId"); + + b.ToTable("Activities"); + + b.HasDiscriminator("Discriminator").HasValue("Activity"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.ActivityPlayer", b => + { + b.Property("GuildId") + .HasColumnType("INTEGER"); + + b.Property("ChannelId") + .HasColumnType("INTEGER"); + + b.Property("MessageId") + .HasColumnType("INTEGER"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("GuildId", "ChannelId", "MessageId", "UserId"); + + b.ToTable("ActivityPlayers"); + + b.HasDiscriminator("Discriminator").HasValue("ActivityPlayer"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.InterstellarActivity", b => + { + b.HasBaseType("Cocotte.Modules.Activities.Models.Activity"); + + b.Property("Color") + .HasColumnType("INTEGER"); + + b.HasDiscriminator().HasValue("InterstellarActivity"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.StagedActivity", b => + { + b.HasBaseType("Cocotte.Modules.Activities.Models.Activity"); + + b.Property("Stage") + .HasColumnType("INTEGER"); + + b.HasDiscriminator().HasValue("StagedActivity"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.ActivityRolePlayer", b => + { + b.HasBaseType("Cocotte.Modules.Activities.Models.ActivityPlayer"); + + b.Property("Roles") + .HasColumnType("INTEGER"); + + b.HasDiscriminator().HasValue("ActivityRolePlayer"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.ActivityPlayer", b => + { + b.HasOne("Cocotte.Modules.Activities.Models.Activity", "Activity") + .WithMany("ActivityPlayers") + .HasForeignKey("GuildId", "ChannelId", "MessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Activity"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.Activity", b => + { + b.Navigation("ActivityPlayers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Cocotte/Migrations/20230325184735_AddActivityCreationDate.cs b/Cocotte/Migrations/20230325184735_AddActivityCreationDate.cs new file mode 100644 index 0000000..f9dd729 --- /dev/null +++ b/Cocotte/Migrations/20230325184735_AddActivityCreationDate.cs @@ -0,0 +1,30 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Cocotte.Migrations +{ + /// + public partial class AddActivityCreationDate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "CreationDate", + table: "Activities", + type: "TEXT", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "CreationDate", + table: "Activities"); + } + } +} diff --git a/Cocotte/Migrations/CocotteDbContextModelSnapshot.cs b/Cocotte/Migrations/CocotteDbContextModelSnapshot.cs new file mode 100644 index 0000000..185380f --- /dev/null +++ b/Cocotte/Migrations/CocotteDbContextModelSnapshot.cs @@ -0,0 +1,153 @@ +// +using System; +using Cocotte.Services; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Cocotte.Migrations +{ + [DbContext(typeof(CocotteDbContext))] + partial class CocotteDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.4"); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.Activity", b => + { + b.Property("GuildId") + .HasColumnType("INTEGER"); + + b.Property("ChannelId") + .HasColumnType("INTEGER"); + + b.Property("MessageId") + .HasColumnType("INTEGER"); + + b.Property("AreRolesEnabled") + .HasColumnType("INTEGER"); + + b.Property("CreationDate") + .HasColumnType("TEXT"); + + b.Property("CreatorDisplayName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("CreatorUserId") + .HasColumnType("INTEGER"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("MaxPlayers") + .HasColumnType("INTEGER"); + + b.Property("Name") + .HasColumnType("INTEGER"); + + b.Property("ThreadId") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("GuildId", "ChannelId", "MessageId"); + + b.HasIndex("ThreadId"); + + b.ToTable("Activities"); + + b.HasDiscriminator("Discriminator").HasValue("Activity"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.ActivityPlayer", b => + { + b.Property("GuildId") + .HasColumnType("INTEGER"); + + b.Property("ChannelId") + .HasColumnType("INTEGER"); + + b.Property("MessageId") + .HasColumnType("INTEGER"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("GuildId", "ChannelId", "MessageId", "UserId"); + + b.ToTable("ActivityPlayers"); + + b.HasDiscriminator("Discriminator").HasValue("ActivityPlayer"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.InterstellarActivity", b => + { + b.HasBaseType("Cocotte.Modules.Activities.Models.Activity"); + + b.Property("Color") + .HasColumnType("INTEGER"); + + b.HasDiscriminator().HasValue("InterstellarActivity"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.StagedActivity", b => + { + b.HasBaseType("Cocotte.Modules.Activities.Models.Activity"); + + b.Property("Stage") + .HasColumnType("INTEGER"); + + b.HasDiscriminator().HasValue("StagedActivity"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.ActivityRolePlayer", b => + { + b.HasBaseType("Cocotte.Modules.Activities.Models.ActivityPlayer"); + + b.Property("Roles") + .HasColumnType("INTEGER"); + + b.HasDiscriminator().HasValue("ActivityRolePlayer"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.ActivityPlayer", b => + { + b.HasOne("Cocotte.Modules.Activities.Models.Activity", "Activity") + .WithMany("ActivityPlayers") + .HasForeignKey("GuildId", "ChannelId", "MessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Activity"); + }); + + modelBuilder.Entity("Cocotte.Modules.Activities.Models.Activity", b => + { + b.Navigation("ActivityPlayers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Cocotte/Modules/Activities/Models/Activity.cs b/Cocotte/Modules/Activities/Models/Activity.cs index 79f5d12..6ab019e 100644 --- a/Cocotte/Modules/Activities/Models/Activity.cs +++ b/Cocotte/Modules/Activities/Models/Activity.cs @@ -23,6 +23,8 @@ public class Activity public required bool AreRolesEnabled { get; init; } public required uint MaxPlayers { get; set; } + public DateTime CreationDate { get; init; } = DateTime.Now; + public List ActivityPlayers { get; init; } = new(); public override string ToString() diff --git a/Cocotte/Program.cs b/Cocotte/Program.cs index ad327bf..1a2a36f 100644 --- a/Cocotte/Program.cs +++ b/Cocotte/Program.cs @@ -74,12 +74,17 @@ await using(var scope = host.Services.CreateAsyncScope()) { var hostEnvironment = scope.ServiceProvider.GetRequiredService(); + var dbContext = scope.ServiceProvider.GetRequiredService(); if (hostEnvironment.IsDevelopment()) { - var dbContext = scope.ServiceProvider.GetRequiredService(); // await dbContext.Database.EnsureDeletedAsync(); await dbContext.Database.EnsureCreatedAsync(); } + else + { + // Apply migrations + await dbContext.Database.MigrateAsync(); + } } await host.RunAsync(); \ No newline at end of file diff --git a/identifier.sqlite b/identifier.sqlite new file mode 100644 index 0000000..e69de29