mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-12 01:15:23 +02:00
refactor: update database imports to use centralized db module for improved consistency across API routes and schemas
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
import { dbUrl } from "./constants";
|
||||
import * as schema from "./schema";
|
||||
|
||||
export { and, eq };
|
||||
export * from "./schema";
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -126,62 +126,88 @@ const schema = createInsertSchema(deployments, {
|
||||
previewDeploymentId: z.string(),
|
||||
buildServerId: z.string(),
|
||||
});
|
||||
export const apiCreateDeployment = z.object({
|
||||
title: z.string().min(1),
|
||||
status: z.string().default("running"),
|
||||
logPath: z.string().min(1),
|
||||
applicationId: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
previewDeploymentId: z.string().optional(),
|
||||
});
|
||||
export const apiCreateDeployment = schema
|
||||
.pick({
|
||||
title: true,
|
||||
status: true,
|
||||
logPath: true,
|
||||
applicationId: true,
|
||||
description: true,
|
||||
previewDeploymentId: true,
|
||||
})
|
||||
.extend({
|
||||
applicationId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiCreateDeploymentPreview = z.object({
|
||||
title: z.string().min(1),
|
||||
status: z.string().default("running"),
|
||||
logPath: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
previewDeploymentId: z.string().min(1),
|
||||
});
|
||||
export const apiCreateDeploymentPreview = schema
|
||||
.pick({
|
||||
title: true,
|
||||
status: true,
|
||||
logPath: true,
|
||||
description: true,
|
||||
previewDeploymentId: true,
|
||||
})
|
||||
.extend({
|
||||
previewDeploymentId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiCreateDeploymentCompose = z.object({
|
||||
title: z.string().min(1),
|
||||
status: z.string().default("running"),
|
||||
logPath: z.string().min(1),
|
||||
composeId: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
});
|
||||
export const apiCreateDeploymentCompose = schema
|
||||
.pick({
|
||||
title: true,
|
||||
status: true,
|
||||
logPath: true,
|
||||
composeId: true,
|
||||
description: true,
|
||||
})
|
||||
.extend({
|
||||
composeId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiCreateDeploymentBackup = z.object({
|
||||
title: z.string().min(1),
|
||||
status: z.string().default("running"),
|
||||
logPath: z.string().min(1),
|
||||
backupId: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
});
|
||||
export const apiCreateDeploymentBackup = schema
|
||||
.pick({
|
||||
title: true,
|
||||
status: true,
|
||||
logPath: true,
|
||||
backupId: true,
|
||||
description: true,
|
||||
})
|
||||
.extend({
|
||||
backupId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiCreateDeploymentServer = z.object({
|
||||
title: z.string().min(1),
|
||||
status: z.string().default("running"),
|
||||
logPath: z.string().min(1),
|
||||
serverId: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
});
|
||||
export const apiCreateDeploymentServer = schema
|
||||
.pick({
|
||||
title: true,
|
||||
status: true,
|
||||
logPath: true,
|
||||
serverId: true,
|
||||
description: true,
|
||||
})
|
||||
.extend({
|
||||
serverId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiCreateDeploymentSchedule = z.object({
|
||||
title: z.string().min(1),
|
||||
status: z.string().default("running"),
|
||||
logPath: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
scheduleId: z.string().min(1),
|
||||
});
|
||||
export const apiCreateDeploymentSchedule = schema
|
||||
.pick({
|
||||
title: true,
|
||||
status: true,
|
||||
logPath: true,
|
||||
description: true,
|
||||
})
|
||||
.extend({
|
||||
scheduleId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiCreateDeploymentVolumeBackup = z.object({
|
||||
title: z.string().min(1),
|
||||
status: z.string().default("running"),
|
||||
logPath: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
volumeBackupId: z.string().min(1),
|
||||
});
|
||||
export const apiCreateDeploymentVolumeBackup = schema
|
||||
.pick({
|
||||
title: true,
|
||||
status: true,
|
||||
logPath: true,
|
||||
description: true,
|
||||
})
|
||||
.extend({
|
||||
volumeBackupId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiFindAllByApplication = z.object({
|
||||
applicationId: z.string().min(1),
|
||||
|
||||
@@ -46,33 +46,43 @@ const createSchema = createInsertSchema(destinations, {
|
||||
region: z.string(),
|
||||
});
|
||||
|
||||
export const apiCreateDestination = z.object({
|
||||
name: z.string().min(1),
|
||||
provider: z.string(),
|
||||
accessKey: z.string(),
|
||||
bucket: z.string(),
|
||||
region: z.string(),
|
||||
endpoint: z.string(),
|
||||
secretAccessKey: z.string(),
|
||||
serverId: z.string().optional(),
|
||||
});
|
||||
export const apiCreateDestination = createSchema
|
||||
.pick({
|
||||
name: true,
|
||||
provider: true,
|
||||
accessKey: true,
|
||||
bucket: true,
|
||||
region: true,
|
||||
endpoint: true,
|
||||
secretAccessKey: true,
|
||||
})
|
||||
.required()
|
||||
.extend({
|
||||
serverId: z.string().optional(),
|
||||
});
|
||||
|
||||
export const apiFindOneDestination = z.object({
|
||||
destinationId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiRemoveDestination = z.object({
|
||||
destinationId: z.string().min(1),
|
||||
});
|
||||
export const apiRemoveDestination = createSchema
|
||||
.pick({
|
||||
destinationId: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
export const apiUpdateDestination = z.object({
|
||||
destinationId: z.string().min(1),
|
||||
name: z.string().min(1).optional(),
|
||||
accessKey: z.string().optional(),
|
||||
bucket: z.string().optional(),
|
||||
region: z.string().optional(),
|
||||
endpoint: z.string().optional(),
|
||||
provider: z.string().optional(),
|
||||
secretAccessKey: z.string().optional(),
|
||||
serverId: z.string().optional(),
|
||||
});
|
||||
export const apiUpdateDestination = createSchema
|
||||
.pick({
|
||||
name: true,
|
||||
accessKey: true,
|
||||
bucket: true,
|
||||
region: true,
|
||||
endpoint: true,
|
||||
secretAccessKey: true,
|
||||
destinationId: true,
|
||||
provider: true,
|
||||
})
|
||||
.required()
|
||||
.extend({
|
||||
serverId: z.string().optional(),
|
||||
});
|
||||
|
||||
@@ -62,13 +62,13 @@ const createSchema = createInsertSchema(patch, {
|
||||
composeId: z.string().optional(),
|
||||
});
|
||||
|
||||
export const apiCreatePatch = z.object({
|
||||
filePath: z.string().min(1),
|
||||
content: z.string(),
|
||||
type: z.enum(["create", "update", "delete"]).optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
applicationId: z.string().optional(),
|
||||
composeId: z.string().optional(),
|
||||
export const apiCreatePatch = createSchema.pick({
|
||||
filePath: true,
|
||||
content: true,
|
||||
type: true,
|
||||
enabled: true,
|
||||
applicationId: true,
|
||||
composeId: true,
|
||||
});
|
||||
|
||||
export const apiFindPatch = z.object({
|
||||
@@ -83,13 +83,12 @@ export const apiFindPatchesByComposeId = z.object({
|
||||
composeId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiUpdatePatch = z.object({
|
||||
patchId: z.string().min(1),
|
||||
filePath: z.string().min(1).optional(),
|
||||
content: z.string().optional(),
|
||||
type: z.enum(["create", "update", "delete"]).optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
});
|
||||
export const apiUpdatePatch = createSchema
|
||||
.partial()
|
||||
.extend({
|
||||
patchId: z.string().min(1),
|
||||
})
|
||||
.omit({ applicationId: true, composeId: true });
|
||||
|
||||
export const apiDeletePatch = z.object({
|
||||
patchId: z.string().min(1),
|
||||
|
||||
@@ -39,22 +39,26 @@ const createSchema = createInsertSchema(ports, {
|
||||
protocol: z.enum(["tcp", "udp"]).default("tcp"),
|
||||
});
|
||||
|
||||
export const apiCreatePort = z.object({
|
||||
publishedPort: z.number(),
|
||||
publishMode: z.enum(["ingress", "host"]).default("ingress"),
|
||||
targetPort: z.number(),
|
||||
protocol: z.enum(["tcp", "udp"]).default("tcp"),
|
||||
applicationId: z.string().min(1),
|
||||
});
|
||||
export const apiCreatePort = createSchema
|
||||
.pick({
|
||||
publishedPort: true,
|
||||
publishMode: true,
|
||||
targetPort: true,
|
||||
protocol: true,
|
||||
applicationId: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
export const apiFindOnePort = z.object({
|
||||
portId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiUpdatePort = z.object({
|
||||
portId: z.string().min(1),
|
||||
publishedPort: z.number(),
|
||||
publishMode: z.enum(["ingress", "host"]),
|
||||
targetPort: z.number(),
|
||||
protocol: z.enum(["tcp", "udp"]),
|
||||
});
|
||||
export const apiUpdatePort = createSchema
|
||||
.pick({
|
||||
portId: true,
|
||||
publishedPort: true,
|
||||
publishMode: true,
|
||||
targetPort: true,
|
||||
protocol: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
@@ -42,14 +42,18 @@ export const apiFindOneSecurity = z.object({
|
||||
securityId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiCreateSecurity = z.object({
|
||||
applicationId: z.string().min(1),
|
||||
username: z.string().min(1),
|
||||
password: z.string().min(1),
|
||||
});
|
||||
export const apiCreateSecurity = createSchema
|
||||
.pick({
|
||||
applicationId: true,
|
||||
username: true,
|
||||
password: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
export const apiUpdateSecurity = z.object({
|
||||
securityId: z.string().min(1),
|
||||
username: z.string().min(1),
|
||||
password: z.string().min(1),
|
||||
});
|
||||
export const apiUpdateSecurity = createSchema
|
||||
.pick({
|
||||
securityId: true,
|
||||
username: true,
|
||||
password: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { pgTable, text } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { nanoid } from "nanoid";
|
||||
import { z } from "zod";
|
||||
import { sshKeyCreate, sshKeyType } from "../validations";
|
||||
@@ -36,13 +37,21 @@ export const sshKeysRelations = relations(sshKeys, ({ many, one }) => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
export const apiCreateSshKey = z.object({
|
||||
name: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
organizationId: z.string().min(1),
|
||||
publicKey: sshKeyCreate.shape.publicKey,
|
||||
privateKey: sshKeyCreate.shape.privateKey,
|
||||
});
|
||||
const createSchema = createInsertSchema(
|
||||
sshKeys,
|
||||
/* Private key is not stored in the DB */
|
||||
sshKeyCreate.omit({ privateKey: true }).shape,
|
||||
);
|
||||
|
||||
export const apiCreateSshKey = createSchema
|
||||
.pick({
|
||||
name: true,
|
||||
description: true,
|
||||
privateKey: true,
|
||||
publicKey: true,
|
||||
organizationId: true,
|
||||
})
|
||||
.merge(sshKeyCreate.pick({ privateKey: true }));
|
||||
|
||||
export const apiFindOneSshKey = z.object({
|
||||
sshKeyId: z.string().min(1),
|
||||
@@ -50,13 +59,23 @@ export const apiFindOneSshKey = z.object({
|
||||
|
||||
export const apiGenerateSSHKey = sshKeyType;
|
||||
|
||||
export const apiRemoveSshKey = z.object({
|
||||
sshKeyId: z.string().min(1),
|
||||
});
|
||||
export const apiRemoveSshKey = createSchema
|
||||
.pick({
|
||||
sshKeyId: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
export const apiUpdateSshKey = z.object({
|
||||
sshKeyId: z.string().min(1),
|
||||
name: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
lastUsedAt: z.string().optional(),
|
||||
});
|
||||
export const apiUpdateSshKey = createSchema
|
||||
.pick({
|
||||
name: true,
|
||||
description: true,
|
||||
lastUsedAt: true,
|
||||
})
|
||||
.partial()
|
||||
.merge(
|
||||
createSchema
|
||||
.pick({
|
||||
sshKeyId: true,
|
||||
})
|
||||
.required(),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { boolean, integer, pgTable, text } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { nanoid } from "nanoid";
|
||||
import { z } from "zod";
|
||||
import { applications } from "./application";
|
||||
@@ -104,45 +105,12 @@ export const volumeBackupsRelations = relations(
|
||||
}),
|
||||
);
|
||||
|
||||
const serviceTypeEnum = z.enum([
|
||||
"application",
|
||||
"postgres",
|
||||
"mysql",
|
||||
"mariadb",
|
||||
"mongo",
|
||||
"redis",
|
||||
"compose",
|
||||
]);
|
||||
|
||||
export const createVolumeBackupSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
volumeName: z.string().min(1),
|
||||
prefix: z.string().min(1),
|
||||
serviceType: serviceTypeEnum.default("application"),
|
||||
appName: z.string().min(1).optional(),
|
||||
serviceName: z.string().optional(),
|
||||
turnOff: z.boolean().default(false),
|
||||
cronExpression: z.string().min(1),
|
||||
keepLatestCount: z.number().optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
applicationId: z.string().optional(),
|
||||
postgresId: z.string().optional(),
|
||||
mariadbId: z.string().optional(),
|
||||
mongoId: z.string().optional(),
|
||||
mysqlId: z.string().optional(),
|
||||
redisId: z.string().optional(),
|
||||
composeId: z.string().optional(),
|
||||
destinationId: z.string().min(1),
|
||||
export const createVolumeBackupSchema = createInsertSchema(volumeBackups).omit({
|
||||
volumeBackupId: true,
|
||||
});
|
||||
|
||||
export const updateVolumeBackupSchema = z.object({
|
||||
export const updateVolumeBackupSchema = createVolumeBackupSchema.extend({
|
||||
volumeBackupId: z.string().min(1),
|
||||
name: z.string().min(1).optional(),
|
||||
destinationId: z.string().optional(),
|
||||
cronExpression: z.string().optional(),
|
||||
keepLatestCount: z.number().optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
turnOff: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const apiFindOneVolumeBackup = z.object({
|
||||
|
||||
Reference in New Issue
Block a user