mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Add scheduleId to deployment schema and establish foreign key relationship
- Introduced a new column `scheduleId` in the `deployment` table to link deployments with schedules. - Added a foreign key constraint on `scheduleId` referencing the `schedule` table, ensuring referential integrity. - Updated the `deployment` schema to include the new relationship with the `schedules` table. - Enhanced the `schedules` schema to establish a one-to-many relationship with deployments.
This commit is contained in:
2
apps/dokploy/drizzle/0089_fearless_morlun.sql
Normal file
2
apps/dokploy/drizzle/0089_fearless_morlun.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE "deployment" ADD COLUMN "scheduleId" text;--> statement-breakpoint
|
||||||
|
ALTER TABLE "deployment" ADD CONSTRAINT "deployment_scheduleId_schedule_scheduleId_fk" FOREIGN KEY ("scheduleId") REFERENCES "public"."schedule"("scheduleId") ON DELETE cascade ON UPDATE no action;
|
||||||
5489
apps/dokploy/drizzle/meta/0089_snapshot.json
Normal file
5489
apps/dokploy/drizzle/meta/0089_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -624,6 +624,13 @@
|
|||||||
"when": 1746177535905,
|
"when": 1746177535905,
|
||||||
"tag": "0088_worthless_surge",
|
"tag": "0088_worthless_surge",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 89,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1746178027816,
|
||||||
|
"tag": "0089_fearless_morlun",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ import { applications } from "./application";
|
|||||||
import { compose } from "./compose";
|
import { compose } from "./compose";
|
||||||
import { previewDeployments } from "./preview-deployments";
|
import { previewDeployments } from "./preview-deployments";
|
||||||
import { server } from "./server";
|
import { server } from "./server";
|
||||||
|
import { schedules } from "./schedule";
|
||||||
export const deploymentStatus = pgEnum("deploymentStatus", [
|
export const deploymentStatus = pgEnum("deploymentStatus", [
|
||||||
"running",
|
"running",
|
||||||
"done",
|
"done",
|
||||||
@@ -48,6 +48,10 @@ export const deployments = pgTable("deployment", {
|
|||||||
.notNull()
|
.notNull()
|
||||||
.$defaultFn(() => new Date().toISOString()),
|
.$defaultFn(() => new Date().toISOString()),
|
||||||
errorMessage: text("errorMessage"),
|
errorMessage: text("errorMessage"),
|
||||||
|
scheduleId: text("scheduleId").references(
|
||||||
|
(): AnyPgColumn => schedules.scheduleId,
|
||||||
|
{ onDelete: "cascade" },
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const deploymentsRelations = relations(deployments, ({ one }) => ({
|
export const deploymentsRelations = relations(deployments, ({ one }) => ({
|
||||||
@@ -67,6 +71,10 @@ export const deploymentsRelations = relations(deployments, ({ one }) => ({
|
|||||||
fields: [deployments.previewDeploymentId],
|
fields: [deployments.previewDeploymentId],
|
||||||
references: [previewDeployments.previewDeploymentId],
|
references: [previewDeployments.previewDeploymentId],
|
||||||
}),
|
}),
|
||||||
|
schedule: one(schedules, {
|
||||||
|
fields: [deployments.scheduleId],
|
||||||
|
references: [schedules.scheduleId],
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const schema = createInsertSchema(deployments, {
|
const schema = createInsertSchema(deployments, {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { createInsertSchema } from "drizzle-zod";
|
|||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { applications } from "./application";
|
import { applications } from "./application";
|
||||||
|
import { deployments } from "./deployment";
|
||||||
export const schedules = pgTable("schedule", {
|
export const schedules = pgTable("schedule", {
|
||||||
scheduleId: text("scheduleId")
|
scheduleId: text("scheduleId")
|
||||||
.notNull()
|
.notNull()
|
||||||
@@ -23,11 +23,12 @@ export const schedules = pgTable("schedule", {
|
|||||||
.$defaultFn(() => new Date().toISOString()),
|
.$defaultFn(() => new Date().toISOString()),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const schedulesRelations = relations(schedules, ({ one }) => ({
|
export const schedulesRelations = relations(schedules, ({ one, many }) => ({
|
||||||
application: one(applications, {
|
application: one(applications, {
|
||||||
fields: [schedules.applicationId],
|
fields: [schedules.applicationId],
|
||||||
references: [applications.applicationId],
|
references: [applications.applicationId],
|
||||||
}),
|
}),
|
||||||
|
deployments: many(deployments),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const createScheduleSchema = createInsertSchema(schedules, {
|
export const createScheduleSchema = createInsertSchema(schedules, {
|
||||||
|
|||||||
Reference in New Issue
Block a user