mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-07 20:45:17 +00:00
feat(db): add user bookmark table and migrations
This commit is contained in:
@@ -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,
|
pgTable,
|
||||||
text,
|
text,
|
||||||
timestamp,
|
timestamp,
|
||||||
|
unique,
|
||||||
} from "drizzle-orm/pg-core";
|
} from "drizzle-orm/pg-core";
|
||||||
import { createInsertSchema } from "drizzle-zod";
|
import { createInsertSchema } from "drizzle-zod";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
@@ -122,6 +123,24 @@ export const user = pgTable("user", {
|
|||||||
serversQuantity: integer("serversQuantity").notNull().default(0),
|
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 }) => ({
|
export const usersRelations = relations(user, ({ one, many }) => ({
|
||||||
account: one(account, {
|
account: one(account, {
|
||||||
fields: [user.id],
|
fields: [user.id],
|
||||||
@@ -132,8 +151,19 @@ export const usersRelations = relations(user, ({ one, many }) => ({
|
|||||||
apiKeys: many(apikey),
|
apiKeys: many(apikey),
|
||||||
backups: many(backups),
|
backups: many(backups),
|
||||||
schedules: many(schedules),
|
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, {
|
const createSchema = createInsertSchema(user, {
|
||||||
id: z.string().min(1),
|
id: z.string().min(1),
|
||||||
isRegistered: z.boolean().optional(),
|
isRegistered: z.boolean().optional(),
|
||||||
|
|||||||
Reference in New Issue
Block a user