using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace e_suite.Database.SqlServer.Migrations
{
    public partial class InitialDatabase : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            var configuration = ESuiteDatabaseExtension.BuildConfiguration();
            if (!ESuiteDatabaseExtension.IsAzure(configuration))
            {
                migrationBuilder.Sql("sp_configure 'contained database authentication', 1;", true);
                migrationBuilder.Sql("RECONFIGURE", true);

                migrationBuilder.Sql("ALTER DATABASE [[DatabaseNameToReplace]] SET RECOVERY SIMPLE", true);
                migrationBuilder.Sql("ALTER DATABASE [[DatabaseNameToReplace]] SET CONTAINMENT = PARTIAL WITH NO_WAIT", true);
            }

            migrationBuilder.Sql("CREATE USER [[DatabaseNameToReplace]ApplicationUser] WITH PASSWORD=N'Plz change me on live, thank you', DEFAULT_SCHEMA=[dbo]");
            migrationBuilder.Sql("ALTER ROLE[db_datareader] ADD MEMBER [[DatabaseNameToReplace]ApplicationUser]");
            migrationBuilder.Sql("ALTER ROLE[db_datawriter] ADD MEMBER [[DatabaseNameToReplace]ApplicationUser]");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
        }
    }
}
