Resolve "Flyway migrations"
This commit is contained in:
1 parent
fae59dd9bb
commit
41d6de7219
11 files changed
+132
-78
No files matched your search
@@ -0,0 +1,43 @@
|
||||
param (
|
||||
[ValidateSet("migrate", "info", "validate", "clean", "baseline", "repair")]
|
||||
[string]$Command = "info"
|
||||
)
|
||||
|
||||
$envFile = ".env"
|
||||
if (-not (Test-Path $envFile)) {
|
||||
Write-Error ".env file not found in the current directory."
|
||||
exit 1
|
||||
}
|
||||
|
||||
Get-Content $envFile | ForEach-Object {
|
||||
if ($_ -match "^\s*([A-Za-z_][A-Za-z0-9_]*)=(.*)$") {
|
||||
$name = $matches[1]
|
||||
$value = $matches[2]
|
||||
[System.Environment]::SetEnvironmentVariable($name, $value)
|
||||
}
|
||||
}
|
||||
|
||||
$MYSQL_HOST = $env:MYSQL_HOST
|
||||
$MYSQL_PORT = $env:MYSQL_PORT
|
||||
$MYSQL_DATABASE = $env:MYSQL_DATABASE
|
||||
|
||||
if (-not $MYSQL_HOST -or -not $MYSQL_PORT -or -not $MYSQL_DATABASE) {
|
||||
Write-Error "MYSQL_HOST, MYSQL_PORT, or MYSQL_DATABASE missing from .env"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$env:LOCALDEV_FLYWAY_URL = "jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}"
|
||||
$env:FLYWAY_URL = $env:LOCALDEV_FLYWAY_URL
|
||||
$env:FLYWAY_USER = $env:MYSQL_USER
|
||||
$env:FLYWAY_PASSWORD = $env:MYSQL_PASSWORD
|
||||
|
||||
Write-Host "Ensuring database '$MYSQL_DATABASE' exists..."
|
||||
$mysqlCommand = "CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||
& mysql --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$env:MYSQL_USER --password=$env:MYSQL_PASSWORD -e $mysqlCommand
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "Failed to create database or connect to MySQL. Check your credentials or server status."
|
||||
exit 1
|
||||
}
|
||||
|
||||
.\mvnw flyway:$Command
|
||||
Reference in new issue
Block a user