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

Function createRollback

packages/server/src/services/rollbacks.ts:31–102  ·  view source on GitHub ↗
(
	input: z.infer<typeof createRollbackSchema>,
)

Source from the content-addressed store, hash-verified

29} from "./registry";
30
31export const createRollback = async (
32 input: z.infer<typeof createRollbackSchema>,
33) => {
34 return await db.transaction(async (tx) => {
35 const { fullContext, ...other } = input;
36 const rollback = await tx
37 .insert(rollbacks)
38 .values(other)
39 .returning()
40 .then((res) => res[0]);
41
42 if (!rollback) {
43 throw new Error("Failed to create rollback");
44 }
45
46 const tagImage = `${input.appName}:v${rollback.version}`;
47 const deployment = await findDeploymentById(rollback.deploymentId);
48
49 if (!deployment?.applicationId) {
50 throw new Error("Deployment not found");
51 }
52
53 const {
54 deployments: _,
55 bitbucket,
56 github,
57 gitlab,
58 gitea,
59 ...rest
60 } = await findApplicationById(deployment.applicationId);
61
62 const registry = rest.registryId
63 ? await findRegistryByIdWithCredentials(rest.registryId)
64 : rest.registry;
65 const buildRegistry = rest.buildRegistryId
66 ? await findRegistryByIdWithCredentials(rest.buildRegistryId)
67 : rest.buildRegistry;
68 const rollbackRegistry = rest.rollbackRegistryId
69 ? await findRegistryByIdWithCredentials(rest.rollbackRegistryId)
70 : rest.rollbackRegistry;
71
72 const fullContextWithCredentials = {
73 ...rest,
74 registry,
75 buildRegistry,
76 rollbackRegistry,
77 };
78
79 await tx
80 .update(rollbacks)
81 .set({
82 image: tagImage,
83 // eslint-disable-next-line @typescript-eslint/no-explicit-any
84 fullContext: fullContextWithCredentials as any,
85 })
86 .where(eq(rollbacks.rollbackId, rollback.rollbackId));
87
88 // Update the deployment to reference this rollback

Callers 1

uploadImageRemoteCommandFunction · 0.90

Calls 3

findDeploymentByIdFunction · 0.90
findApplicationByIdFunction · 0.90

Tested by

no test coverage detected