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

View File

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

View File

@@ -24,23 +24,24 @@ export const createRollback = async (
}
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);
if (!deployment?.applicationId) {
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;
});
@@ -123,7 +124,6 @@ export const rollback = async (rollbackId: string) => {
await rollbackApplication(
application.appName,
result.image || "",
result.env || "",
application.serverId,
);
};
@@ -131,7 +131,6 @@ export const rollback = async (rollbackId: string) => {
const rollbackApplication = async (
appName: string,
image: string,
env: string,
serverId?: string | null,
) => {
const docker = await getRemoteDocker(serverId);
@@ -141,7 +140,6 @@ const rollbackApplication = async (
TaskTemplate: {
ContainerSpec: {
Image: image,
// Env: env.split("\n"),
},
},
};