feat: add resource quotas, PayPal subscriptions and paid disk allowances

Calculate and enforce configurable resource consumption, expose balances in PostIt and document the rule in CGU. Add confirmed monthly PayPal credits and disk quotas of twice the free default for Discovery and five times for Premium, with payment reconciliation, migrations and regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Paul Schneider 2026-11-08 05:02:23 +00:00
commit 650e5f5e30
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
69 changed files with 19111 additions and 203 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,107 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Yavsc.Migrations
{
/// <inheritdoc />
public partial class ResourceSubscriptions : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<decimal>(
name: "CreditPoints",
table: "ResourceUsageRecords",
type: "numeric(28,8)",
precision: 28,
scale: 8,
nullable: false,
defaultValue: 0m);
migrationBuilder.CreateTable(
name: "ResourceSubscriptions",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<string>(type: "character varying(450)", maxLength: 450, nullable: false),
Pack = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
PlanId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
PayPalId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
State = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
MonthlyPoints = table.Column<decimal>(type: "numeric(28,8)", precision: 28, scale: 8, nullable: false),
PriceExcludingTax = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
VatPercent = table.Column<decimal>(type: "numeric", nullable: false),
PriceIncludingTax = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
StartsAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
NextBillingAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
LastCreditedCycle = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ResourceSubscriptions", x => x.Id);
table.ForeignKey(
name: "FK_ResourceSubscriptions_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "ResourceSubscriptionPayments",
columns: table => new
{
Id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
SubscriptionId = table.Column<Guid>(type: "uuid", nullable: false),
Cycle = table.Column<int>(type: "integer", nullable: false),
PaidAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
GrantedPoints = table.Column<decimal>(type: "numeric(28,8)", precision: 28, scale: 8, nullable: false),
Reversed = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ResourceSubscriptionPayments", x => x.Id);
table.ForeignKey(
name: "FK_ResourceSubscriptionPayments_ResourceSubscriptions_Subscrip~",
column: x => x.SubscriptionId,
principalTable: "ResourceSubscriptions",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_ResourceSubscriptionPayments_SubscriptionId_Cycle",
table: "ResourceSubscriptionPayments",
columns: new[] { "SubscriptionId", "Cycle" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_ResourceSubscriptions_PayPalId",
table: "ResourceSubscriptions",
column: "PayPalId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_ResourceSubscriptions_UserId",
table: "ResourceSubscriptions",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ResourceSubscriptionPayments");
migrationBuilder.DropTable(
name: "ResourceSubscriptions");
migrationBuilder.DropColumn(
name: "CreditPoints",
table: "ResourceUsageRecords");
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,29 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Yavsc.Migrations
{
/// <inheritdoc />
public partial class PremiumDiskQuota : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTimeOffset>(
name: "PremiumDiskQuotaUntil",
table: "AspNetUsers",
type: "timestamp with time zone",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "PremiumDiskQuotaUntil",
table: "AspNetUsers");
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,29 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Yavsc.Migrations
{
/// <inheritdoc />
public partial class DiscoveryDiskQuota : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTimeOffset>(
name: "DiscoveryDiskQuotaUntil",
table: "AspNetUsers",
type: "timestamp with time zone",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "DiscoveryDiskQuotaUntil",
table: "AspNetUsers");
}
}
}

View file

@ -1150,6 +1150,9 @@ namespace Yavsc.Migrations
.HasMaxLength(512)
.HasColumnType("character varying(512)");
b.Property<DateTimeOffset?>("DiscoveryDiskQuotaUntil")
.HasColumnType("timestamp with time zone");
b.Property<long>("DiskQuota")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
@ -1202,6 +1205,9 @@ namespace Yavsc.Migrations
b.Property<long?>("PostalAddressId")
.HasColumnType("bigint");
b.Property<DateTimeOffset?>("PremiumDiskQuotaUntil")
.HasColumnType("timestamp with time zone");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
@ -2803,6 +2809,101 @@ namespace Yavsc.Migrations
b.ToTable("PerformerDonations");
});
modelBuilder.Entity("Yavsc.Models.Payment.ResourceSubscription", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("LastCreditedCycle")
.HasColumnType("integer");
b.Property<decimal>("MonthlyPoints")
.HasPrecision(28, 8)
.HasColumnType("numeric(28,8)");
b.Property<DateTimeOffset?>("NextBillingAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Pack")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)");
b.Property<string>("PayPalId")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("PlanId")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<decimal>("PriceExcludingTax")
.HasColumnType("numeric(18,2)");
b.Property<decimal>("PriceIncludingTax")
.HasColumnType("numeric(18,2)");
b.Property<DateTimeOffset?>("StartsAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("State")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)");
b.Property<string>("UserId")
.IsRequired()
.HasMaxLength(450)
.HasColumnType("character varying(450)");
b.Property<decimal>("VatPercent")
.HasColumnType("numeric");
b.HasKey("Id");
b.HasIndex("PayPalId")
.IsUnique();
b.HasIndex("UserId");
b.ToTable("ResourceSubscriptions");
});
modelBuilder.Entity("Yavsc.Models.Payment.ResourceSubscriptionPayment", b =>
{
b.Property<string>("Id")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<int>("Cycle")
.HasColumnType("integer");
b.Property<decimal>("GrantedPoints")
.HasPrecision(28, 8)
.HasColumnType("numeric(28,8)");
b.Property<DateTimeOffset>("PaidAt")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Reversed")
.HasColumnType("boolean");
b.Property<Guid>("SubscriptionId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SubscriptionId", "Cycle")
.IsUnique();
b.ToTable("ResourceSubscriptionPayments");
});
modelBuilder.Entity("Yavsc.Models.Relationship.Circle", b =>
{
b.Property<long>("Id")
@ -2997,6 +3098,12 @@ namespace Yavsc.Migrations
b.Property<decimal>("CpuSeconds")
.HasColumnType("numeric");
b.Property<decimal>("CreditPoints")
.ValueGeneratedOnAdd()
.HasPrecision(28, 8)
.HasColumnType("numeric(28,8)")
.HasDefaultValue(0m);
b.Property<string>("Currency")
.IsRequired()
.ValueGeneratedOnAdd()
@ -4623,6 +4730,24 @@ namespace Yavsc.Migrations
.IsRequired();
});
modelBuilder.Entity("Yavsc.Models.Payment.ResourceSubscription", b =>
{
b.HasOne("Yavsc.Models.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
modelBuilder.Entity("Yavsc.Models.Payment.ResourceSubscriptionPayment", b =>
{
b.HasOne("Yavsc.Models.Payment.ResourceSubscription", null)
.WithMany()
.HasForeignKey("SubscriptionId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
modelBuilder.Entity("Yavsc.Models.Relationship.Circle", b =>
{
b.HasOne("Yavsc.Models.ApplicationUser", null)