@@ -708,6 +708,40 @@ function Resolve-ServiceComposeConfiguration {
708708 return Resolve-ConfigSources - Sources $sources - BasePath $ComposeDir - IncludeTrace
709709}
710710
711+ function Get-DatabaseStateWarningMessage {
712+ [CmdletBinding ()]
713+ param (
714+ [string ]$ServiceName ,
715+ [string ]$DataPath
716+ )
717+
718+ $candidateFiles = switch ($ServiceName ) {
719+ ' postgre' {
720+ @ (
721+ [System.IO.Path ]::Combine($DataPath , ' postgresql' , ' data' , ' PG_VERSION' ),
722+ [System.IO.Path ]::Combine($DataPath , ' postgresql' , ' PG_VERSION' )
723+ )
724+ }
725+ ' paradedb' {
726+ @ (
727+ [System.IO.Path ]::Combine($DataPath , ' paradedb' , ' data' , ' PG_VERSION' ),
728+ [System.IO.Path ]::Combine($DataPath , ' paradedb' , ' PG_VERSION' )
729+ )
730+ }
731+ default {
732+ @ ()
733+ }
734+ }
735+
736+ foreach ($candidate in $candidateFiles ) {
737+ if (Test-Path - LiteralPath $candidate ) {
738+ return " 检测到已初始化的 $ServiceName 数据目录 ($candidate )。当前用户名、密码、库名配置仅影响新初始化实例;已有数据目录不会自动迁移内部角色、密码或默认库。"
739+ }
740+ }
741+
742+ return $null
743+ }
744+
711745# 测试加载脚本时跳过主流程,避免 dot-source 触发真实 Docker 调用。
712746if ($env: PWSH_TEST_SKIP_START_CONTAINER_MAIN -eq ' 1' ) {
713747 return
@@ -795,6 +829,8 @@ try {
795829 }
796830
797831 if ($Update ) {
832+ $databaseWarning = Get-DatabaseStateWarningMessage - ServiceName $ServiceName - DataPath $composeEnvironment.DATA_PATH
833+ if (-not [string ]::IsNullOrWhiteSpace($databaseWarning )) { Write-Warning $databaseWarning }
798834 Invoke-DockerCompose - File $composePath - Project $projectName - Profiles $targetProfiles - Action ' pull' - Environment $composeEnvironment - DryRun:$DryRun
799835 Invoke-DockerCompose - File $composePath - Project $projectName - Profiles $targetProfiles - Action ' up -d' - Environment $composeEnvironment - DryRun:$DryRun
800836 if (-not $DryRun -and $ServiceName ) {
@@ -810,6 +846,8 @@ try {
810846 if ($PullAlways ) {
811847 $modeForUp = Test-DockerAvailable
812848 if ($modeForUp -eq ' sub' ) {
849+ $databaseWarning = Get-DatabaseStateWarningMessage - ServiceName $ServiceName - DataPath $composeEnvironment.DATA_PATH
850+ if (-not [string ]::IsNullOrWhiteSpace($databaseWarning )) { Write-Warning $databaseWarning }
813851 Invoke-DockerCompose - File $composePath - Project $projectName - Profiles $targetProfiles - Action ' up -d' - ExtraArgs @ (' --pull' , ' always' ) - Environment $composeEnvironment - DryRun:$DryRun
814852 if (-not $DryRun -and $ServiceName ) {
815853 foreach ($tp in $targetProfiles ) {
@@ -820,6 +858,8 @@ try {
820858 }
821859 }
822860 else {
861+ $databaseWarning = Get-DatabaseStateWarningMessage - ServiceName $ServiceName - DataPath $composeEnvironment.DATA_PATH
862+ if (-not [string ]::IsNullOrWhiteSpace($databaseWarning )) { Write-Warning $databaseWarning }
823863 Invoke-DockerCompose - File $composePath - Project $projectName - Profiles $targetProfiles - Action ' pull' - Environment $composeEnvironment - DryRun:$DryRun
824864 Invoke-DockerCompose - File $composePath - Project $projectName - Profiles $targetProfiles - Action ' up -d' - Environment $composeEnvironment - DryRun:$DryRun
825865 if (-not $DryRun -and $ServiceName ) {
@@ -858,6 +898,8 @@ try {
858898 if ($ServiceName -eq ' beszel-suite' -or $ServiceName -eq ' rustdesk' ) { $isValidService = $true }
859899
860900 if ($isValidService ) {
901+ $databaseWarning = Get-DatabaseStateWarningMessage - ServiceName $ServiceName - DataPath $composeEnvironment.DATA_PATH
902+ if (-not [string ]::IsNullOrWhiteSpace($databaseWarning )) { Write-Warning $databaseWarning }
861903 Invoke-DockerCompose - File $composePath - Project $projectName - Profiles $targetProfiles - Action ' up -d' - Environment $composeEnvironment - DryRun:$DryRun
862904 if (-not $DryRun ) {
863905 foreach ($tp in $targetProfiles ) {
0 commit comments