Spaces:
Paused
Paused
| import { pgTable, bigint, text, index, boolean, timestamp } from 'drizzle-orm/pg-core'; | |
| export const user = pgTable('user', { | |
| id: text('id').primaryKey(), | |
| age: bigint('age', { mode: 'number' }), | |
| username: text('username').notNull().unique(), | |
| passwordHash: text('password_hash').notNull(), | |
| storageQuota: bigint('storage_quota', { mode: 'number' }).notNull().default(10995116277760) // 10TB default quota | |
| }); | |
| export const session = pgTable('session', { | |
| id: text('id').primaryKey(), | |
| userId: text('user_id').notNull().references(() => user.id), | |
| expiresAt: timestamp('expires_at', { mode: 'date' }).notNull() | |
| }, (table) => ({ | |
| userIdIdx: index('session_user_id_idx').on(table.userId), | |
| expiresAtIdx: index('session_expires_at_idx').on(table.expiresAt) | |
| })); | |
| export const file = pgTable('file', { | |
| id: text('id').primaryKey(), | |
| name: text('name').notNull(), | |
| path: text('path').notNull(), | |
| size: bigint('size', { mode: 'number' }).notNull(), | |
| mimeType: text('mime_type').notNull(), | |
| userId: text('user_id').notNull().references(() => user.id), | |
| parentId: text('parent_id'), | |
| isFolder: boolean('is_folder').notNull().default(false), | |
| deletedAt: timestamp('deleted_at', { mode: 'date' }), | |
| createdAt: timestamp('created_at', { mode: 'date' }).notNull(), | |
| updatedAt: timestamp('updated_at', { mode: 'date' }).notNull(), | |
| // Hugging Face storage fields | |
| hash: text('hash'), // MD5 hash for deduplication | |
| hfPath: text('hf_path'), // Path in HF Dataset: {userId}/{hash}/{filename} | |
| isUploaded: boolean('is_uploaded').default(false), // Upload status to HF | |
| uploadedAt: timestamp('uploaded_at', { mode: 'date' }) // When successfully uploaded to HF | |
| }, (table) => ({ | |
| userIdIdx: index('file_user_id_idx').on(table.userId), | |
| parentIdIdx: index('file_parent_id_idx').on(table.parentId), | |
| isFolderIdx: index('file_is_folder_idx').on(table.isFolder), | |
| deletedAtIdx: index('file_deleted_at_idx').on(table.deletedAt), | |
| nameIdx: index('file_name_idx').on(table.name), | |
| userFolderIdx: index('file_user_folder_idx').on(table.userId, table.isFolder, table.deletedAt), | |
| userParentDeletedIdx: index('file_user_parent_deleted_idx').on(table.userId, table.parentId, table.deletedAt), | |
| hashIdx: index('file_hash_idx').on(table.hash), | |
| userHashIdx: index('file_user_hash_idx').on(table.userId, table.hash), | |
| uploadedHashIdx: index('file_uploaded_hash_idx').on(table.isUploaded, table.hash), | |
| hfPathIdx: index('file_hf_path_idx').on(table.hfPath) | |
| })); | |
| export type Session = typeof session.$inferSelect; | |
| export type User = typeof user.$inferSelect; | |
| export type File = typeof file.$inferSelect; | |