fixes save
This commit is contained in:
93
devops/scripts/efcore/Scaffold-AllModules.ps1
Normal file
93
devops/scripts/efcore/Scaffold-AllModules.ps1
Normal file
@@ -0,0 +1,93 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Scaffolds EF Core DbContext, entities, and compiled models for all StellaOps modules.
|
||||
|
||||
.DESCRIPTION
|
||||
Iterates through all configured modules and runs Scaffold-Module.ps1 for each.
|
||||
Use this after schema changes or for initial setup.
|
||||
|
||||
.PARAMETER SkipMissing
|
||||
Skip modules whose projects don't exist yet (default: true)
|
||||
|
||||
.EXAMPLE
|
||||
.\Scaffold-AllModules.ps1
|
||||
|
||||
.EXAMPLE
|
||||
.\Scaffold-AllModules.ps1 -SkipMissing:$false
|
||||
#>
|
||||
param(
|
||||
[bool]$SkipMissing = $true
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Module definitions: Module name -> Schema name
|
||||
$modules = @(
|
||||
@{ Module = "Unknowns"; Schema = "unknowns" },
|
||||
@{ Module = "PacksRegistry"; Schema = "packs" },
|
||||
@{ Module = "Authority"; Schema = "authority" },
|
||||
@{ Module = "Scanner"; Schema = "scanner" },
|
||||
@{ Module = "Scheduler"; Schema = "scheduler" },
|
||||
@{ Module = "TaskRunner"; Schema = "taskrunner" },
|
||||
@{ Module = "Policy"; Schema = "policy" },
|
||||
@{ Module = "Notify"; Schema = "notify" },
|
||||
@{ Module = "Concelier"; Schema = "vuln" },
|
||||
@{ Module = "Excititor"; Schema = "vex" },
|
||||
@{ Module = "Signals"; Schema = "signals" },
|
||||
@{ Module = "Attestor"; Schema = "proofchain" },
|
||||
@{ Module = "Signer"; Schema = "signer" }
|
||||
)
|
||||
|
||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$RepoRoot = (Get-Item $ScriptDir).Parent.Parent.Parent.FullName
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "============================================================================" -ForegroundColor Cyan
|
||||
Write-Host " EF Core Scaffolding for All Modules" -ForegroundColor Cyan
|
||||
Write-Host "============================================================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
$successCount = 0
|
||||
$skipCount = 0
|
||||
$failCount = 0
|
||||
|
||||
foreach ($m in $modules) {
|
||||
$projectPath = Join-Path $RepoRoot "src" $m.Module "__Libraries" "StellaOps.$($m.Module).Persistence.EfCore"
|
||||
|
||||
if (-not (Test-Path "$projectPath\*.csproj")) {
|
||||
if ($SkipMissing) {
|
||||
Write-Host "SKIP: $($m.Module) - Project not found" -ForegroundColor DarkGray
|
||||
$skipCount++
|
||||
continue
|
||||
} else {
|
||||
Write-Host "FAIL: $($m.Module) - Project not found at: $projectPath" -ForegroundColor Red
|
||||
$failCount++
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host ">>> Scaffolding $($m.Module)..." -ForegroundColor Magenta
|
||||
|
||||
try {
|
||||
& "$ScriptDir\Scaffold-Module.ps1" -Module $m.Module -Schema $m.Schema
|
||||
$successCount++
|
||||
}
|
||||
catch {
|
||||
Write-Host "FAIL: $($m.Module) - $($_.Exception.Message)" -ForegroundColor Red
|
||||
$failCount++
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "============================================================================" -ForegroundColor Cyan
|
||||
Write-Host " Summary" -ForegroundColor Cyan
|
||||
Write-Host "============================================================================" -ForegroundColor Cyan
|
||||
Write-Host " Success: $successCount"
|
||||
Write-Host " Skipped: $skipCount"
|
||||
Write-Host " Failed: $failCount"
|
||||
Write-Host ""
|
||||
|
||||
if ($failCount -gt 0) {
|
||||
exit 1
|
||||
}
|
||||
162
devops/scripts/efcore/Scaffold-Module.ps1
Normal file
162
devops/scripts/efcore/Scaffold-Module.ps1
Normal file
@@ -0,0 +1,162 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Scaffolds EF Core DbContext, entities, and compiled models from PostgreSQL schema.
|
||||
|
||||
.DESCRIPTION
|
||||
This script performs database-first scaffolding for a StellaOps module:
|
||||
1. Cleans existing generated files (Entities, CompiledModels, DbContext)
|
||||
2. Scaffolds DbContext and entities from live PostgreSQL schema
|
||||
3. Generates compiled models for startup performance
|
||||
|
||||
.PARAMETER Module
|
||||
The module name (e.g., Unknowns, PacksRegistry, Authority)
|
||||
|
||||
.PARAMETER Schema
|
||||
The PostgreSQL schema name (defaults to lowercase module name)
|
||||
|
||||
.PARAMETER ConnectionString
|
||||
PostgreSQL connection string. If not provided, uses default dev connection.
|
||||
|
||||
.PARAMETER ProjectPath
|
||||
Optional custom project path. Defaults to src/{Module}/__Libraries/StellaOps.{Module}.Persistence.EfCore
|
||||
|
||||
.EXAMPLE
|
||||
.\Scaffold-Module.ps1 -Module Unknowns
|
||||
|
||||
.EXAMPLE
|
||||
.\Scaffold-Module.ps1 -Module Unknowns -Schema unknowns -ConnectionString "Host=localhost;Database=stellaops_platform;Username=unknowns_user;Password=unknowns_dev"
|
||||
|
||||
.EXAMPLE
|
||||
.\Scaffold-Module.ps1 -Module PacksRegistry -Schema packs
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$Module,
|
||||
|
||||
[string]$Schema,
|
||||
|
||||
[string]$ConnectionString,
|
||||
|
||||
[string]$ProjectPath
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Resolve repository root
|
||||
$RepoRoot = (Get-Item $PSScriptRoot).Parent.Parent.Parent.FullName
|
||||
|
||||
# Default schema to lowercase module name
|
||||
if (-not $Schema) {
|
||||
$Schema = $Module.ToLower()
|
||||
}
|
||||
|
||||
# Default connection string
|
||||
if (-not $ConnectionString) {
|
||||
$user = "${Schema}_user"
|
||||
$password = "${Schema}_dev"
|
||||
$ConnectionString = "Host=localhost;Port=5432;Database=stellaops_platform;Username=$user;Password=$password;SearchPath=$Schema"
|
||||
}
|
||||
|
||||
# Default project path
|
||||
if (-not $ProjectPath) {
|
||||
$ProjectPath = Join-Path $RepoRoot "src" $Module "__Libraries" "StellaOps.$Module.Persistence.EfCore"
|
||||
}
|
||||
|
||||
$ContextDir = "Context"
|
||||
$EntitiesDir = "Entities"
|
||||
$CompiledModelsDir = "CompiledModels"
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "============================================================================" -ForegroundColor Cyan
|
||||
Write-Host " EF Core Scaffolding for Module: $Module" -ForegroundColor Cyan
|
||||
Write-Host "============================================================================" -ForegroundColor Cyan
|
||||
Write-Host " Schema: $Schema"
|
||||
Write-Host " Project: $ProjectPath"
|
||||
Write-Host " Connection: Host=localhost;Database=stellaops_platform;Username=${Schema}_user;..."
|
||||
Write-Host ""
|
||||
|
||||
# Verify project exists
|
||||
if (-not (Test-Path "$ProjectPath\*.csproj")) {
|
||||
Write-Error "Project not found at: $ProjectPath"
|
||||
Write-Host "Create the project first with: dotnet new classlib -n StellaOps.$Module.Persistence.EfCore"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Step 1: Clean existing generated files
|
||||
Write-Host "[1/4] Cleaning existing generated files..." -ForegroundColor Yellow
|
||||
$paths = @(
|
||||
(Join-Path $ProjectPath $EntitiesDir),
|
||||
(Join-Path $ProjectPath $CompiledModelsDir),
|
||||
(Join-Path $ProjectPath $ContextDir "${Module}DbContext.cs")
|
||||
)
|
||||
foreach ($path in $paths) {
|
||||
if (Test-Path $path) {
|
||||
Remove-Item -Recurse -Force $path
|
||||
Write-Host " Removed: $path" -ForegroundColor DarkGray
|
||||
}
|
||||
}
|
||||
|
||||
# Recreate directories
|
||||
New-Item -ItemType Directory -Force -Path (Join-Path $ProjectPath $EntitiesDir) | Out-Null
|
||||
New-Item -ItemType Directory -Force -Path (Join-Path $ProjectPath $CompiledModelsDir) | Out-Null
|
||||
New-Item -ItemType Directory -Force -Path (Join-Path $ProjectPath $ContextDir) | Out-Null
|
||||
|
||||
# Step 2: Scaffold DbContext and entities
|
||||
Write-Host "[2/4] Scaffolding DbContext and entities from schema '$Schema'..." -ForegroundColor Yellow
|
||||
$scaffoldArgs = @(
|
||||
"ef", "dbcontext", "scaffold",
|
||||
"`"$ConnectionString`"",
|
||||
"Npgsql.EntityFrameworkCore.PostgreSQL",
|
||||
"--project", "`"$ProjectPath`"",
|
||||
"--schema", $Schema,
|
||||
"--context", "${Module}DbContext",
|
||||
"--context-dir", $ContextDir,
|
||||
"--output-dir", $EntitiesDir,
|
||||
"--namespace", "StellaOps.$Module.Persistence.EfCore.Entities",
|
||||
"--context-namespace", "StellaOps.$Module.Persistence.EfCore.Context",
|
||||
"--data-annotations",
|
||||
"--no-onconfiguring",
|
||||
"--force"
|
||||
)
|
||||
|
||||
$process = Start-Process -FilePath "dotnet" -ArgumentList $scaffoldArgs -Wait -PassThru -NoNewWindow
|
||||
if ($process.ExitCode -ne 0) {
|
||||
Write-Error "Scaffold failed with exit code: $($process.ExitCode)"
|
||||
exit 1
|
||||
}
|
||||
Write-Host " Scaffolded entities to: $EntitiesDir" -ForegroundColor DarkGray
|
||||
|
||||
# Step 3: Generate compiled models
|
||||
Write-Host "[3/4] Generating compiled models..." -ForegroundColor Yellow
|
||||
$optimizeArgs = @(
|
||||
"ef", "dbcontext", "optimize",
|
||||
"--project", "`"$ProjectPath`"",
|
||||
"--context", "StellaOps.$Module.Persistence.EfCore.Context.${Module}DbContext",
|
||||
"--output-dir", $CompiledModelsDir,
|
||||
"--namespace", "StellaOps.$Module.Persistence.EfCore.CompiledModels"
|
||||
)
|
||||
|
||||
$process = Start-Process -FilePath "dotnet" -ArgumentList $optimizeArgs -Wait -PassThru -NoNewWindow
|
||||
if ($process.ExitCode -ne 0) {
|
||||
Write-Error "Compiled model generation failed with exit code: $($process.ExitCode)"
|
||||
exit 1
|
||||
}
|
||||
Write-Host " Generated compiled models to: $CompiledModelsDir" -ForegroundColor DarkGray
|
||||
|
||||
# Step 4: Summary
|
||||
Write-Host "[4/4] Scaffolding complete!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Generated files:" -ForegroundColor Cyan
|
||||
$contextFile = Join-Path $ProjectPath $ContextDir "${Module}DbContext.cs"
|
||||
$entityFiles = Get-ChildItem -Path (Join-Path $ProjectPath $EntitiesDir) -Filter "*.cs" -ErrorAction SilentlyContinue
|
||||
$compiledFiles = Get-ChildItem -Path (Join-Path $ProjectPath $CompiledModelsDir) -Filter "*.cs" -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host " Context: $(if (Test-Path $contextFile) { $contextFile } else { 'Not found' })"
|
||||
Write-Host " Entities: $($entityFiles.Count) files"
|
||||
Write-Host " Compiled Models: $($compiledFiles.Count) files"
|
||||
Write-Host ""
|
||||
Write-Host "Next steps:" -ForegroundColor Yellow
|
||||
Write-Host " 1. Review generated entities for any customization needs"
|
||||
Write-Host " 2. Create repository implementations in Repositories/"
|
||||
Write-Host " 3. Add DI registration in Extensions/"
|
||||
Write-Host ""
|
||||
88
devops/scripts/efcore/scaffold-all-modules.sh
Normal file
88
devops/scripts/efcore/scaffold-all-modules.sh
Normal file
@@ -0,0 +1,88 @@
|
||||
#!/bin/bash
|
||||
# ============================================================================
|
||||
# EF Core Scaffolding for All StellaOps Modules
|
||||
# ============================================================================
|
||||
# Iterates through all configured modules and runs scaffold-module.sh for each.
|
||||
# Use this after schema changes or for initial setup.
|
||||
#
|
||||
# Usage: ./scaffold-all-modules.sh [--no-skip-missing]
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
SKIP_MISSING=true
|
||||
if [ "$1" = "--no-skip-missing" ]; then
|
||||
SKIP_MISSING=false
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
|
||||
|
||||
# Module definitions: "Module:Schema"
|
||||
MODULES=(
|
||||
"Unknowns:unknowns"
|
||||
"PacksRegistry:packs"
|
||||
"Authority:authority"
|
||||
"Scanner:scanner"
|
||||
"Scheduler:scheduler"
|
||||
"TaskRunner:taskrunner"
|
||||
"Policy:policy"
|
||||
"Notify:notify"
|
||||
"Concelier:vuln"
|
||||
"Excititor:vex"
|
||||
"Signals:signals"
|
||||
"Attestor:proofchain"
|
||||
"Signer:signer"
|
||||
)
|
||||
|
||||
echo ""
|
||||
echo "============================================================================"
|
||||
echo " EF Core Scaffolding for All Modules"
|
||||
echo "============================================================================"
|
||||
echo ""
|
||||
|
||||
SUCCESS_COUNT=0
|
||||
SKIP_COUNT=0
|
||||
FAIL_COUNT=0
|
||||
|
||||
for entry in "${MODULES[@]}"; do
|
||||
MODULE="${entry%%:*}"
|
||||
SCHEMA="${entry##*:}"
|
||||
|
||||
PROJECT_PATH="$REPO_ROOT/src/$MODULE/__Libraries/StellaOps.$MODULE.Persistence.EfCore"
|
||||
|
||||
if [ ! -f "$PROJECT_PATH"/*.csproj ]; then
|
||||
if [ "$SKIP_MISSING" = true ]; then
|
||||
echo "SKIP: $MODULE - Project not found"
|
||||
((SKIP_COUNT++))
|
||||
continue
|
||||
else
|
||||
echo "FAIL: $MODULE - Project not found at: $PROJECT_PATH"
|
||||
((FAIL_COUNT++))
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo ">>> Scaffolding $MODULE..."
|
||||
|
||||
if "$SCRIPT_DIR/scaffold-module.sh" "$MODULE" "$SCHEMA"; then
|
||||
((SUCCESS_COUNT++))
|
||||
else
|
||||
echo "FAIL: $MODULE - Scaffolding failed"
|
||||
((FAIL_COUNT++))
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "============================================================================"
|
||||
echo " Summary"
|
||||
echo "============================================================================"
|
||||
echo " Success: $SUCCESS_COUNT"
|
||||
echo " Skipped: $SKIP_COUNT"
|
||||
echo " Failed: $FAIL_COUNT"
|
||||
echo ""
|
||||
|
||||
if [ "$FAIL_COUNT" -gt 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
113
devops/scripts/efcore/scaffold-module.sh
Normal file
113
devops/scripts/efcore/scaffold-module.sh
Normal file
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
# ============================================================================
|
||||
# EF Core Scaffolding Script for StellaOps Modules
|
||||
# ============================================================================
|
||||
# Usage: ./scaffold-module.sh <Module> [Schema] [ConnectionString]
|
||||
#
|
||||
# Examples:
|
||||
# ./scaffold-module.sh Unknowns
|
||||
# ./scaffold-module.sh Unknowns unknowns
|
||||
# ./scaffold-module.sh PacksRegistry packs "Host=localhost;..."
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
MODULE=$1
|
||||
SCHEMA=${2:-$(echo "$MODULE" | tr '[:upper:]' '[:lower:]')}
|
||||
CONNECTION_STRING=$3
|
||||
|
||||
if [ -z "$MODULE" ]; then
|
||||
echo "Usage: $0 <Module> [Schema] [ConnectionString]"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 Unknowns"
|
||||
echo " $0 Unknowns unknowns"
|
||||
echo " $0 PacksRegistry packs \"Host=localhost;Database=stellaops_platform;Username=packs_user;Password=packs_dev\""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Resolve repository root
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
|
||||
|
||||
# Default connection string
|
||||
if [ -z "$CONNECTION_STRING" ]; then
|
||||
USER="${SCHEMA}_user"
|
||||
PASSWORD="${SCHEMA}_dev"
|
||||
CONNECTION_STRING="Host=localhost;Port=5432;Database=stellaops_platform;Username=$USER;Password=$PASSWORD;SearchPath=$SCHEMA"
|
||||
fi
|
||||
|
||||
PROJECT_DIR="$REPO_ROOT/src/$MODULE/__Libraries/StellaOps.$MODULE.Persistence.EfCore"
|
||||
CONTEXT_DIR="Context"
|
||||
ENTITIES_DIR="Entities"
|
||||
COMPILED_DIR="CompiledModels"
|
||||
|
||||
echo ""
|
||||
echo "============================================================================"
|
||||
echo " EF Core Scaffolding for Module: $MODULE"
|
||||
echo "============================================================================"
|
||||
echo " Schema: $SCHEMA"
|
||||
echo " Project: $PROJECT_DIR"
|
||||
echo " Connection: Host=localhost;Database=stellaops_platform;Username=${SCHEMA}_user;..."
|
||||
echo ""
|
||||
|
||||
# Verify project exists
|
||||
if [ ! -f "$PROJECT_DIR"/*.csproj ]; then
|
||||
echo "ERROR: Project not found at: $PROJECT_DIR"
|
||||
echo "Create the project first with: dotnet new classlib -n StellaOps.$MODULE.Persistence.EfCore"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Step 1: Clean existing generated files
|
||||
echo "[1/4] Cleaning existing generated files..."
|
||||
rm -rf "$PROJECT_DIR/$ENTITIES_DIR"
|
||||
rm -rf "$PROJECT_DIR/$COMPILED_DIR"
|
||||
rm -f "$PROJECT_DIR/$CONTEXT_DIR/${MODULE}DbContext.cs"
|
||||
|
||||
mkdir -p "$PROJECT_DIR/$ENTITIES_DIR"
|
||||
mkdir -p "$PROJECT_DIR/$COMPILED_DIR"
|
||||
mkdir -p "$PROJECT_DIR/$CONTEXT_DIR"
|
||||
|
||||
echo " Cleaned: $ENTITIES_DIR, $COMPILED_DIR, ${MODULE}DbContext.cs"
|
||||
|
||||
# Step 2: Scaffold DbContext and entities
|
||||
echo "[2/4] Scaffolding DbContext and entities from schema '$SCHEMA'..."
|
||||
dotnet ef dbcontext scaffold \
|
||||
"$CONNECTION_STRING" \
|
||||
Npgsql.EntityFrameworkCore.PostgreSQL \
|
||||
--project "$PROJECT_DIR" \
|
||||
--schema "$SCHEMA" \
|
||||
--context "${MODULE}DbContext" \
|
||||
--context-dir "$CONTEXT_DIR" \
|
||||
--output-dir "$ENTITIES_DIR" \
|
||||
--namespace "StellaOps.$MODULE.Persistence.EfCore.Entities" \
|
||||
--context-namespace "StellaOps.$MODULE.Persistence.EfCore.Context" \
|
||||
--data-annotations \
|
||||
--no-onconfiguring \
|
||||
--force
|
||||
|
||||
echo " Scaffolded entities to: $ENTITIES_DIR"
|
||||
|
||||
# Step 3: Generate compiled models
|
||||
echo "[3/4] Generating compiled models..."
|
||||
dotnet ef dbcontext optimize \
|
||||
--project "$PROJECT_DIR" \
|
||||
--context "StellaOps.$MODULE.Persistence.EfCore.Context.${MODULE}DbContext" \
|
||||
--output-dir "$COMPILED_DIR" \
|
||||
--namespace "StellaOps.$MODULE.Persistence.EfCore.CompiledModels"
|
||||
|
||||
echo " Generated compiled models to: $COMPILED_DIR"
|
||||
|
||||
# Step 4: Summary
|
||||
echo "[4/4] Scaffolding complete!"
|
||||
echo ""
|
||||
echo "Generated files:"
|
||||
echo " Context: $PROJECT_DIR/$CONTEXT_DIR/${MODULE}DbContext.cs"
|
||||
echo " Entities: $(ls -1 "$PROJECT_DIR/$ENTITIES_DIR"/*.cs 2>/dev/null | wc -l) files"
|
||||
echo " Compiled Models: $(ls -1 "$PROJECT_DIR/$COMPILED_DIR"/*.cs 2>/dev/null | wc -l) files"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo " 1. Review generated entities for any customization needs"
|
||||
echo " 2. Create repository implementations in Repositories/"
|
||||
echo " 3. Add DI registration in Extensions/"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user