// <copyright file="20260501000000_AddLibraryOptionsTable.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>

using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Jellyfin.Database.Providers.Postgres.Migrations
{
    /// <inheritdoc />
    public partial class AddLibraryOptionsTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql(@"
                CREATE TABLE IF NOT EXISTS library.""LibraryOptions"" (
                    ""LibraryPath"" text NOT NULL,
                    ""OptionsJson"" jsonb NOT NULL,
                    ""Version"" integer NOT NULL DEFAULT 1,
                    ""DateCreated"" timestamp with time zone NOT NULL DEFAULT now(),
                    ""DateModified"" timestamp with time zone NOT NULL DEFAULT now(),
                    CONSTRAINT ""PK_LibraryOptions"" PRIMARY KEY (""LibraryPath"")
                );
            ");

            migrationBuilder.Sql(@"
                CREATE INDEX IF NOT EXISTS ""IX_LibraryOptions_DateModified""
                ON library.""LibraryOptions"" (""DateModified"" DESC);
            ");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql(@"DROP TABLE IF EXISTS library.""LibraryOptions"" CASCADE;");
        }
    }
}
