/*
  K_Recycle Installer - SQL post-install configuration
  - Ensures login [scale] exists with blank password
  - Grants sysadmin role for full database management
  - Mixed Mode authentication is enabled by Configure-SqlLogin.ps1 (registry + service restart)
*/
SET NOCOUNT ON;
GO

USE [master];
GO

IF NOT EXISTS (SELECT 1 FROM sys.server_principals WHERE name = N'scale')
BEGIN
    CREATE LOGIN [scale]
        WITH PASSWORD = N'',
             CHECK_POLICY = OFF,
             CHECK_EXPIRATION = OFF,
             DEFAULT_DATABASE = [master],
             DEFAULT_LANGUAGE = [us_english];
    PRINT N'Created login [scale].';
END
ELSE
BEGIN
    ALTER LOGIN [scale]
        WITH PASSWORD = N'',
             CHECK_POLICY = OFF,
             CHECK_EXPIRATION = OFF;
    PRINT N'Updated login [scale].';
END
GO

IF IS_SRVROLEMEMBER(N'sysadmin', N'scale') <> 1
BEGIN
    ALTER SERVER ROLE [sysadmin] ADD MEMBER [scale];
    PRINT N'Granted sysadmin to [scale].';
END
ELSE
BEGIN
    PRINT N'Login [scale] already has sysadmin.';
END
GO

PRINT N'SQL login configuration completed.';
GO
