mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat: add preview deployments #379
This commit is contained in:
74
packages/server/src/db/schema/preview-deployments.ts
Normal file
74
packages/server/src/db/schema/preview-deployments.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { pgTable, text } from "drizzle-orm/pg-core";
|
||||
import { nanoid } from "nanoid";
|
||||
import { applications } from "./application";
|
||||
import { domains } from "./domain";
|
||||
import { deployments } from "./deployment";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { z } from "zod";
|
||||
import { generateAppName } from "./utils";
|
||||
import { applicationStatus } from "./shared";
|
||||
|
||||
export const previewDeployments = pgTable("preview_deployments", {
|
||||
previewDeploymentId: text("previewDeploymentId")
|
||||
.notNull()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => nanoid()),
|
||||
branch: text("branch").notNull(),
|
||||
pullRequestId: text("pullRequestId").notNull(),
|
||||
pullRequestNumber: text("pullRequestNumber").notNull(),
|
||||
pullRequestURL: text("pullRequestURL").notNull(),
|
||||
pullRequestTitle: text("pullRequestTitle").notNull(),
|
||||
pullRequestCommentId: text("pullRequestCommentId").notNull(),
|
||||
previewStatus: applicationStatus("previewStatus").notNull().default("idle"),
|
||||
appName: text("appName")
|
||||
.notNull()
|
||||
.$defaultFn(() => generateAppName("preview"))
|
||||
.unique(),
|
||||
applicationId: text("applicationId")
|
||||
.notNull()
|
||||
.references(() => applications.applicationId, {
|
||||
onDelete: "cascade",
|
||||
}),
|
||||
domainId: text("domainId").references(() => domains.domainId, {
|
||||
onDelete: "cascade",
|
||||
}),
|
||||
createdAt: text("createdAt")
|
||||
.notNull()
|
||||
.$defaultFn(() => new Date().toISOString()),
|
||||
expiresAt: text("expiresAt"),
|
||||
});
|
||||
|
||||
export const previewDeploymentsRelations = relations(
|
||||
previewDeployments,
|
||||
({ one, many }) => ({
|
||||
deployments: many(deployments),
|
||||
domain: one(domains, {
|
||||
fields: [previewDeployments.domainId],
|
||||
references: [domains.domainId],
|
||||
}),
|
||||
application: one(applications, {
|
||||
fields: [previewDeployments.applicationId],
|
||||
references: [applications.applicationId],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export const createSchema = createInsertSchema(previewDeployments, {
|
||||
applicationId: z.string(),
|
||||
});
|
||||
|
||||
export const apiCreatePreviewDeployment = createSchema
|
||||
.pick({
|
||||
applicationId: true,
|
||||
domainId: true,
|
||||
branch: true,
|
||||
pullRequestId: true,
|
||||
pullRequestNumber: true,
|
||||
pullRequestURL: true,
|
||||
pullRequestTitle: true,
|
||||
})
|
||||
.extend({
|
||||
applicationId: z.string().min(1),
|
||||
// deploymentId: z.string().min(1),
|
||||
});
|
||||
Reference in New Issue
Block a user