mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-16 04:35:24 +02:00
feat(db): add user bookmark table and migrations
This commit is contained in:
9
apps/dokploy/drizzle/0119_rainy_rumiko_fujikawa.sql
Normal file
9
apps/dokploy/drizzle/0119_rainy_rumiko_fujikawa.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE IF NOT EXISTS "user_template_bookmarks" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"userId" text NOT NULL,
|
||||
"templateId" text NOT NULL,
|
||||
"createdAt" timestamp DEFAULT now() NOT NULL,
|
||||
CONSTRAINT "user_template_bookmarks_userId_templateId_unique" UNIQUE("userId","templateId")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "user_template_bookmarks" ADD CONSTRAINT "user_template_bookmarks_userId_user_temp_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user_temp"("id") ON DELETE cascade ON UPDATE no action;
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
unique,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { nanoid } from "nanoid";
|
||||
@@ -122,6 +123,24 @@ export const user = pgTable("user", {
|
||||
serversQuantity: integer("serversQuantity").notNull().default(0),
|
||||
});
|
||||
|
||||
export const userTemplateBookmarks = pgTable(
|
||||
"user_template_bookmarks",
|
||||
{
|
||||
id: text("id")
|
||||
.notNull()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => nanoid()),
|
||||
userId: text("userId")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
templateId: text("templateId").notNull(),
|
||||
createdAt: timestamp("createdAt").notNull().defaultNow(),
|
||||
},
|
||||
(table) => ({
|
||||
uniqueUserTemplate: unique().on(table.userId, table.templateId),
|
||||
}),
|
||||
);
|
||||
|
||||
export const usersRelations = relations(user, ({ one, many }) => ({
|
||||
account: one(account, {
|
||||
fields: [user.id],
|
||||
@@ -132,8 +151,19 @@ export const usersRelations = relations(user, ({ one, many }) => ({
|
||||
apiKeys: many(apikey),
|
||||
backups: many(backups),
|
||||
schedules: many(schedules),
|
||||
templateBookmarks: many(userTemplateBookmarks),
|
||||
}));
|
||||
|
||||
export const userTemplateBookmarksRelations = relations(
|
||||
userTemplateBookmarks,
|
||||
({ one }) => ({
|
||||
user: one(user, {
|
||||
fields: [userTemplateBookmarks.userId],
|
||||
references: [user.id],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
const createSchema = createInsertSchema(user, {
|
||||
id: z.string().min(1),
|
||||
isRegistered: z.boolean().optional(),
|
||||
|
||||
Reference in New Issue
Block a user