File tree Expand file tree Collapse file tree
packages/server/src/services Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -101,6 +101,18 @@ export const findEnvironmentsByProjectId = async (projectId: string) => {
101101 return projectEnvironments ;
102102} ;
103103
104+ const environmentHasServices = ( env : Awaited < ReturnType < typeof findEnvironmentById > > ) => {
105+ return (
106+ ( env . applications ?. length ?? 0 ) > 0 ||
107+ ( env . compose ?. length ?? 0 ) > 0 ||
108+ ( env . mariadb ?. length ?? 0 ) > 0 ||
109+ ( env . mongo ?. length ?? 0 ) > 0 ||
110+ ( env . mysql ?. length ?? 0 ) > 0 ||
111+ ( env . postgres ?. length ?? 0 ) > 0 ||
112+ ( env . redis ?. length ?? 0 ) > 0
113+ ) ;
114+ } ;
115+
104116export const deleteEnvironment = async ( environmentId : string ) => {
105117 const currentEnvironment = await findEnvironmentById ( environmentId ) ;
106118 if ( currentEnvironment . isDefault ) {
@@ -109,6 +121,13 @@ export const deleteEnvironment = async (environmentId: string) => {
109121 message : "You cannot delete the default environment" ,
110122 } ) ;
111123 }
124+ if ( environmentHasServices ( currentEnvironment ) ) {
125+ throw new TRPCError ( {
126+ code : "BAD_REQUEST" ,
127+ message :
128+ "Cannot delete environment: it has active services. Delete all services first." ,
129+ } ) ;
130+ }
112131 const deletedEnvironment = await db
113132 . delete ( environments )
114133 . where ( eq ( environments . environmentId , environmentId ) )
You can’t perform that action at this time.
0 commit comments