Album is abstract with UserAlbum as its first table-per-type child, the same split Track already uses, so the YouTube albums can join later without moving anything. Tracks are linked through AlbumHasTrack rather than a column on the track itself: an external track is shared between users and the same song shows up in more than one album.
118 lines
5.2 KiB
C#
118 lines
5.2 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Musify.Infrastructure.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddAlbums : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Albums",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Title = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
|
NormalizedTitle = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
|
Description = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
|
ReleaseYear = table.Column<int>(type: "integer", nullable: true),
|
|
OriginalPictureName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
SmallPictureName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
MediumPictureName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
LargePictureName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
LifeCycleStatus = table.Column<int>(type: "integer", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Albums", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "AlbumHasTrack",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
AlbumId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
TrackId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
TrackNumber = table.Column<int>(type: "integer", nullable: false),
|
|
AddedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_AlbumHasTrack", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_AlbumHasTrack_Albums_AlbumId",
|
|
column: x => x.AlbumId,
|
|
principalTable: "Albums",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_AlbumHasTrack_Tracks_TrackId",
|
|
column: x => x.TrackId,
|
|
principalTable: "Tracks",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "UserAlbums",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
OwnerUserId = table.Column<long>(type: "bigint", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_UserAlbums", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_UserAlbums_Albums_Id",
|
|
column: x => x.Id,
|
|
principalTable: "Albums",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_UserAlbums_User_OwnerUserId",
|
|
column: x => x.OwnerUserId,
|
|
principalTable: "User",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AlbumHasTrack_AlbumId_TrackId",
|
|
table: "AlbumHasTrack",
|
|
columns: new[] { "AlbumId", "TrackId" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AlbumHasTrack_TrackId",
|
|
table: "AlbumHasTrack",
|
|
column: "TrackId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_UserAlbums_OwnerUserId",
|
|
table: "UserAlbums",
|
|
column: "OwnerUserId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "AlbumHasTrack");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "UserAlbums");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Albums");
|
|
}
|
|
}
|
|
}
|