This repository has no description
1.2 kB
38 lines
1import {
2 pgTable,
3 text,
4 timestamp,
5 jsonb,
6 uuid,
7 integer,
8 index,
9 type PgTableWithColumns,
10} from 'drizzle-orm/pg-core';
11import { publishedRecords } from './publishedRecord.sql';
12
13export const cards: PgTableWithColumns<any> = pgTable(
14 'cards',
15 {
16 id: uuid('id').primaryKey(),
17 authorId: text('author_id').notNull(),
18 type: text('type').notNull(), // URL, NOTE, HIGHLIGHT
19 contentData: jsonb('content_data').notNull(),
20 url: text('url'), // Optional URL field for all card types
21 parentCardId: uuid('parent_card_id').references(() => cards.id),
22 publishedRecordId: uuid('published_record_id').references(
23 () => publishedRecords.id,
24 ),
25 libraryCount: integer('library_count').notNull().default(0),
26 createdAt: timestamp('created_at').notNull().defaultNow(),
27 updatedAt: timestamp('updated_at').notNull().defaultNow(),
28 },
29 (table) => {
30 return {
31 // Critical for findUsersUrlCardByUrl queries
32 authorUrlIdx: index('cards_author_url_idx').on(table.authorId, table.url),
33
34 // For general card queries by author
35 authorIdIdx: index('cards_author_id_idx').on(table.authorId),
36 };
37 },
38);