@@ -4,6 +4,7 @@ import { useEffect } from "react";
44import { useFieldArray , useForm } from "react-hook-form" ;
55import { toast } from "sonner" ;
66import { z } from "zod" ;
7+ import { AlertBlock } from "@/components/shared/alert-block" ;
78import { Button } from "@/components/ui/button" ;
89import { Card , CardContent , CardHeader , CardTitle } from "@/components/ui/card" ;
910import {
@@ -18,6 +19,19 @@ import { Input } from "@/components/ui/input";
1819import { api } from "@/utils/api" ;
1920import type { ServiceType } from "../../application/advanced/show-resources" ;
2021
22+ const getPostgresMountPath = ( dockerImage : string ) : string => {
23+ const versionMatch = dockerImage . match ( / p o s t g r e s : ( \d + ) / ) ;
24+ if ( versionMatch ?. [ 1 ] ) {
25+ const version = Number . parseInt ( versionMatch [ 1 ] , 10 ) ;
26+ if ( version >= 18 ) {
27+ return `/var/lib/postgresql/${ version } /docker` ;
28+ }
29+ }
30+ return "/var/lib/postgresql/data" ;
31+ } ;
32+
33+ const POSTGRES_DATA_PATH_REGEX = / ^ \/ v a r \/ l i b \/ p o s t g r e s q l ( \/ | $ ) / ;
34+
2135const addDockerImage = z . object ( {
2236 dockerImage : z . string ( ) . min ( 1 , "Docker image is required" ) ,
2337 command : z . string ( ) ,
@@ -91,6 +105,22 @@ export const ShowCustomCommand = ({ id, type }: Props) => {
91105 }
92106 } , [ data , form ] ) ;
93107
108+ const dockerImage = form . watch ( "dockerImage" ) ;
109+
110+ const mountPathWarning = ( ( ) => {
111+ if ( type !== "postgres" || ! dockerImage ) return null ;
112+ const mounts = ( data as any ) ?. mounts ?? [ ] ;
113+ const dataMount = mounts . find (
114+ ( mount : { type : string ; mountPath : string } ) =>
115+ mount . type === "volume" &&
116+ POSTGRES_DATA_PATH_REGEX . test ( mount . mountPath ) ,
117+ ) ;
118+ if ( ! dataMount ) return null ;
119+ const expectedPath = getPostgresMountPath ( dockerImage ) ;
120+ if ( expectedPath === dataMount . mountPath ) return null ;
121+ return { expectedPath, currentPath : dataMount . mountPath } ;
122+ } ) ( ) ;
123+
94124 const onSubmit = async ( formData : AddDockerImage ) => {
95125 await mutateAsync ( {
96126 mongoId : id || "" ,
@@ -139,6 +169,18 @@ export const ShowCustomCommand = ({ id, type }: Props) => {
139169 </ FormItem >
140170 ) }
141171 />
172+ { mountPathWarning && (
173+ < AlertBlock type = "warning" >
174+ This image expects its data directory under{ " " }
175+ < code > { mountPathWarning . expectedPath } </ code > , but the
176+ volume of this database is mounted at{ " " }
177+ < code > { mountPathWarning . currentPath } </ code > . Changing the
178+ image does not migrate existing data — Postgres may
179+ crash-loop or start with an empty database. Adjust the
180+ volume mount path in the Volumes section or keep a
181+ compatible image before saving.
182+ </ AlertBlock >
183+ ) }
142184 </ div >
143185 < FormField
144186 control = { form . control }
0 commit comments