From e0999f701cd1834c3d940113cd8dd5247c5fe95f Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Fri, 19 Apr 2024 00:09:27 +0100 Subject: feature: Nested lists (#110). Fixes #62 * feature: Add support for nested lists * prevent moving the parent to a subtree --- packages/db/schema.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'packages/db/schema.ts') diff --git a/packages/db/schema.ts b/packages/db/schema.ts index 6a7128c0..037be814 100644 --- a/packages/db/schema.ts +++ b/packages/db/schema.ts @@ -2,6 +2,7 @@ import type { AdapterAccount } from "@auth/core/adapters"; import { createId } from "@paralleldrive/cuid2"; import { relations } from "drizzle-orm"; import { + AnySQLiteColumn, index, integer, primaryKey, @@ -223,9 +224,10 @@ export const bookmarkLists = sqliteTable( userId: text("userId") .notNull() .references(() => users.id, { onDelete: "cascade" }), + parentId: text("parentId") + .references((): AnySQLiteColumn => bookmarkLists.id, { onDelete: "set null" }), }, (bl) => ({ - unq: unique().on(bl.name, bl.userId), userIdIdx: index("bookmarkLists_userId_idx").on(bl.userId), }), ); @@ -318,6 +320,10 @@ export const bookmarkListsRelations = relations( fields: [bookmarkLists.userId], references: [users.id], }), + parent: one(bookmarkLists, { + fields: [bookmarkLists.parentId], + references: [bookmarkLists.id], + }), }), ); -- cgit v1.2.3-70-g09d2