refactor: move getMountPath function to services and update logic

- Moved the getMountPath function from the postgres router to the postgres service for better organization.
- Updated the logic to return the correct mount path based on the PostgreSQL version, ensuring compatibility with versions below 18.
This commit is contained in:
Mauricio Siu
2025-11-26 01:20:40 -05:00
parent d08fdeb939
commit 23b235303c
2 changed files with 13 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ import {
findMountsByApplicationId,
findPostgresById,
findProjectById,
getMountPath,
IS_CLOUD,
rebuildDatabase,
removePostgresById,
@@ -40,13 +41,6 @@ import {
} from "@/server/db/schema";
import { cancelJobs } from "@/server/utils/backup";
function getMountPath(dockerImage: string): string {
const versionMatch = dockerImage.match(/postgres:(\d+)/);
const version = versionMatch?.[1] ? Number.parseInt(versionMatch[1], 10) : 18;
return `/var/lib/postgresql/${version}/data`;
}
export const postgresRouter = createTRPCRouter({
create: protectedProcedure
.input(apiCreatePostgres)

View File

@@ -13,6 +13,18 @@ import { TRPCError } from "@trpc/server";
import { eq, getTableColumns } from "drizzle-orm";
import { validUniqueServerAppName } from "./project";
export function getMountPath(dockerImage: string): string {
const versionMatch = dockerImage.match(/postgres:(\d+)/);
if (versionMatch?.[1]) {
const version = Number.parseInt(versionMatch[1], 10);
if (version >= 18) {
return `/var/lib/postgresql/${version}/data`;
}
}
return "/var/lib/postgresql/data";
}
export type Postgres = typeof postgres.$inferSelect;
export const createPostgres = async (input: typeof apiCreatePostgres._type) => {