DBMS / scripts /run_compat_2022_csv.ps1
vkhoa2110
Deploy SQL Server demo Space
f53fbd9
param(
[string]$Server = ".\SQLEXPRESS",
[string]$Database = "CustomerAIDemo2022",
[Parameter(Mandatory = $true)]
[string]$CsvPath,
[switch]$SqlAuth,
[string]$User,
[string]$Password
)
$ErrorActionPreference = "Stop"
$resolvedCsv = (Resolve-Path -LiteralPath $CsvPath).Path
if (-not (Test-Path -LiteralPath $resolvedCsv)) {
throw "CSV not found: $resolvedCsv"
}
$repoRoot = Split-Path -Parent $PSScriptRoot
$inputFile = Join-Path $repoRoot "sql\compat_2022_csv_seed.sql"
# sqlcmd's -v parser strips the drive letter from paths with colons (e.g. D:\...),
# so substitute the variables in PowerShell and pipe the rendered SQL via stdin.
$sql = Get-Content -LiteralPath $inputFile -Raw -Encoding UTF8
$sql = $sql -replace '\$\(DemoDatabase\)', $Database
$sql = $sql -replace '\$\(CsvPath\)', $resolvedCsv
$tempFile = [System.IO.Path]::GetTempFileName()
$tempFile = [System.IO.Path]::ChangeExtension($tempFile, '.sql')
[System.IO.File]::WriteAllText($tempFile, $sql, [System.Text.UTF8Encoding]::new($false))
$sqlcmdArgs = @(
"-S", $Server,
"-b",
"-f", "i:65001,o:65001",
"-i", $tempFile
)
if ($SqlAuth) {
$sqlcmdArgs += @("-U", $User, "-P", $Password)
} else {
$sqlcmdArgs += "-E"
}
Write-Host "Importing $resolvedCsv into $Server / $Database (fallback 2022 schema)..."
try {
& sqlcmd @sqlcmdArgs
} finally {
Remove-Item -LiteralPath $tempFile -Force -ErrorAction SilentlyContinue
}
if ($LASTEXITCODE -ne 0) {
throw "sqlcmd failed for $inputFile with exit code $LASTEXITCODE."
}
Write-Host ""
Write-Host "CSV import complete."
Write-Host "Next: .\scripts\build_real_embeddings_ollama.ps1 -Server '$Server' -Database '$Database' -Model 'bge-m3'"