mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-16 00:45:18 +00:00
refactor(mount): streamline service type handling and improve organization ID retrieval
- Updated service type checks in the getBaseFilesPath and getServerId functions to use application and service IDs for better clarity and reliability. - Removed redundant service type checks and adjusted logic to enhance maintainability. - Added 'libsql' to the server relations in the schema for improved service management.
This commit is contained in:
@@ -13,13 +13,14 @@ import {
|
|||||||
getServiceContainer,
|
getServiceContainer,
|
||||||
updateMount,
|
updateMount,
|
||||||
} from "@dokploy/server";
|
} from "@dokploy/server";
|
||||||
|
import type { ServiceType } from "@dokploy/server/services/mount";
|
||||||
import {
|
import {
|
||||||
checkServiceAccess,
|
checkServiceAccess,
|
||||||
checkServicePermissionAndAccess,
|
checkServicePermissionAndAccess,
|
||||||
} from "@dokploy/server/services/permission";
|
} from "@dokploy/server/services/permission";
|
||||||
import type { ServiceType } from "@dokploy/server/db/schema/mount";
|
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { audit } from "@/server/api/utils/audit";
|
||||||
import {
|
import {
|
||||||
apiCreateMount,
|
apiCreateMount,
|
||||||
apiFindMountByApplicationId,
|
apiFindMountByApplicationId,
|
||||||
@@ -28,7 +29,6 @@ import {
|
|||||||
apiUpdateMount,
|
apiUpdateMount,
|
||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
||||||
import { audit } from "@/server/api/utils/audit";
|
|
||||||
|
|
||||||
async function getServiceOrganizationId(
|
async function getServiceOrganizationId(
|
||||||
serviceId: string,
|
serviceId: string,
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ export const serverRelations = relations(server, ({ one, many }) => ({
|
|||||||
relationName: "applicationBuildServer",
|
relationName: "applicationBuildServer",
|
||||||
}),
|
}),
|
||||||
compose: many(compose),
|
compose: many(compose),
|
||||||
|
libsql: many(libsql),
|
||||||
redis: many(redis),
|
redis: many(redis),
|
||||||
mariadb: many(mariadb),
|
mariadb: many(mariadb),
|
||||||
mongo: many(mongo),
|
mongo: many(mongo),
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { db } from "@dokploy/server/db";
|
|||||||
import {
|
import {
|
||||||
type apiCreateMount,
|
type apiCreateMount,
|
||||||
mounts,
|
mounts,
|
||||||
type ServiceType,
|
|
||||||
} from "@dokploy/server/db/schema";
|
} from "@dokploy/server/db/schema";
|
||||||
import {
|
import {
|
||||||
createFile,
|
createFile,
|
||||||
@@ -20,6 +19,16 @@ import { TRPCError } from "@trpc/server";
|
|||||||
import { eq, type SQL, sql } from "drizzle-orm";
|
import { eq, type SQL, sql } from "drizzle-orm";
|
||||||
import type { z } from "zod";
|
import type { z } from "zod";
|
||||||
|
|
||||||
|
export type ServiceType =
|
||||||
|
| "application"
|
||||||
|
| "compose"
|
||||||
|
| "libsql"
|
||||||
|
| "mariadb"
|
||||||
|
| "mongo"
|
||||||
|
| "mysql"
|
||||||
|
| "postgres"
|
||||||
|
| "redis";
|
||||||
|
|
||||||
export type Mount = typeof mounts.$inferSelect;
|
export type Mount = typeof mounts.$inferSelect;
|
||||||
|
|
||||||
export const createMount = async (input: z.infer<typeof apiCreateMount>) => {
|
export const createMount = async (input: z.infer<typeof apiCreateMount>) => {
|
||||||
@@ -352,35 +361,35 @@ export const getBaseFilesPath = async (mountId: string) => {
|
|||||||
let appName = "";
|
let appName = "";
|
||||||
let directoryPath = "";
|
let directoryPath = "";
|
||||||
|
|
||||||
if (mount.serviceType === "application" && mount.application) {
|
if (mount.applicationId && mount.application) {
|
||||||
const { APPLICATIONS_PATH } = paths(!!mount.application.serverId);
|
const { APPLICATIONS_PATH } = paths(!!mount.application.serverId);
|
||||||
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
||||||
appName = mount.application.appName;
|
appName = mount.application.appName;
|
||||||
} else if (mount.serviceType === "compose" && mount.compose) {
|
} else if (mount.composeId && mount.compose) {
|
||||||
const { COMPOSE_PATH } = paths(!!mount.compose.serverId);
|
const { COMPOSE_PATH } = paths(!!mount.compose.serverId);
|
||||||
appName = mount.compose.appName;
|
appName = mount.compose.appName;
|
||||||
absoluteBasePath = path.resolve(COMPOSE_PATH);
|
absoluteBasePath = path.resolve(COMPOSE_PATH);
|
||||||
} else if (mount.serviceType === "libsql" && mount.libsql) {
|
} else if (mount.libsqlId && mount.libsql) {
|
||||||
const { APPLICATIONS_PATH } = paths(!!mount.libsql.serverId);
|
const { APPLICATIONS_PATH } = paths(!!mount.libsql.serverId);
|
||||||
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
||||||
appName = mount.libsql.appName;
|
appName = mount.libsql.appName;
|
||||||
} else if (mount.serviceType === "mariadb" && mount.mariadb) {
|
} else if (mount.mariadbId && mount.mariadb) {
|
||||||
const { APPLICATIONS_PATH } = paths(!!mount.mariadb.serverId);
|
const { APPLICATIONS_PATH } = paths(!!mount.mariadb.serverId);
|
||||||
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
||||||
appName = mount.mariadb.appName;
|
appName = mount.mariadb.appName;
|
||||||
} else if (mount.serviceType === "mongo" && mount.mongo) {
|
} else if (mount.mongoId && mount.mongo) {
|
||||||
const { APPLICATIONS_PATH } = paths(!!mount.mongo.serverId);
|
const { APPLICATIONS_PATH } = paths(!!mount.mongo.serverId);
|
||||||
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
||||||
appName = mount.mongo.appName;
|
appName = mount.mongo.appName;
|
||||||
} else if (mount.serviceType === "mysql" && mount.mysql) {
|
} else if (mount.mysqlId && mount.mysql) {
|
||||||
const { APPLICATIONS_PATH } = paths(!!mount.mysql.serverId);
|
const { APPLICATIONS_PATH } = paths(!!mount.mysql.serverId);
|
||||||
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
||||||
appName = mount.mysql.appName;
|
appName = mount.mysql.appName;
|
||||||
} else if (mount.serviceType === "postgres" && mount.postgres) {
|
} else if (mount.postgresId && mount.postgres) {
|
||||||
const { APPLICATIONS_PATH } = paths(!!mount.postgres.serverId);
|
const { APPLICATIONS_PATH } = paths(!!mount.postgres.serverId);
|
||||||
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
||||||
appName = mount.postgres.appName;
|
appName = mount.postgres.appName;
|
||||||
} else if (mount.serviceType === "redis" && mount.redis) {
|
} else if (mount.redisId && mount.redis) {
|
||||||
const { APPLICATIONS_PATH } = paths(!!mount.redis.serverId);
|
const { APPLICATIONS_PATH } = paths(!!mount.redis.serverId);
|
||||||
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
absoluteBasePath = path.resolve(APPLICATIONS_PATH);
|
||||||
appName = mount.redis.appName;
|
appName = mount.redis.appName;
|
||||||
@@ -392,28 +401,28 @@ export const getBaseFilesPath = async (mountId: string) => {
|
|||||||
|
|
||||||
type MountNested = Awaited<ReturnType<typeof findMountById>>;
|
type MountNested = Awaited<ReturnType<typeof findMountById>>;
|
||||||
export const getServerId = async (mount: MountNested) => {
|
export const getServerId = async (mount: MountNested) => {
|
||||||
if (mount.serviceType === "application" && mount?.application?.serverId) {
|
if (mount.applicationId && mount?.application?.serverId) {
|
||||||
return mount.application.serverId;
|
return mount.application.serverId;
|
||||||
}
|
}
|
||||||
if (mount.serviceType === "compose" && mount?.compose?.serverId) {
|
if (mount.composeId && mount?.compose?.serverId) {
|
||||||
return mount.compose.serverId;
|
return mount.compose.serverId;
|
||||||
}
|
}
|
||||||
if (mount.serviceType === "libsql" && mount?.libsql?.serverId) {
|
if (mount.libsqlId && mount?.libsql?.serverId) {
|
||||||
return mount.libsql.serverId;
|
return mount.libsql.serverId;
|
||||||
}
|
}
|
||||||
if (mount.serviceType === "mariadb" && mount?.mariadb?.serverId) {
|
if (mount.mariadbId && mount?.mariadb?.serverId) {
|
||||||
return mount.mariadb.serverId;
|
return mount.mariadb.serverId;
|
||||||
}
|
}
|
||||||
if (mount.serviceType === "mongo" && mount?.mongo?.serverId) {
|
if (mount.mongoId && mount?.mongo?.serverId) {
|
||||||
return mount.mongo.serverId;
|
return mount.mongo.serverId;
|
||||||
}
|
}
|
||||||
if (mount.serviceType === "mysql" && mount?.mysql?.serverId) {
|
if (mount.mysqlId && mount?.mysql?.serverId) {
|
||||||
return mount.mysql.serverId;
|
return mount.mysql.serverId;
|
||||||
}
|
}
|
||||||
if (mount.serviceType === "postgres" && mount?.postgres?.serverId) {
|
if (mount.postgresId && mount?.postgres?.serverId) {
|
||||||
return mount.postgres.serverId;
|
return mount.postgres.serverId;
|
||||||
}
|
}
|
||||||
if (mount.serviceType === "redis" && mount?.redis?.serverId) {
|
if (mount.redisId && mount?.redis?.serverId) {
|
||||||
return mount.redis.serverId;
|
return mount.redis.serverId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user