using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace VigilCareClinicalAPI.Migrations
{
    /// <inheritdoc />
    public partial class AddExternalResourceIdentifiers : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "external_resource_identifiers",
                columns: table => new
                {
                    id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
                    resource_type = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
                    internal_id = table.Column<Guid>(type: "uuid", nullable: false),
                    system = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
                    value = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
                    created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_external_resource_identifiers", x => x.id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_external_resource_identifiers_resource_type_internal_id",
                table: "external_resource_identifiers",
                columns: new[] { "resource_type", "internal_id" });

            migrationBuilder.CreateIndex(
                name: "IX_external_resource_identifiers_resource_type_system_value",
                table: "external_resource_identifiers",
                columns: new[] { "resource_type", "system", "value" },
                unique: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "external_resource_identifiers");
        }
    }
}
