feat: 添加书签模块 schema 和关联
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { boolean, integer, pgTable, text, uuid } from 'drizzle-orm/pg-core'
|
||||
import { userTable } from '../../server/auth/schema'
|
||||
import { generatedFields } from '../../server/db/fields'
|
||||
|
||||
export const categoryTable = pgTable('category', {
|
||||
...generatedFields,
|
||||
name: text('name').notNull(),
|
||||
isPinned: boolean('is_pinned').notNull().default(false),
|
||||
isPublic: boolean('is_public').notNull().default(true),
|
||||
orderId: integer('order_id').notNull().default(0),
|
||||
userId: text('user_id')
|
||||
.notNull()
|
||||
.references(() => userTable.id, { onDelete: 'cascade' }),
|
||||
})
|
||||
|
||||
export const bookmarkTable = pgTable('bookmark', {
|
||||
...generatedFields,
|
||||
name: text('name').notNull(),
|
||||
url: text('url').notNull(),
|
||||
icon: text('icon'),
|
||||
categoryId: uuid('category_id')
|
||||
.notNull()
|
||||
.references(() => categoryTable.id, { onDelete: 'cascade' }),
|
||||
isPublic: boolean('is_public').notNull().default(true),
|
||||
orderId: integer('order_id').notNull().default(0),
|
||||
userId: text('user_id')
|
||||
.notNull()
|
||||
.references(() => userTable.id, { onDelete: 'cascade' }),
|
||||
})
|
||||
@@ -1,4 +1,26 @@
|
||||
import { defineRelations } from 'drizzle-orm'
|
||||
import * as schema from './schema'
|
||||
|
||||
export const relations = defineRelations(schema, (_r) => ({}))
|
||||
export const relations = defineRelations(schema, (r) => ({
|
||||
userTable: {
|
||||
categories: r.many.categoryTable(),
|
||||
bookmarks: r.many.bookmarkTable(),
|
||||
},
|
||||
categoryTable: {
|
||||
user: r.one.userTable({
|
||||
from: r.categoryTable.userId,
|
||||
to: r.userTable.id,
|
||||
}),
|
||||
bookmarks: r.many.bookmarkTable(),
|
||||
},
|
||||
bookmarkTable: {
|
||||
user: r.one.userTable({
|
||||
from: r.bookmarkTable.userId,
|
||||
to: r.userTable.id,
|
||||
}),
|
||||
category: r.one.categoryTable({
|
||||
from: r.bookmarkTable.categoryId,
|
||||
to: r.categoryTable.id,
|
||||
}),
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export * from './todo'
|
||||
export * from '../../../modules/bookmarks/schema'
|
||||
export * from '../../auth/schema'
|
||||
|
||||
Reference in New Issue
Block a user