feat: add fullContext column to rollback table and update related functionality

- Introduced a new "fullContext" JSONB column in the "rollback" table to store additional context for rollbacks.
- Removed the "env" column from the "rollback" table to streamline data management.
- Updated the rollbacks service to handle the new "fullContext" field during rollback creation.
- Adjusted the application service to eliminate environment variable handling in rollback operations.
This commit is contained in:
Mauricio Siu
2025-06-02 21:02:17 -06:00
parent 4966bbeb73
commit f8baf6fe41
6 changed files with 5836 additions and 25 deletions

View File

@@ -0,0 +1,2 @@
ALTER TABLE "rollback" ADD COLUMN "fullContext" jsonb;--> statement-breakpoint
ALTER TABLE "rollback" DROP COLUMN "env";

File diff suppressed because it is too large Load Diff

View File

@@ -659,6 +659,13 @@
"when": 1748835784658, "when": 1748835784658,
"tag": "0093_funny_leper_queen", "tag": "0093_funny_leper_queen",
"breakpoints": true "breakpoints": true
},
{
"idx": 94,
"version": "7",
"when": 1748918922255,
"tag": "0094_true_marvel_zombies",
"breakpoints": true
} }
] ]
} }

View File

@@ -1,5 +1,5 @@
import { relations } from "drizzle-orm"; import { relations } from "drizzle-orm";
import { pgTable, serial, text } from "drizzle-orm/pg-core"; import { jsonb, pgTable, serial, text } from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod"; import { createInsertSchema } from "drizzle-zod";
import { nanoid } from "nanoid"; import { nanoid } from "nanoid";
import { z } from "zod"; import { z } from "zod";
@@ -10,7 +10,6 @@ export const rollbacks = pgTable("rollback", {
.notNull() .notNull()
.primaryKey() .primaryKey()
.$defaultFn(() => nanoid()), .$defaultFn(() => nanoid()),
env: text("env"),
deploymentId: text("deploymentId") deploymentId: text("deploymentId")
.notNull() .notNull()
.references(() => deployments.deploymentId, { .references(() => deployments.deploymentId, {
@@ -21,6 +20,7 @@ export const rollbacks = pgTable("rollback", {
createdAt: text("createdAt") createdAt: text("createdAt")
.notNull() .notNull()
.$defaultFn(() => new Date().toISOString()), .$defaultFn(() => new Date().toISOString()),
fullContext: jsonb("fullContext"),
}); });
export type Rollback = typeof rollbacks.$inferSelect; export type Rollback = typeof rollbacks.$inferSelect;

View File

@@ -41,10 +41,7 @@ import {
import { createTraefikConfig } from "@dokploy/server/utils/traefik/application"; import { createTraefikConfig } from "@dokploy/server/utils/traefik/application";
import { TRPCError } from "@trpc/server"; import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { import { encodeBase64 } from "../utils/docker/utils";
encodeBase64,
prepareEnvironmentVariables,
} from "../utils/docker/utils";
import { getDokployUrl } from "./admin"; import { getDokployUrl } from "./admin";
import { import {
createDeployment, createDeployment,
@@ -219,14 +216,8 @@ export const deployApplication = async ({
await updateApplicationStatus(applicationId, "done"); await updateApplicationStatus(applicationId, "done");
if (application.rollbackActive) { if (application.rollbackActive) {
const resolveEnvs = prepareEnvironmentVariables(
application.env,
application.project.env,
);
await createRollback({ await createRollback({
appName: application.appName, appName: application.appName,
env: resolveEnvs.join("\n"),
deploymentId: deployment.deploymentId, deploymentId: deployment.deploymentId,
}); });
} }

View File

@@ -24,23 +24,24 @@ export const createRollback = async (
} }
const tagImage = `${input.appName}:v${rollback.version}`; const tagImage = `${input.appName}:v${rollback.version}`;
await tx
.update(rollbacks)
.set({
image: tagImage,
})
.where(eq(rollbacks.rollbackId, rollback.rollbackId));
const deployment = await findDeploymentById(rollback.deploymentId); const deployment = await findDeploymentById(rollback.deploymentId);
if (!deployment?.applicationId) { if (!deployment?.applicationId) {
throw new Error("Deployment not found"); throw new Error("Deployment not found");
} }
const application = await findApplicationById(deployment.applicationId); const { deployments, bitbucket, github, gitlab, gitea, ...rest } =
await findApplicationById(deployment.applicationId);
await createRollbackImage(application, tagImage); await tx
.update(rollbacks)
.set({
image: tagImage,
fullContext: JSON.stringify(rest),
})
.where(eq(rollbacks.rollbackId, rollback.rollbackId));
await createRollbackImage(rest, tagImage);
return rollback; return rollback;
}); });
@@ -123,7 +124,6 @@ export const rollback = async (rollbackId: string) => {
await rollbackApplication( await rollbackApplication(
application.appName, application.appName,
result.image || "", result.image || "",
result.env || "",
application.serverId, application.serverId,
); );
}; };
@@ -131,7 +131,6 @@ export const rollback = async (rollbackId: string) => {
const rollbackApplication = async ( const rollbackApplication = async (
appName: string, appName: string,
image: string, image: string,
env: string,
serverId?: string | null, serverId?: string | null,
) => { ) => {
const docker = await getRemoteDocker(serverId); const docker = await getRemoteDocker(serverId);
@@ -141,7 +140,6 @@ const rollbackApplication = async (
TaskTemplate: { TaskTemplate: {
ContainerSpec: { ContainerSpec: {
Image: image, Image: image,
// Env: env.split("\n"),
}, },
}, },
}; };