-- =============================================
-- Create mindzie Database with Correct Collation
-- =============================================
-- IMPORTANT: This script creates the mindzie database with the required collation.
-- The collation SQL_Latin1_General_CP1_CI_AS is REQUIRED for correct string comparisons.
--
-- Run this script on the SQL Server where you want to create the mindzie database.
-- You must have sysadmin or dbcreator permissions to run this script.
--
-- After creating the database, use the Configuration app to:
-- 1. Configure the database connection
-- 2. Run the schema update to create all tables
-- =============================================

USE [master]
GO

-- Check if database already exists
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'mindzie')
BEGIN
    RAISERROR('The mindzie database already exists. Drop it first if you want to recreate it.', 16, 1)
    RETURN
END

-- Create the database with the correct collation
-- SQL_Latin1_General_CP1_CI_AS breakdown:
--   SQL_Latin1_General = Latin alphabet sorting rules
--   CP1 = Code Page 1252 (Windows Western European)
--   CI = Case Insensitive (A = a)
--   AS = Accent Sensitive (a <> a with accent)
CREATE DATABASE [mindzie]
    COLLATE SQL_Latin1_General_CP1_CI_AS
GO

-- Verify the database was created with correct collation
SELECT
    name AS DatabaseName,
    collation_name AS Collation
FROM sys.databases
WHERE name = 'mindzie'
GO

PRINT 'mindzie database created successfully with collation SQL_Latin1_General_CP1_CI_AS'
GO
