Settings, migrations and updated TestDataSeeder.cs

This commit is contained in:
Karl Carriere
2024-12-18 08:44:50 -05:00
parent c447479362
commit 2c4f954af9
7 changed files with 454 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMajor",
"rollForward": "latestMinor",
"allowPrerelease": false
}
}

View File

@@ -0,0 +1,292 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PortraitUrl")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StripeAccountId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Creators", "Membership");
});
modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Subscription", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<Guid>("CreatorId")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("EndDate")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset>("StartDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("StripeSessionId")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<string>("StripeSubscriptionId")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<Guid>("TierId")
.HasColumnType("uuid");
b.Property<Guid>("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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<Guid>("CreatorId")
.HasColumnType("uuid");
b.Property<string>("CurrencyCode")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(4096)
.HasColumnType("character varying(4096)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<decimal>("Price")
.HasColumnType("numeric");
b.Property<string>("StripePriceId")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<decimal>("Amount")
.HasColumnType("numeric");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<Guid>("CreatorId")
.HasColumnType("uuid");
b.Property<string>("CreatorName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Currency")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Message")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StripeSessionId")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("TipperId")
.HasColumnType("uuid");
b.Property<string>("TipperName")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("TransactionId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("TransactionId");
b.ToTable("Tips", "Membership");
});
modelBuilder.Entity("Hutopy.Web.Features.Memberships.Data.Transaction", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<decimal>("Amount")
.HasColumnType("numeric");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<string>("Currency")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StripeInvoiceUrl")
.HasColumnType("text");
b.Property<Guid?>("SubscriptionId")
.HasColumnType("uuid");
b.Property<DateTime>("Timestamp")
.HasColumnType("timestamp with time zone");
b.Property<string>("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
}
}
}

View File

@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Hutopy.Web.Features.Memberships.Data.Migrations
{
/// <inheritdoc />
public partial class UpdateSeedData : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@@ -0,0 +1,70 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<Guid>("CreatedBy")
.HasColumnType("uuid");
b.Property<string>("CreatedByName")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<string>("CreatedByPortraitUrl")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<Guid?>("ParentId")
.HasColumnType("uuid");
b.Property<Guid>("SubjectId")
.HasColumnType("uuid");
b.Property<string>("Value")
.IsRequired()
.HasMaxLength(2048)
.HasColumnType("character varying(2048)");
b.HasKey("Id");
b.ToTable("Messages", "Messaging");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Hutopy.Web.Features.Messages.Migrations
{
/// <inheritdoc />
public partial class ChangeStripeId : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Value",
schema: "Messaging",
table: "Messages",
type: "character varying(2048)",
maxLength: 2048,
nullable: false,
oldClrType: typeof(string),
oldType: "text");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Value",
schema: "Messaging",
table: "Messages",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(2048)",
oldMaxLength: 2048);
}
}
}

View File

@@ -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<string>("Value")
.IsRequired()
.HasColumnType("text");
.HasMaxLength(2048)
.HasColumnType("character varying(2048)");
b.HasKey("Id");

View File

@@ -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<ApplicationUserManager>(),
scope.ServiceProvider.GetRequiredService<ContentDbContext>(),
scope.ServiceProvider.GetRequiredService<MessagingDbContext>());
scope.ServiceProvider.GetRequiredService<MessagingDbContext>(),
scope.ServiceProvider.GetRequiredService<MembershipDbContext>());
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<Content> 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,