MCPcopy
hub / github.com/Dokploy/dokploy / createPostgres

Function createPostgres

packages/server/src/services/postgres.ts:32–65  ·  view source on GitHub ↗
(
	input: z.infer<typeof apiCreatePostgres>,
)

Source from the content-addressed store, hash-verified

30export type Postgres = typeof postgres.$inferSelect;
31
32export const createPostgres = async (
33 input: z.infer<typeof apiCreatePostgres>,
34) => {
35 const appName = buildAppName("postgres", input.appName);
36
37 const valid = await validUniqueServerAppName(appName);
38 if (!valid) {
39 throw new TRPCError({
40 code: "CONFLICT",
41 message: "Service with this 'AppName' already exists",
42 });
43 }
44
45 const newPostgres = await db
46 .insert(postgres)
47 .values({
48 ...input,
49 databasePassword: input.databasePassword
50 ? input.databasePassword
51 : generatePassword(),
52 appName,
53 })
54 .returning()
55 .then((value) => value[0]);
56
57 if (!newPostgres) {
58 throw new TRPCError({
59 code: "BAD_REQUEST",
60 message: "Error input: Inserting postgresql database",
61 });
62 }
63
64 return newPostgres;
65};
66export const findPostgresById = async (postgresId: string) => {
67 const result = await db.query.postgres.findFirst({
68 where: eq(postgres.postgresId, postgresId),

Callers 2

duplicateServiceFunction · 0.90
postgres.tsFile · 0.90

Calls 3

buildAppNameFunction · 0.90
validUniqueServerAppNameFunction · 0.90
generatePasswordFunction · 0.90

Tested by

no test coverage detected