pl / src /db /schema.ts
ghuser1's picture
Upload schema.ts
24cdd6a verified
Raw
History Blame Contribute Delete
2.61 kB
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
// Prompt 表 — 一条记录可同时含图像 + 视频提示词
export const prompts = sqliteTable('prompts', {
id: text('id').primaryKey(),
title: text('title').notNull(),
contentImage: text('content_image').default(''), // gpt-image-2
contentVideo: text('content_video').default(''), // seedance-2
translationImage: text('translation_image'),
translationVideo: text('translation_video'),
tags: text('tags').default('[]'), // JSON array
sourceUrl: text('source_url'),
isFavorite: integer('is_favorite', { mode: 'boolean' }).default(false),
createdAt: integer('created_at').notNull(),
updatedAt: integer('updated_at').notNull(),
});
// 已生成的图片(独立表,存历史多张)
export const images = sqliteTable('images', {
id: text('id').primaryKey(),
promptId: text('prompt_id').notNull(),
b64: text('b64').notNull(), // data:image/png;base64,...
model: text('model').notNull(),
size: text('size').notNull(), // 1024x1024 / 1792x1024 / 1024x1792
quality: text('quality').notNull(), // standard | hd
generationDuration: integer('generation_duration').notNull(), // ms
promptUsed: text('prompt_used').notNull(),
createdAt: integer('created_at').notNull(),
});
// 全局设置(单行,id = 'default')
// 翻译复用 OpenAI 同一套配置;只允许独立选择翻译模型
export const settings = sqliteTable('settings', {
id: text('id').primaryKey().default('default'),
openaiBaseUrl: text('openai_base_url').default('https://api.openai.com/v1'),
openaiApiKey: text('openai_api_key').default(''),
imageModel: text('image_model').default('gpt-image-2'),
// 全局默认生成分辨率
defaultSize: text('default_size').default('1024x1024'),
// 自定义分辨率(除预设 1024x1024/1792x1024/1024x1792 外);JSON 数组字符串,如 ["768x768","2048x2048"]
customSizes: text('custom_sizes').default('[]'),
translateModel: text('translate_model').default('gpt-4o-mini'),
// 访问密码 hash(空 = 不需要登陆)
accessPassword: text('access_password').default(''),
// 前端轮询生成 jobs 的间隔(ms),默认 3000,范围 1000~30000
jobPollInterval: integer('job_poll_interval').default(3000),
updatedAt: integer('updated_at').notNull(),
});
export type Prompt = typeof prompts.$inferSelect;
export type NewPrompt = typeof prompts.$inferInsert;
export type Image = typeof images.$inferSelect;
export type Settings = typeof settings.$inferSelect;