mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
81 lines
1.8 KiB
TypeScript
81 lines
1.8 KiB
TypeScript
import { relations } from "drizzle-orm";
|
|
import { createInsertSchema } from "drizzle-zod";
|
|
import { z } from "zod";
|
|
import { nanoid } from "nanoid";
|
|
import { pgTable, text } from "drizzle-orm/pg-core";
|
|
import { admins } from "./admin";
|
|
import { backups } from "./backups";
|
|
|
|
export const destinations = pgTable("destination", {
|
|
destinationId: text("destinationId")
|
|
.notNull()
|
|
.primaryKey()
|
|
.$defaultFn(() => nanoid()),
|
|
name: text("name").notNull(),
|
|
accessKey: text("accessKey").notNull(),
|
|
secretAccessKey: text("secretAccessKey").notNull(),
|
|
bucket: text("bucket").notNull(),
|
|
region: text("region").notNull(),
|
|
// maybe it can be null
|
|
endpoint: text("endpoint").notNull(),
|
|
adminId: text("adminId")
|
|
.notNull()
|
|
.references(() => admins.adminId, { onDelete: "cascade" }),
|
|
});
|
|
|
|
export const destinationsRelations = relations(
|
|
destinations,
|
|
({ many, one }) => ({
|
|
backups: many(backups),
|
|
admin: one(admins, {
|
|
fields: [destinations.adminId],
|
|
references: [admins.adminId],
|
|
}),
|
|
}),
|
|
);
|
|
|
|
const createSchema = createInsertSchema(destinations, {
|
|
destinationId: z.string(),
|
|
name: z.string().min(1),
|
|
accessKey: z.string(),
|
|
bucket: z.string(),
|
|
endpoint: z.string(),
|
|
secretAccessKey: z.string(),
|
|
region: z.string(),
|
|
});
|
|
|
|
export const apiCreateDestination = createSchema
|
|
.pick({
|
|
name: true,
|
|
accessKey: true,
|
|
bucket: true,
|
|
region: true,
|
|
endpoint: true,
|
|
secretAccessKey: true,
|
|
})
|
|
.required();
|
|
|
|
export const apiFindOneDestination = createSchema
|
|
.pick({
|
|
destinationId: true,
|
|
})
|
|
.required();
|
|
|
|
export const apiRemoveDestination = createSchema
|
|
.pick({
|
|
destinationId: true,
|
|
})
|
|
.required();
|
|
|
|
export const apiUpdateDestination = createSchema
|
|
.pick({
|
|
name: true,
|
|
accessKey: true,
|
|
bucket: true,
|
|
region: true,
|
|
endpoint: true,
|
|
secretAccessKey: true,
|
|
destinationId: true,
|
|
})
|
|
.required();
|