#Requires -Version 5.1 <# .SYNOPSIS RasterizedDB: a server for development on this machine only. PostgreSQL on 127.0.0.1:5432 and the native protocol on 127.0.0.1:61170, no TLS. Runs in the foreground; Ctrl+C stops it cleanly. .EXAMPLE .\setup.ps1 .\setup.ps1 -Data memory -PgPort 55432 #> [CmdletBinding()] param( [string]$RdbBin = $(if ($env:RDB_BIN) { $env:RDB_BIN } else { 'rasterizeddb.exe' }), # The database directory; 'memory' keeps everything in memory. [string]$Data = $(if ($env:RDB_DATA) { $env:RDB_DATA } else { '.\data' }), [int]$PgPort = $(if ($env:RDB_PG_PORT) { [int]$env:RDB_PG_PORT } else { 5432 }), [int]$Port = $(if ($env:RDB_PORT) { [int]$env:RDB_PORT } else { 61170 }), [string]$User = $(if ($env:RDB_USER) { $env:RDB_USER } else { 'rasterized' }), [string]$LogLevel = $(if ($env:RDB_LOG_LEVEL) { $env:RDB_LOG_LEVEL } else { 'info' }) ) $ErrorActionPreference = 'Stop' $cmd = Get-Command $RdbBin -ErrorAction SilentlyContinue if (-not $cmd) { throw "'$RdbBin' not found; install it (see the install script) or pass -RdbBin with its path." } # The first start creates the role $User with this password. Set # $env:RASTERIZEDDB_PG_PASSWORD yourself, or one is made up and printed. if (-not $env:RASTERIZEDDB_PG_PASSWORD) { $env:RASTERIZEDDB_PG_PASSWORD = 'dev-' + (-join (1..12 | ForEach-Object { '{0:x}' -f (Get-Random -Maximum 16) })) Write-Host "RASTERIZEDDB_PG_PASSWORD was not set; using $env:RASTERIZEDDB_PG_PASSWORD" Write-Host '(it only takes effect on a new data directory; an existing one keeps its role''s password)' } if ($Data -eq 'memory') { $where = @('--in-memory') } else { New-Item -ItemType Directory -Force -Path $Data | Out-Null $Data = (Resolve-Path -LiteralPath $Data).Path $where = @('--location', $Data) } $serverArgs = $where + @( '--protocol', 'both', '--pg-addr', '127.0.0.1', '--pg-port', "$PgPort", '--pg-tls', 'disable', '--pg-user', $User, '--rdb-addr', '127.0.0.1', '--rdb-port', "$Port", '--log-level', $LogLevel ) Write-Host '' Write-Host "PostgreSQL: postgresql://${User}:$($env:RASTERIZEDDB_PG_PASSWORD)@127.0.0.1:$PgPort/postgres?sslmode=disable" Write-Host "Native: 127.0.0.1:$Port (user $User, same password)" Write-Host 'Stop with Ctrl+C.' Write-Host '' & $cmd.Source @serverArgs exit $LASTEXITCODE