aboutsummaryrefslogtreecommitdiffstats
path: root/packages/db/schema.ts
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-03-01 18:00:58 +0000
committerMohamedBassem <me@mbassem.com>2024-03-01 18:00:58 +0000
commit75d315dda4232ee3b89abf054f0b6ee10105ffe3 (patch)
treef0796a136578f3b5aa82b4b3313e54fa3061ff5f /packages/db/schema.ts
parent588471d65039e6920751ac2add8874ee932bc2f1 (diff)
downloadkarakeep-75d315dda4232ee3b89abf054f0b6ee10105ffe3.tar.zst
feature: Add support for creating and updating lists
Diffstat (limited to 'packages/db/schema.ts')
-rw-r--r--packages/db/schema.ts63
1 files changed, 63 insertions, 0 deletions
diff --git a/packages/db/schema.ts b/packages/db/schema.ts
index ea78a2b0..3c464d6c 100644
--- a/packages/db/schema.ts
+++ b/packages/db/schema.ts
@@ -172,6 +172,43 @@ export const tagsOnBookmarks = sqliteTable(
}),
);
+export const bookmarkLists = sqliteTable(
+ "bookmarkLists",
+ {
+ id: text("id")
+ .notNull()
+ .primaryKey()
+ .$defaultFn(() => createId()),
+ name: text("name").notNull(),
+ icon: text("icon").notNull(),
+ createdAt: createdAtField(),
+ userId: text("userId")
+ .notNull()
+ .references(() => users.id, { onDelete: "cascade" }),
+ },
+ (bl) => ({
+ unq: unique().on(bl.name, bl.userId),
+ }),
+);
+
+export const bookmarksInLists = sqliteTable(
+ "bookmarksInLists",
+ {
+ bookmarkId: text("bookmarkId")
+ .notNull()
+ .references(() => bookmarks.id, { onDelete: "cascade" }),
+ listId: text("listId")
+ .notNull()
+ .references(() => bookmarkLists.id, { onDelete: "cascade" }),
+ addedAt: integer("addedAt", { mode: "timestamp" }).$defaultFn(
+ () => new Date(),
+ ),
+ },
+ (tb) => ({
+ pk: primaryKey({ columns: [tb.bookmarkId, tb.listId] }),
+ }),
+);
+
// Relations
export const userRelations = relations(users, ({ many }) => ({
@@ -193,6 +230,7 @@ export const bookmarkRelations = relations(bookmarks, ({ many, one }) => ({
references: [bookmarkTexts.id],
}),
tagsOnBookmarks: many(tagsOnBookmarks),
+ bookmarksInLists: many(bookmarksInLists),
}));
export const bookmarkTagsRelations = relations(
@@ -226,3 +264,28 @@ export const apiKeyRelations = relations(apiKeys, ({ one }) => ({
references: [users.id],
}),
}));
+
+export const bookmarkListsRelations = relations(
+ bookmarkLists,
+ ({ one, many }) => ({
+ bookmarksInLists: many(bookmarksInLists),
+ user: one(users, {
+ fields: [bookmarkLists.userId],
+ references: [users.id],
+ }),
+ }),
+);
+
+export const bookmarksInListsRelations = relations(
+ bookmarksInLists,
+ ({ one }) => ({
+ bookmark: one(bookmarks, {
+ fields: [bookmarksInLists.bookmarkId],
+ references: [bookmarks.id],
+ }),
+ list: one(bookmarkLists, {
+ fields: [bookmarksInLists.listId],
+ references: [bookmarkLists.id],
+ }),
+ }),
+);