diff options
| author | Mohamed Bassem <me@mbassem.com> | 2024-03-19 00:33:11 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-19 00:33:11 +0000 |
| commit | 785a5b574992296e187a66412dd42f7b4a686353 (patch) | |
| tree | 64b608927cc63d7494395f639636fd4b36e5a977 /packages/db/schema.ts | |
| parent | 549520919c482e72cdf7adae5ba852d1b6cbe5aa (diff) | |
| download | karakeep-785a5b574992296e187a66412dd42f7b4a686353.tar.zst | |
Feature: Add support for uploading images and automatically inferring their tags (#2)
* feature: Experimental support for asset uploads
* feature(web): Add new bookmark type asset
* feature: Add support for automatically tagging images
* fix: Add support for image assets in preview page
* use next Image for fetching the images
* Fix auth and error codes in the route handlers
* Add support for image uploads on mobile
* Fix typing of upload requests
* Remove the ugly dragging box
* Bump mobile version to 1.3
* Change the editor card placeholder to mention uploading images
* Fix a typo
* Change ios icon for photo library
* Silence typescript error
Diffstat (limited to 'packages/db/schema.ts')
| -rw-r--r-- | packages/db/schema.ts | 95 |
1 files changed, 68 insertions, 27 deletions
diff --git a/packages/db/schema.ts b/packages/db/schema.ts index 6063fccc..769632d9 100644 --- a/packages/db/schema.ts +++ b/packages/db/schema.ts @@ -1,14 +1,15 @@ +import type { AdapterAccount } from "@auth/core/adapters"; +import { createId } from "@paralleldrive/cuid2"; +import { relations } from "drizzle-orm"; import { + blob, + index, integer, + primaryKey, sqliteTable, text, - primaryKey, unique, - index, } from "drizzle-orm/sqlite-core"; -import type { AdapterAccount } from "@auth/core/adapters"; -import { createId } from "@paralleldrive/cuid2"; -import { relations } from "drizzle-orm"; function createdAtField() { return integer("createdAt", { mode: "timestamp" }) @@ -96,28 +97,32 @@ export const apiKeys = sqliteTable( }), ); -export const bookmarks = sqliteTable("bookmarks", { - id: text("id") - .notNull() - .primaryKey() - .$defaultFn(() => createId()), - createdAt: createdAtField(), - archived: integer("archived", { mode: "boolean" }).notNull().default(false), - favourited: integer("favourited", { mode: "boolean" }) - .notNull() - .default(false), - userId: text("userId") - .notNull() - .references(() => users.id, { onDelete: "cascade" }), - taggingStatus: text("taggingStatus", { - enum: ["pending", "failure", "success"], - }).default("pending"), -}, (b) => ({ - userIdIdx: index("bookmarks_userId_idx").on(b.userId), - archivedIdx: index("bookmarks_archived_idx").on(b.archived), - favIdx: index("bookmarks_favourited_idx").on(b.favourited), - createdAtIdx: index("bookmarks_createdAt_idx").on(b.createdAt), -})); +export const bookmarks = sqliteTable( + "bookmarks", + { + id: text("id") + .notNull() + .primaryKey() + .$defaultFn(() => createId()), + createdAt: createdAtField(), + archived: integer("archived", { mode: "boolean" }).notNull().default(false), + favourited: integer("favourited", { mode: "boolean" }) + .notNull() + .default(false), + userId: text("userId") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + taggingStatus: text("taggingStatus", { + enum: ["pending", "failure", "success"], + }).default("pending"), + }, + (b) => ({ + userIdIdx: index("bookmarks_userId_idx").on(b.userId), + archivedIdx: index("bookmarks_archived_idx").on(b.archived), + favIdx: index("bookmarks_favourited_idx").on(b.favourited), + createdAtIdx: index("bookmarks_createdAt_idx").on(b.createdAt), + }), +); export const bookmarkLinks = sqliteTable("bookmarkLinks", { id: text("id") @@ -146,6 +151,18 @@ export const bookmarkTexts = sqliteTable("bookmarkTexts", { text: text("text"), }); +export const bookmarkAssets = sqliteTable("bookmarkAssets", { + id: text("id") + .notNull() + .primaryKey() + .$defaultFn(() => createId()) + .references(() => bookmarks.id, { onDelete: "cascade" }), + assetType: text("assetType", { enum: ["image"] }).notNull(), + assetId: text("assetId") + .notNull() + .references(() => assets.id, { onDelete: "cascade" }), +}); + export const bookmarkTags = sqliteTable( "bookmarkTags", { @@ -208,6 +225,26 @@ export const bookmarkLists = sqliteTable( }), ); +export const assets = sqliteTable( + "assets", + { + id: text("id") + .notNull() + .primaryKey() + .$defaultFn(() => createId()), + userId: text("userId") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + createdAt: createdAtField(), + contentType: text("contentType").notNull(), + encoding: text("encoding", { enum: ["binary"] }).notNull(), + blob: blob("blob").notNull(), + }, + (a) => ({ + userIdIdx: index("assets_userId_idx").on(a.userId), + }), +); + export const bookmarksInLists = sqliteTable( "bookmarksInLists", { @@ -248,6 +285,10 @@ export const bookmarkRelations = relations(bookmarks, ({ many, one }) => ({ fields: [bookmarks.id], references: [bookmarkTexts.id], }), + asset: one(bookmarkAssets, { + fields: [bookmarks.id], + references: [bookmarkAssets.id], + }), tagsOnBookmarks: many(tagsOnBookmarks), bookmarksInLists: many(bookmarksInLists), })); |
