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.ts11
1 files changed, 10 insertions, 1 deletions
diff --git a/packages/db/schema.ts b/packages/db/schema.ts
index cc4d4b56..fbb8d24f 100644
--- a/packages/db/schema.ts
+++ b/packages/db/schema.ts
@@ -1,6 +1,6 @@
import type { AdapterAccount } from "@auth/core/adapters";
import { createId } from "@paralleldrive/cuid2";
-import { relations } from "drizzle-orm";
+import { relations, sql, SQL } from "drizzle-orm";
import {
AnySQLiteColumn,
foreignKey,
@@ -366,6 +366,14 @@ export const bookmarkTags = sqliteTable(
.primaryKey()
.$defaultFn(() => createId()),
name: text("name").notNull(),
+ normalizedName: text("normalizedName").generatedAlwaysAs(
+ (): SQL =>
+ // This function needs to be in sync with the tagNormalizer function in tagging.ts
+ sql`lower(replace(replace(replace(${bookmarkTags.name}, ' ', ''), '-', ''), '_', ''))`,
+ {
+ mode: "virtual",
+ },
+ ),
createdAt: createdAtField(),
userId: text("userId")
.notNull()
@@ -376,6 +384,7 @@ export const bookmarkTags = sqliteTable(
unique("bookmarkTags_userId_id_idx").on(bt.userId, bt.id),
index("bookmarkTags_name_idx").on(bt.name),
index("bookmarkTags_userId_idx").on(bt.userId),
+ index("bookmarkTags_normalizedName_idx").on(bt.normalizedName),
],
);