From 2c4f954af98be9e98c55dca66ccbdff73dbafcea Mon Sep 17 00:00:00 2001 From: Karl Carriere Date: Wed, 18 Dec 2024 08:44:50 -0500 Subject: [PATCH] Settings, migrations and updated TestDataSeeder.cs --- global.json | 4 +- .../20241216215210_UpdateSeedData.Designer.cs | 292 ++++++++++++++++++ .../20241216215210_UpdateSeedData.cs | 22 ++ .../20241217225954_ChangeStripeId.Designer.cs | 70 +++++ .../20241217225954_ChangeStripeId.cs | 38 +++ .../MessagingDbContextModelSnapshot.cs | 5 +- src/Web/TestDataSeeder.cs | 37 ++- 7 files changed, 454 insertions(+), 14 deletions(-) create mode 100644 src/Web/Features/Memberships/Data/Migrations/20241216215210_UpdateSeedData.Designer.cs create mode 100644 src/Web/Features/Memberships/Data/Migrations/20241216215210_UpdateSeedData.cs create mode 100644 src/Web/Features/Messages/Data/Migrations/20241217225954_ChangeStripeId.Designer.cs create mode 100644 src/Web/Features/Messages/Data/Migrations/20241217225954_ChangeStripeId.cs diff --git a/global.json b/global.json index b5b37b6..18b689d 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "sdk": { "version": "8.0.0", - "rollForward": "latestMajor", + "rollForward": "latestMinor", "allowPrerelease": false } -} \ No newline at end of file +} diff --git a/src/Web/Features/Memberships/Data/Migrations/20241216215210_UpdateSeedData.Designer.cs b/src/Web/Features/Memberships/Data/Migrations/20241216215210_UpdateSeedData.Designer.cs new file mode 100644 index 0000000..dc927cf --- /dev/null +++ b/src/Web/Features/Memberships/Data/Migrations/20241216215210_UpdateSeedData.Designer.cs @@ -0,0 +1,292 @@ +// +using System; +using Hutopy.Web.Features.Memberships.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Hutopy.Web.Features.Memberships.Data.Migrations +{ + [DbContext(typeof(MembershipDbContext))] + [Migration("20241216215210_UpdateSeedData")] + partial class UpdateSeedData + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Membership") + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Creator", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("PortraitUrl") + .IsRequired() + .HasColumnType("text"); + + b.Property("StripeAccountId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Creators", "Membership"); + }); + + modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("EndDate") + .HasColumnType("timestamp with time zone"); + + b.Property("StartDate") + .HasColumnType("timestamp with time zone"); + + b.Property("StripeSessionId") + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("StripeSubscriptionId") + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("TierId") + .HasColumnType("uuid"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("TierId"); + + b.ToTable("Subscriptions", "Membership"); + }); + + modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Tier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("CurrencyCode") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(4096) + .HasColumnType("character varying(4096)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Price") + .HasColumnType("numeric"); + + b.Property("StripePriceId") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("StripeProductId") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.ToTable("Tiers", "Membership"); + }); + + modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Tip", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("numeric"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("CreatorName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Currency") + .IsRequired() + .HasColumnType("text"); + + b.Property("Message") + .IsRequired() + .HasColumnType("text"); + + b.Property("StripeSessionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("TipperId") + .HasColumnType("uuid"); + + b.Property("TipperName") + .IsRequired() + .HasColumnType("text"); + + b.Property("TransactionId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("TransactionId"); + + b.ToTable("Tips", "Membership"); + }); + + modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Transaction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("numeric"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Currency") + .IsRequired() + .HasColumnType("text"); + + b.Property("StripeInvoiceUrl") + .HasColumnType("text"); + + b.Property("SubscriptionId") + .HasColumnType("uuid"); + + b.Property("Timestamp") + .HasColumnType("timestamp with time zone"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("SubscriptionId"); + + b.ToTable("Transactions", "Membership"); + }); + + modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Subscription", b => + { + b.HasOne("Hutopy.Web.Features.Memberships.Data.Creator", "Creator") + .WithMany() + .HasForeignKey("CreatorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Hutopy.Web.Features.Memberships.Data.Tier", "Tier") + .WithMany("Subscriptions") + .HasForeignKey("TierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Tier"); + }); + + modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Tier", b => + { + b.HasOne("Hutopy.Web.Features.Memberships.Data.Creator", "Creator") + .WithMany() + .HasForeignKey("CreatorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Tip", b => + { + b.HasOne("Hutopy.Web.Features.Memberships.Data.Transaction", "Transaction") + .WithMany() + .HasForeignKey("TransactionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Transaction"); + }); + + modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Transaction", b => + { + b.HasOne("Hutopy.Web.Features.Memberships.Data.Subscription", null) + .WithMany("Transactions") + .HasForeignKey("SubscriptionId"); + }); + + modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Subscription", b => + { + b.Navigation("Transactions"); + }); + + modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Tier", b => + { + b.Navigation("Subscriptions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Web/Features/Memberships/Data/Migrations/20241216215210_UpdateSeedData.cs b/src/Web/Features/Memberships/Data/Migrations/20241216215210_UpdateSeedData.cs new file mode 100644 index 0000000..cb5b667 --- /dev/null +++ b/src/Web/Features/Memberships/Data/Migrations/20241216215210_UpdateSeedData.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Hutopy.Web.Features.Memberships.Data.Migrations +{ + /// + public partial class UpdateSeedData : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/src/Web/Features/Messages/Data/Migrations/20241217225954_ChangeStripeId.Designer.cs b/src/Web/Features/Messages/Data/Migrations/20241217225954_ChangeStripeId.Designer.cs new file mode 100644 index 0000000..ed928e5 --- /dev/null +++ b/src/Web/Features/Messages/Data/Migrations/20241217225954_ChangeStripeId.Designer.cs @@ -0,0 +1,70 @@ +// +using System; +using Hutopy.Web.Features.Messages.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Hutopy.Web.Features.Messages.Migrations +{ + [DbContext(typeof(MessagingDbContext))] + [Migration("20241217225954_ChangeStripeId")] + partial class ChangeStripeId + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Messaging") + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Hutopy.Web.Features.Messages.Data.Message", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatedByName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("CreatedByPortraitUrl") + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("ParentId") + .HasColumnType("uuid"); + + b.Property("SubjectId") + .HasColumnType("uuid"); + + b.Property("Value") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b.HasKey("Id"); + + b.ToTable("Messages", "Messaging"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Web/Features/Messages/Data/Migrations/20241217225954_ChangeStripeId.cs b/src/Web/Features/Messages/Data/Migrations/20241217225954_ChangeStripeId.cs new file mode 100644 index 0000000..44a9df9 --- /dev/null +++ b/src/Web/Features/Messages/Data/Migrations/20241217225954_ChangeStripeId.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Hutopy.Web.Features.Messages.Migrations +{ + /// + public partial class ChangeStripeId : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Value", + schema: "Messaging", + table: "Messages", + type: "character varying(2048)", + maxLength: 2048, + nullable: false, + oldClrType: typeof(string), + oldType: "text"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Value", + schema: "Messaging", + table: "Messages", + type: "text", + nullable: false, + oldClrType: typeof(string), + oldType: "character varying(2048)", + oldMaxLength: 2048); + } + } +} diff --git a/src/Web/Features/Messages/Data/Migrations/MessagingDbContextModelSnapshot.cs b/src/Web/Features/Messages/Data/Migrations/MessagingDbContextModelSnapshot.cs index b1848d8..14c77a2 100644 --- a/src/Web/Features/Messages/Data/Migrations/MessagingDbContextModelSnapshot.cs +++ b/src/Web/Features/Messages/Data/Migrations/MessagingDbContextModelSnapshot.cs @@ -18,7 +18,7 @@ namespace Hutopy.Web.Features.Messages.Migrations #pragma warning disable 612, 618 modelBuilder .HasDefaultSchema("Messaging") - .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("ProductVersion", "8.0.10") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -54,7 +54,8 @@ namespace Hutopy.Web.Features.Messages.Migrations b.Property("Value") .IsRequired() - .HasColumnType("text"); + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); b.HasKey("Id"); diff --git a/src/Web/TestDataSeeder.cs b/src/Web/TestDataSeeder.cs index 5b0bef7..c4655f8 100644 --- a/src/Web/TestDataSeeder.cs +++ b/src/Web/TestDataSeeder.cs @@ -1,5 +1,8 @@ using Hutopy.Web.Common; using Hutopy.Web.Features.Contents.Data; +using ContentCreator = Hutopy.Web.Features.Contents.Data.Creator; +using Hutopy.Web.Features.Memberships.Data; +using MembershipCreator = Hutopy.Web.Features.Memberships.Data.Creator; using Hutopy.Web.Features.Messages.Data; using Hutopy.Web.Features.Users; @@ -16,7 +19,8 @@ public static class WebApplicationExtensions var seeder = new TestDataSeeder( scope.ServiceProvider.GetRequiredService(), scope.ServiceProvider.GetRequiredService(), - scope.ServiceProvider.GetRequiredService()); + scope.ServiceProvider.GetRequiredService(), + scope.ServiceProvider.GetRequiredService()); await seeder.SeedAsync(); } @@ -25,7 +29,8 @@ public static class WebApplicationExtensions internal class TestDataSeeder( ApplicationUserManager userManager, ContentDbContext contentContext, - MessagingDbContext messagingContext) + MessagingDbContext messagingContext, + MembershipDbContext membershipContext) { private const string DefaultPassword = "Test123#"; @@ -65,11 +70,23 @@ internal class TestDataSeeder( await messagingContext.SaveChangesAsync(); } + + // convert to MembershipCreator + var membershipCreator = new MembershipCreator + { + Id = creator.Id, + Name = creator.Name, + StripeAccountId = Guid.NewGuid().ToString(), + PortraitUrl = creator.Images.Logo, + }; + + await membershipContext.Creators.AddAsync(membershipCreator); + await membershipContext.SaveChangesAsync(); } } private List GenerateContent( - Creator creator, + ContentCreator creator, int contentCount) { var currentDate = DateTimeOffset.UtcNow; @@ -191,7 +208,7 @@ internal class TestDataSeeder( [ ]; - private readonly static Creator HutopyCreator = new() + private readonly static ContentCreator HutopyCreator = new() { Name = "hutopy", Title = "Page officielle", @@ -222,7 +239,7 @@ internal class TestDataSeeder( } }; - private readonly static Creator ArpsCreator = new() + private readonly static ContentCreator ArpsCreator = new() { Name = "arps", Title = "Créateur de contenu", @@ -255,7 +272,7 @@ internal class TestDataSeeder( } }; - private readonly static Creator ChloeBeaugrandCreator = new() + private readonly static ContentCreator ChloeBeaugrandCreator = new() { Name = "chloebeaugrand", Title = "Page officielle", @@ -285,7 +302,7 @@ internal class TestDataSeeder( } }; - private readonly static Creator GuillaumeMCreator = new() + private readonly static ContentCreator GuillaumeMCreator = new() { Name = "guillaumem", Title = "Page officielle", @@ -317,7 +334,7 @@ internal class TestDataSeeder( } }; - private readonly static Creator LeffetCreator = new() + private readonly static ContentCreator LeffetCreator = new() { Name = "leffet", Title = "Page officielle", @@ -348,7 +365,7 @@ internal class TestDataSeeder( } }; - private readonly static Creator MathieuCaron = new() + private readonly static ContentCreator MathieuCaron = new() { Name = "mathieucaron", Title = "Page officielle", @@ -378,7 +395,7 @@ internal class TestDataSeeder( } }; - private readonly Creator[] _creators = + private readonly ContentCreator[] _creators = [ HutopyCreator, ArpsCreator,