refactor(database): remove unique constraint and related files for preview_deployments

- Deleted the SQL file that added a unique constraint on the combination of applicationId and pullRequestId in the preview_deployments table.
- Removed the corresponding entry from the _journal.json to reflect the deletion of the migration.
- Deleted the snapshot file for version 142, which is no longer needed.
- Updated the preview-deployments schema to remove the unique index, reverting to the previous state.
This commit is contained in:
Mauricio Siu
2026-02-08 01:51:02 -06:00
parent 51095e3ac5
commit a212d42495
5 changed files with 49 additions and 7312 deletions
@@ -1 +0,0 @@
ALTER TABLE "preview_deployments" ADD CONSTRAINT "preview_deployments_applicationId_pullRequestId_unique" UNIQUE("applicationId","pullRequestId");
File diff suppressed because it is too large Load Diff
-7
View File
@@ -995,13 +995,6 @@
"when": 1770490719123, "when": 1770490719123,
"tag": "0141_plain_earthquake", "tag": "0141_plain_earthquake",
"breakpoints": true "breakpoints": true
},
{
"idx": 142,
"version": "7",
"when": 1770535594423,
"tag": "0142_loose_warpath",
"breakpoints": true
} }
] ]
} }
+22 -15
View File
@@ -355,6 +355,11 @@ export default async function handler(
action === "labeled" || action === "labeled" ||
action === "unlabeled" action === "unlabeled"
) { ) {
const shouldCreateDeployment =
action === "opened" ||
action === "synchronize" ||
action === "reopened";
const repository = githubBody?.repository?.name; const repository = githubBody?.repository?.name;
const deploymentHash = githubBody?.pull_request?.head?.sha; const deploymentHash = githubBody?.pull_request?.head?.sha;
const branch = githubBody?.pull_request?.base?.ref; const branch = githubBody?.pull_request?.base?.ref;
@@ -475,7 +480,7 @@ export default async function handler(
let previewDeploymentId = let previewDeploymentId =
previewDeploymentResult?.previewDeploymentId || ""; previewDeploymentResult?.previewDeploymentId || "";
if (!previewDeploymentResult) { if (!previewDeploymentResult && shouldCreateDeployment) {
const previewDeployment = await createPreviewDeployment({ const previewDeployment = await createPreviewDeployment({
applicationId: app.applicationId as string, applicationId: app.applicationId as string,
branch: prBranch, branch: prBranch,
@@ -497,21 +502,23 @@ export default async function handler(
previewDeploymentId, previewDeploymentId,
}; };
if (IS_CLOUD && app.serverId) { if (previewDeploymentId) {
jobData.serverId = app.serverId; if (IS_CLOUD && app.serverId) {
deploy(jobData).catch((error) => { jobData.serverId = app.serverId;
console.error("Background deployment failed:", error); deploy(jobData).catch((error) => {
}); console.error("Background deployment failed:", error);
continue; });
continue;
}
await myQueue.add(
"deployments",
{ ...jobData },
{
removeOnComplete: true,
removeOnFail: true,
},
);
} }
await myQueue.add(
"deployments",
{ ...jobData },
{
removeOnComplete: true,
removeOnFail: true,
},
);
} }
return res.status(200).json({ message: "Apps Deployed" }); return res.status(200).json({ message: "Apps Deployed" });
} }
@@ -1,5 +1,5 @@
import { relations } from "drizzle-orm"; import { relations } from "drizzle-orm";
import { pgTable, text, unique } from "drizzle-orm/pg-core"; import { pgTable, 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";
@@ -9,41 +9,35 @@ import { domains } from "./domain";
import { applicationStatus } from "./shared"; import { applicationStatus } from "./shared";
import { generateAppName } from "./utils"; import { generateAppName } from "./utils";
export const previewDeployments = pgTable( export const previewDeployments = pgTable("preview_deployments", {
"preview_deployments", previewDeploymentId: text("previewDeploymentId")
{ .notNull()
previewDeploymentId: text("previewDeploymentId") .primaryKey()
.notNull() .$defaultFn(() => nanoid()),
.primaryKey() branch: text("branch").notNull(),
.$defaultFn(() => nanoid()), pullRequestId: text("pullRequestId").notNull(),
branch: text("branch").notNull(), pullRequestNumber: text("pullRequestNumber").notNull(),
pullRequestId: text("pullRequestId").notNull(), pullRequestURL: text("pullRequestURL").notNull(),
pullRequestNumber: text("pullRequestNumber").notNull(), pullRequestTitle: text("pullRequestTitle").notNull(),
pullRequestURL: text("pullRequestURL").notNull(), pullRequestCommentId: text("pullRequestCommentId").notNull(),
pullRequestTitle: text("pullRequestTitle").notNull(), previewStatus: applicationStatus("previewStatus").notNull().default("idle"),
pullRequestCommentId: text("pullRequestCommentId").notNull(), appName: text("appName")
previewStatus: applicationStatus("previewStatus").notNull().default("idle"), .notNull()
appName: text("appName") .$defaultFn(() => generateAppName("preview"))
.notNull() .unique(),
.$defaultFn(() => generateAppName("preview")) applicationId: text("applicationId")
.unique(), .notNull()
applicationId: text("applicationId") .references(() => applications.applicationId, {
.notNull()
.references(() => applications.applicationId, {
onDelete: "cascade",
}),
domainId: text("domainId").references(() => domains.domainId, {
onDelete: "cascade", onDelete: "cascade",
}), }),
createdAt: text("createdAt") domainId: text("domainId").references(() => domains.domainId, {
.notNull() onDelete: "cascade",
.$defaultFn(() => new Date().toISOString()),
expiresAt: text("expiresAt"),
},
(t) => ({
unqApplicationPullRequest: unique().on(t.applicationId, t.pullRequestId),
}), }),
); createdAt: text("createdAt")
.notNull()
.$defaultFn(() => new Date().toISOString()),
expiresAt: text("expiresAt"),
});
export const previewDeploymentsRelations = relations( export const previewDeploymentsRelations = relations(
previewDeployments, previewDeployments,