mirror of
https://github.com/claunia/marechai.git
synced 2026-07-08 17:57:08 +00:00
Compilations were previously modeled as a SoftwareRelease row with IsCompilation=true, with bundled contents tracked via release-keyed junction tables. This conflated "release" with "the thing being released" and blocked compilations from having their own identity, predecessor chain, or covers independent of any one release. Introduce SoftwareCompilation as a sibling entity to Software: - Has its own Name, optional bundling link to a Software or Machine (e.g. games bundled with an OS, or a dedicated handheld), and a predecessor/successor self-reference reusing SoftwareRelationshipType. - Owns its releases (SoftwareRelease.SoftwareCompilationId) and covers (SoftwareCover.SoftwareCompilationId), mirroring Software's existing patterns. - Owns its contained software/versions via new SoftwareBySoftwareCompilation / SoftwareVersionBySoftwareCompilation junctions (moved off SoftwareRelease, since different releases of the same compilation contain the same games). - Can itself be nested inside other compilations via SoftwareCompilationBySoftwareCompilation, a many-to-many junction (a sub-compilation can ship inside several different bundles). This also fixes a MobyGames importer bug where a compilation containing another compilation as one of its titles couldn't be resolved, because the original Software row backing the inner compilation was deleted with no replacement pointer recorded; MobyGamesImportState now gets a SoftwareCompilationId for exactly this case. Three migrations carry out the conversion: schema addition, a data backfill that converts existing IsCompilation=true releases into real SoftwareCompilation rows (re-pointing their releases, covers, and junction rows), and a cleanup migration dropping the old column/tables. Applied and verified against the dev database. Add SoftwareCompilationsController with CRUD, releases, covers, included-software/version junctions, and nested-compilation endpoints (with a cycle guard). Update SoftwareReleasesController, SoftwareController's catalog UNION queries, SearchController, and SoftwareReleaseSuggestionApplier to use SoftwareCompilationId instead of the removed IsCompilation flag. Remaining work (Marechai.ApiClient DTO mirrors, Blazor UI, Marechai.App compile fixes, MobyGames CompilationRelationService rewrite) is tracked separately and not yet included in this commit.
115 lines
4.8 KiB
C#
115 lines
4.8 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Marechai.Database.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class RemoveIsCompilationFromSoftwareReleases : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
// Safety net: any release that was flagged IsCompilation=1 but never picked up a
|
|
// SoftwareCompilationId in the backfill migration (e.g. rows inserted between the two
|
|
// migrations) has no owner at all once IsCompilation is dropped below — remove it
|
|
// outright rather than leave a dangling, unreachable release row.
|
|
migrationBuilder.Sql(
|
|
"""
|
|
DELETE FROM SoftwareReleases WHERE IsCompilation = 1 AND SoftwareCompilationId IS NULL;
|
|
""");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "LegacyReleaseId",
|
|
table: "SoftwareCompilations");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "SoftwareBySoftwareRelease");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "SoftwareVersionBySoftwareRelease");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "IsCompilation",
|
|
table: "SoftwareReleases");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<ulong>(
|
|
name: "LegacyReleaseId",
|
|
table: "SoftwareCompilations",
|
|
type: "bigint unsigned",
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<bool>(
|
|
name: "IsCompilation",
|
|
table: "SoftwareReleases",
|
|
type: "bit(1)",
|
|
nullable: false,
|
|
defaultValue: false);
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "SoftwareBySoftwareRelease",
|
|
columns: table => new
|
|
{
|
|
ReleaseId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
|
|
SoftwareId = table.Column<ulong>(type: "bigint unsigned", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_SoftwareBySoftwareRelease", x => new { x.ReleaseId, x.SoftwareId });
|
|
table.ForeignKey(
|
|
name: "FK_SoftwareBySoftwareRelease_SoftwareReleases_ReleaseId",
|
|
column: x => x.ReleaseId,
|
|
principalTable: "SoftwareReleases",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_SoftwareBySoftwareRelease_Softwares_SoftwareId",
|
|
column: x => x.SoftwareId,
|
|
principalTable: "Softwares",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "SoftwareVersionBySoftwareRelease",
|
|
columns: table => new
|
|
{
|
|
ReleaseId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
|
|
SoftwareVersionId = table.Column<ulong>(type: "bigint unsigned", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_SoftwareVersionBySoftwareRelease", x => new { x.ReleaseId, x.SoftwareVersionId });
|
|
table.ForeignKey(
|
|
name: "FK_SoftwareVersionBySoftwareRelease_SoftwareReleases_ReleaseId",
|
|
column: x => x.ReleaseId,
|
|
principalTable: "SoftwareReleases",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_SoftwareVersionBySoftwareRelease_SoftwareVersions_SoftwareVe~",
|
|
column: x => x.SoftwareVersionId,
|
|
principalTable: "SoftwareVersions",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_SoftwareBySoftwareRelease_SoftwareId",
|
|
table: "SoftwareBySoftwareRelease",
|
|
column: "SoftwareId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_SoftwareVersionBySoftwareRelease_SoftwareVersionId",
|
|
table: "SoftwareVersionBySoftwareRelease",
|
|
column: "SoftwareVersionId");
|
|
}
|
|
}
|
|
}
|