mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
- 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.
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { relations } from "drizzle-orm";
|
|
import { pgTable, text } from "drizzle-orm/pg-core";
|
|
import { createInsertSchema } from "drizzle-zod";
|
|
import { nanoid } from "nanoid";
|
|
import { z } from "zod";
|
|
import { applications } from "./application";
|
|
import { deployments } from "./deployment";
|
|
export const schedules = pgTable("schedule", {
|
|
scheduleId: text("scheduleId")
|
|
.notNull()
|
|
.primaryKey()
|
|
.$defaultFn(() => nanoid()),
|
|
name: text("name").notNull(),
|
|
cronExpression: text("cronExpression").notNull(),
|
|
command: text("command").notNull(),
|
|
applicationId: text("applicationId")
|
|
.notNull()
|
|
.references(() => applications.applicationId, {
|
|
onDelete: "cascade",
|
|
}),
|
|
createdAt: text("createdAt")
|
|
.notNull()
|
|
.$defaultFn(() => new Date().toISOString()),
|
|
});
|
|
|
|
export const schedulesRelations = relations(schedules, ({ one, many }) => ({
|
|
application: one(applications, {
|
|
fields: [schedules.applicationId],
|
|
references: [applications.applicationId],
|
|
}),
|
|
deployments: many(deployments),
|
|
}));
|
|
|
|
export const createScheduleSchema = createInsertSchema(schedules, {
|
|
name: z.string().min(1),
|
|
cronExpression: z.string().min(1),
|
|
command: z.string().min(1),
|
|
applicationId: z.string().min(1),
|
|
});
|