# sql/helper_scripts/generate_rollup.ps1
<#
.SYNOPSIS
    SQL ROLLUP GENERATION SCRIPT (POWERSHELL)
.DESCRIPTION
    This script automatically generates the 'master_schema_rollup.sql' file by
    concatenating the individual SQL component files in the correct order.

    WARNING: This will overwrite the existing master_schema_rollup.sql file.
.EXAMPLE
    From the root of the project, run:
    .\sql\generate_rollup.ps1
#>

# Set the script to stop on errors
$ErrorActionPreference = "Stop"

# Define file paths relative to the script's location
$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$ProjectRoot = Resolve-Path -Path (Join-Path $PSScriptRoot "..")
$MasterFile = Join-Path $ProjectRoot "sql\master_schema_rollup.sql"

# The individual files to concatenate, IN ORDER.
$SourceFiles = @(
    (Join-Path $ProjectRoot "sql\initial_schema.sql"),
    (Join-Path $ProjectRoot "sql\initial_data.sql"),
    (Join-Path $ProjectRoot "sql\initial_triggers_and_functions.sql")
)

Write-Host "Generating '$MasterFile' from source files..."
Get-Content -Path $SourceFiles | Set-Content -Path $MasterFile -Encoding UTF8
Write-Host "✅ Success: '$MasterFile' has been generated." -ForegroundColor Green
