120 lines
4.4 KiB
PowerShell
120 lines
4.4 KiB
PowerShell
# PowerShell Script zum Setup der Appwrite-Datenbank
|
|
# Dieses Skript erstellt die Datenbank und führt das Schema-Setup aus
|
|
|
|
$ErrorActionPreference = "Continue"
|
|
|
|
Write-Host "=== Appwrite Datenbank Setup ===" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# 1. Prüfe Login-Status
|
|
Write-Host "1. Prüfe Appwrite Login-Status..." -ForegroundColor Yellow
|
|
$loginCheck = appwrite databases list 2>&1
|
|
|
|
if ($LASTEXITCODE -ne 0 -and $loginCheck -like "*Session not found*") {
|
|
Write-Host " [WARNUNG] Nicht eingeloggt. Bitte zuerst einloggen:" -ForegroundColor Red
|
|
Write-Host " appwrite login" -ForegroundColor White
|
|
Write-Host ""
|
|
Write-Host " Führe diesen Befehl jetzt aus..." -ForegroundColor Yellow
|
|
appwrite login
|
|
Write-Host ""
|
|
}
|
|
|
|
# 2. Erstelle oder verwende vorhandene Datenbank
|
|
$DATABASE_ID = "eship-db"
|
|
$DATABASE_NAME = "eship-database"
|
|
|
|
Write-Host "2. Prüfe ob Datenbank '$DATABASE_ID' existiert..." -ForegroundColor Yellow
|
|
|
|
# Versuche die Datenbank zu finden
|
|
$dbList = appwrite databases list 2>&1
|
|
$dbExists = $dbList -like "*$DATABASE_ID*"
|
|
|
|
if (-not $dbExists) {
|
|
Write-Host " Datenbank nicht gefunden. Erstelle neue Datenbank..." -ForegroundColor Yellow
|
|
$createResult = appwrite databases create --name $DATABASE_NAME --database-id $DATABASE_ID 2>&1
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " [OK] Datenbank '$DATABASE_ID' erfolgreich erstellt!" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " [WARNUNG] Fehler beim Erstellen der Datenbank." -ForegroundColor Yellow
|
|
Write-Host " Verwende ID: $DATABASE_ID" -ForegroundColor Gray
|
|
Write-Host " Stelle sicher, dass die Datenbank-ID korrekt ist." -ForegroundColor Yellow
|
|
}
|
|
} else {
|
|
Write-Host " [OK] Datenbank '$DATABASE_ID' existiert bereits!" -ForegroundColor Green
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "3. Erstelle Datenbank-Schema..." -ForegroundColor Yellow
|
|
Write-Host " Dies kann einige Minuten dauern..." -ForegroundColor Gray
|
|
Write-Host ""
|
|
|
|
# Aktualisiere DATABASE_ID im Bash-Skript
|
|
$schemaScriptContent = Get-Content "appwrite_schema.sh" -Raw -Encoding UTF8
|
|
$oldDatabaseIdPattern = 'DATABASE_ID="YOUR_DATABASE_ID"'
|
|
$newDatabaseIdValue = "DATABASE_ID=`"$DATABASE_ID`""
|
|
$schemaScriptContent = $schemaScriptContent -replace [regex]::Escape($oldDatabaseIdPattern), $newDatabaseIdValue
|
|
Set-Content -Path "appwrite_schema.sh" -Value $schemaScriptContent -NoNewline -Encoding UTF8
|
|
|
|
Write-Host " DATABASE_ID im Schema-Skript auf '$DATABASE_ID' gesetzt" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Prüfe ob Git Bash oder WSL verfügbar ist
|
|
$bashPath = $null
|
|
$useBash = $false
|
|
|
|
# Versuche Git Bash zu finden
|
|
if (Test-Path "C:\Program Files\Git\bin\bash.exe") {
|
|
$bashPath = "C:\Program Files\Git\bin\bash.exe"
|
|
$useBash = $true
|
|
} elseif (Test-Path "C:\Program Files (x86)\Git\bin\bash.exe") {
|
|
$bashPath = "C:\Program Files (x86)\Git\bin\bash.exe"
|
|
$useBash = $true
|
|
} else {
|
|
# Prüfe ob WSL verfügbar ist
|
|
$wslCheck = wsl --list 2>&1
|
|
if ($LASTEXITCODE -eq 0) {
|
|
$useBash = $true
|
|
$bashPath = "wsl"
|
|
}
|
|
}
|
|
|
|
if ($useBash) {
|
|
Write-Host "4. Führe Schema-Skript aus (über Bash)..." -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
$scriptPath = (Resolve-Path "appwrite_schema.sh").Path
|
|
|
|
if ($bashPath -eq "wsl") {
|
|
# Konvertiere Windows-Pfad zu WSL-Pfad
|
|
$driveLetter = $scriptPath.Substring(0, 1).ToLower()
|
|
$remainingPath = $scriptPath.Substring(3) -replace '\\', '/'
|
|
$wslPath = "/mnt/$driveLetter$remainingPath"
|
|
wsl bash $wslPath
|
|
} else {
|
|
& $bashPath $scriptPath
|
|
}
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host ""
|
|
Write-Host "[OK] Schema-Setup erfolgreich abgeschlossen!" -ForegroundColor Green
|
|
} else {
|
|
Write-Host ""
|
|
Write-Host "[WARNUNG] Schema-Setup abgeschlossen (einige Fehler wurden ignoriert)" -ForegroundColor Yellow
|
|
}
|
|
} else {
|
|
Write-Host "4. Bash nicht gefunden." -ForegroundColor Yellow
|
|
Write-Host ""
|
|
Write-Host " Option 1: Installiere Git Bash und führe dann aus:" -ForegroundColor White
|
|
Write-Host " bash appwrite_schema.sh" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host " Option 2: Siehe DATABASE_SETUP.md für manuelle Anweisungen" -ForegroundColor White
|
|
Write-Host ""
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "=== Setup abgeschlossen ===" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "Datenbank-ID: $DATABASE_ID" -ForegroundColor White
|
|
Write-Host "Du kannst die Datenbank in der Appwrite-Konsole überprüfen." -ForegroundColor Gray
|