feat: DB backend and API implemementation
This commit is contained in:
1 parent
39b891cd63
commit
a78e84515a
14 files changed
+955
-652
No files matched your search
@@ -0,0 +1,34 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$ComposeFile,
|
||||
[string]$MigrationDirectory
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$scriptDirectory = Split-Path -Parent $PSCommandPath
|
||||
if ([string]::IsNullOrWhiteSpace($scriptDirectory)) {
|
||||
$scriptDirectory = (Get-Location).Path
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($ComposeFile)) {
|
||||
$ComposeFile = Join-Path $scriptDirectory '..\docker-compose.yml'
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($MigrationDirectory)) {
|
||||
$MigrationDirectory = Join-Path $scriptDirectory '..\database\migrations'
|
||||
}
|
||||
|
||||
if (-not (Test-Path -LiteralPath $MigrationDirectory -PathType Container)) {
|
||||
throw "Das Migrationsverzeichnis '$MigrationDirectory' wurde nicht gefunden."
|
||||
}
|
||||
|
||||
$composeFile = (Resolve-Path -LiteralPath $ComposeFile).Path
|
||||
$migrations = Get-ChildItem -LiteralPath $MigrationDirectory -Filter '*.sql' -File | Sort-Object Name
|
||||
|
||||
foreach ($migration in $migrations) {
|
||||
$sql = Get-Content -LiteralPath $migration.FullName -Raw
|
||||
$sql | & docker compose -f $composeFile exec -T db sh -lc 'exec mariadb -u"$MARIADB_USER" -p"$MARIADB_PASSWORD" "$MARIADB_DATABASE"'
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Migration '$($migration.Name)' ist fehlgeschlagen."
|
||||
}
|
||||
|
||||
Write-Host "Migration ausgeführt: $($migration.Name)"
|
||||
}
|
||||
Reference in new issue
Block a user