aboutsummaryrefslogtreecommitdiffstats
path: root/packages/db/schema.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/db/schema.ts')
-rw-r--r--packages/db/schema.ts54
1 files changed, 54 insertions, 0 deletions
diff --git a/packages/db/schema.ts b/packages/db/schema.ts
index 5f523d21..0479bb52 100644
--- a/packages/db/schema.ts
+++ b/packages/db/schema.ts
@@ -411,6 +411,14 @@ export const bookmarksInLists = sqliteTable(
addedAt: integer("addedAt", { mode: "timestamp" }).$defaultFn(
() => new Date(),
),
+ // Tie the list's existence to the user's membership
+ // of this list.
+ listMembershipId: text("listMembershipId").references(
+ () => listCollaborators.id,
+ {
+ onDelete: "cascade",
+ },
+ ),
},
(tb) => [
primaryKey({ columns: [tb.bookmarkId, tb.listId] }),
@@ -419,6 +427,32 @@ export const bookmarksInLists = sqliteTable(
],
);
+export const listCollaborators = sqliteTable(
+ "listCollaborators",
+ {
+ id: text("id")
+ .notNull()
+ .primaryKey()
+ .$defaultFn(() => createId()),
+ listId: text("listId")
+ .notNull()
+ .references(() => bookmarkLists.id, { onDelete: "cascade" }),
+ userId: text("userId")
+ .notNull()
+ .references(() => users.id, { onDelete: "cascade" }),
+ role: text("role", { enum: ["viewer", "editor"] }).notNull(),
+ addedAt: createdAtField(),
+ addedBy: text("addedBy").references(() => users.id, {
+ onDelete: "set null",
+ }),
+ },
+ (lc) => [
+ unique().on(lc.listId, lc.userId),
+ index("listCollaborators_listId_idx").on(lc.listId),
+ index("listCollaborators_userId_idx").on(lc.userId),
+ ],
+);
+
export const customPrompts = sqliteTable(
"customPrompts",
{
@@ -698,6 +732,7 @@ export const userRelations = relations(users, ({ many, one }) => ({
invites: many(invites),
subscription: one(subscriptions),
importSessions: many(importSessions),
+ listCollaborations: many(listCollaborators),
}));
export const bookmarkRelations = relations(bookmarks, ({ many, one }) => ({
@@ -767,6 +802,7 @@ export const bookmarkListsRelations = relations(
bookmarkLists,
({ one, many }) => ({
bookmarksInLists: many(bookmarksInLists),
+ collaborators: many(listCollaborators),
user: one(users, {
fields: [bookmarkLists.userId],
references: [users.id],
@@ -792,6 +828,24 @@ export const bookmarksInListsRelations = relations(
}),
);
+export const listCollaboratorsRelations = relations(
+ listCollaborators,
+ ({ one }) => ({
+ list: one(bookmarkLists, {
+ fields: [listCollaborators.listId],
+ references: [bookmarkLists.id],
+ }),
+ user: one(users, {
+ fields: [listCollaborators.userId],
+ references: [users.id],
+ }),
+ addedByUser: one(users, {
+ fields: [listCollaborators.addedBy],
+ references: [users.id],
+ }),
+ }),
+);
+
export const webhooksRelations = relations(webhooksTable, ({ one }) => ({
user: one(users, {
fields: [webhooksTable.userId],