Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🌐 chore: translate non-English comments to English in packages/database (#10468)

LobeHub Bot285a05059ea6
diff --git a/packages/database/src/client/db.ts b/packages/database/src/client/db.ts
index 5c1be52de2c..ef9a67c9bd3 100644
--- a/packages/database/src/client/db.ts
+++ b/packages/database/src/client/db.ts
@@ -207,7 +207,7 @@ export class DatabaseManager {
return this.db;
}
- // 初始化数据库
+ // Initialize database
async initialize(callbacks?: DatabaseLoadingCallbacks): Promise<DrizzleInstance> {
if (this.initPromise) return this.initPromise;
@@ -218,13 +218,13 @@ export class DatabaseManager {
if (this.dbInstance) return this.dbInstance;
const time = Date.now();
- // 初始化数据库
+ // Initialize database
this.callbacks?.onStateChange?.(DatabaseLoadingState.Initializing);
- // 加载依赖
+ // Load dependencies
const { fsBundle, PGlite, MemoryFS, IdbFs, vector } = await this.loadDependencies();
- // 加载并编译 WASM 模块
+ // Load and compile WASM module
const wasmModule = await this.loadWasmModule();
const { initPgliteWorker } = await import('./pglite');
@@ -267,10 +267,10 @@ export class DatabaseManager {
this.callbacks?.onStateChange?.(DatabaseLoadingState.Error);
const error = e as Error;
- // 查询迁移表数据
+ // Query migration table data
let migrationsTableData: MigrationTableItem[] = [];
try {
- // 尝试查询迁移表
+ // Attempt to query migration table
const drizzleMigration = new DrizzleMigrationModel(this.db as any);
migrationsTableData = await drizzleMigration.getMigrationList();
} catch (queryError) {
@@ -295,7 +295,7 @@ export class DatabaseManager {
return this.initPromise;
}
- // 获取数据库实例
+ // Get database instance
get db(): DrizzleInstance {
if (!this.dbInstance) {
throw new Error('Database not initialized. Please call initialize() first.');
@@ -303,7 +303,7 @@ export class DatabaseManager {
return this.dbInstance;
}
- // 创建代理对象
+ // Create proxy object
createProxy(): DrizzleInstance {
return new Proxy({} as DrizzleInstance, {
get: (target, prop) => {
@@ -313,7 +313,7 @@ export class DatabaseManager {
}
async resetDatabase(): Promise<void> {
- // 1. 关闭现有的 PGlite 连接(如果存在)
+ // 1. Close existing PGlite connection (if exists)
if (this.dbInstance) {
try {
// @ts-ignore
@@ -321,31 +321,31 @@ export class DatabaseManager {
console.log('PGlite instance closed successfully.');
} catch (e) {
console.error('Error closing PGlite instance:', e);
- // 即使关闭失败,也尝试继续删除,IndexedDB 的 onblocked 或 onerror 会处理后续问题
+ // Even if closing fails, continue with deletion attempt; IndexedDB onblocked or onerror will handle subsequent issues
}
}
- // 2. 重置数据库实例和初始化状态
+ // 2. Reset database instance and initialization state
this.dbInstance = null;
this.initPromise = null;
- this.isLocalDBSchemaSynced = false; // 重置同步状态
+ this.isLocalDBSchemaSynced = false; // Reset sync state
- // 3. 删除 IndexedDB 数据库
+ // 3. Delete IndexedDB database
return new Promise<void>((resolve, reject) => {
- // 检查 IndexedDB 是否可用
+ // Check if IndexedDB is available
if (typeof indexedDB === 'undefined') {
console.warn('IndexedDB is not available, cannot delete database');
- resolve(); // 在此环境下无法删除,直接解决
+ resolve(); // Cannot delete in this environment, resolve directly
return;
}
- const dbName = `/pglite/${DB_NAME}`; // PGlite IdbFs 使用的路径
+ const dbName = `/pglite/${DB_NAME}`; // Path used by PGlite IdbFs
const request = indexedDB.deleteDatabase(dbName);
request.onsuccess = () => {
console.log(`✅ Database '${dbName}' reset successfully`);
- // 清除本地存储的模式哈希
+ // Clear locally stored schema hash
if (typeof localStorage !== 'undefined') {
localStorage.removeItem(pgliteSchemaHashCache);
}
@@ -365,7 +365,7 @@ export class DatabaseManager {
};
request.onblocked = (event) => {
- // 当其他打开的连接阻止数据库删除时,会触发此事件
+ // This event is triggered when other open connections block database deletion
console.warn(
`Deletion of database '${dbName}' is blocked. This usually means other connections (e.g., in other tabs) are still open. Event:`,
event,
@@ -380,13 +380,13 @@ export class DatabaseManager {
}
}
-// 导出单例
+// Export singleton
const dbManager = DatabaseManager.getInstance();
-// 保持原有的 clientDB 导出不变
+// Keep original clientDB export unchanged
export const clientDB = dbManager.createProxy();
-// 导出初始化方法,供应用启动时使用
+// Export initialization method for application startup
export const initializeDB = (callbacks?: DatabaseLoadingCallbacks) =>
dbManager.initialize(callbacks);
diff --git a/packages/database/src/repositories/dataImporter/deprecated/index.ts b/packages/database/src/repositories/dataImporter/deprecated/index.ts
index b0541e5d5b1..3c3ed3b14c7 100644
--- a/packages/database/src/repositories/dataImporter/deprecated/index.ts
+++ b/packages/database/src/repositories/dataImporter/deprecated/index.ts
@@ -127,7 +127,7 @@ export class DeprecatedDataImporterRepos {
// filter out existing session, only insert new ones
.filter((s) => query.every((q) => q.clientId !== s.id));
- // 只有当需要有新的 session 时,才会插入 agent
+ // Only insert agent when new sessions are needed
if (shouldInsertSessionAgents.length > 0) {
const agentMapArray = await trx
.insert(agents)
@@ -221,14 +221,14 @@ export class DeprecatedDataImporterRepos {
parentId: null,
provider: extra?.fromProvider,
sessionId: sessionId ? sessionIdMap[sessionId] : null,
- topicId: topicId ? topicIdMap[topicId] : null, // 暂时设为 NULL
+ topicId: topicId ? topicIdMap[topicId] : null, // Temporarily set to NULL
updatedAt: new Date(updatedAt),
userId: this.userId,
}),
);
console.time('insert messages');
- const BATCH_SIZE = 100; // 每批次插入的记录数
+ const BATCH_SIZE = 100; // Number of records to insert per batch
for (let i = 0; i < inertValues.length; i += BATCH_SIZE) {
const batch = inertValues.slice(i, i + BATCH_SIZE);
@@ -257,7 +257,7 @@ export class DeprecatedDataImporterRepos {
// 3. update parentId for messages
console.time('execute updates parentId');
const parentIdUpdates = shouldInsertMessages
- .filter((msg) => msg.parentId) // 只处理有 parentId 的消息
+ .filter((msg) => msg.parentId) // Only process messages with parentId
.map((msg) => {
if (messageIdMap[msg.parentId as string])
return sql`WHEN ${messages.clientId} = ${msg.id} THEN ${messageIdMap[msg.parentId as string]} `;
@@ -315,7 +315,7 @@ export class DeprecatedDataImporterRepos {
);
}
- // TODO: 未来需要处理 TTS 和图片的插入 (目前存在 file 的部分,不方便处理)
+ // TODO: Need to handle TTS and image insertion in the future (currently difficult to handle due to file-related parts)
}
messageResult.added = shouldInsertMessages.length;
diff --git a/packages/database/src/repositories/dataImporter/index.ts b/packages/database/src/repositories/dataImporter/index.ts
index 01d2447dbb6..1e5d853d635 100644
--- a/packages/database/src/repositories/dataImporter/index.ts
+++ b/packages/database/src/repositories/dataImporter/index.ts
@@ -67,7 +67,7 @@ const IMPORT_TABLE_CONFIG: TableImportConfig[] = [
},
{
conflictStrategy: 'skip',
- preserveId: true, // 需要保留原始ID
+ preserveId: true, // Need to preserve original ID
relations: [
{
field: 'providerId',
@@ -89,7 +89,7 @@ const IMPORT_TABLE_CONFIG: TableImportConfig[] = [
uniqueConstraints: ['slug'],
},
{
- // 对slug字段进行特殊处理
+ // Special processing for slug field
fieldProcessors: {
slug: (value) => `${value}-${uuid().slice(0, 8)}`,
},
@@ -113,7 +113,7 @@ const IMPORT_TABLE_CONFIG: TableImportConfig[] = [
},
{
conflictStrategy: 'skip',
- isCompositeKey: true, // 使用复合主键 [agentId, sessionId]
+ isCompositeKey: true, // Uses composite primary key [agentId, sessionId]
relations: [
{
field: 'agentId',
@@ -172,7 +172,7 @@ const IMPORT_TABLE_CONFIG: TableImportConfig[] = [
},
{
conflictStrategy: 'skip',
- preserveId: true, // 使用消息ID作为主键
+ preserveId: true, // Uses message ID as primary key
relations: [
{
field: 'id',
@@ -182,7 +182,7 @@ const IMPORT_TABLE_CONFIG: TableImportConfig[] = [
table: 'messagePlugins',
},
{
- isCompositeKey: true, // 使用复合主键 [messageId, chunkId]
+ isCompositeKey: true, // Uses composite primary key [messageId, chunkId]
relations: [
{
field: 'messageId',
@@ -196,7 +196,7 @@ const IMPORT_TABLE_CONFIG: TableImportConfig[] = [
table: 'messageChunks',
},
{
- isCompositeKey: true, // 使用复合主键 [id, queryId, chunkId]
+ isCompositeKey: true, // Uses composite primary key [id, queryId, chunkId]
relations: [
{
field: 'id',
@@ -228,7 +228,7 @@ const IMPORT_TABLE_CONFIG: TableImportConfig[] = [
// },
{
conflictStrategy: 'skip',
- preserveId: true, // 使用消息ID作为主键
+ preserveId: true, // Uses message ID as primary key
relations: [
{
field: 'id',
@@ -239,7 +239,7 @@ const IMPORT_TABLE_CONFIG: TableImportConfig[] = [
},
// {
// conflictStrategy: 'skip',
- // preserveId: true, // 使用消息ID作为主键
+ // preserveId: true, // Uses message ID as primary key
// relations: [
// {
// field: 'id',
@@ -273,7 +273,7 @@ export class DataImporterRepos {
};
/**
- * 导入PostgreSQL数据
+ * Import PostgreSQL data
*/
async importPgData(
dbData: ImportPgDataStructure,
@@ -282,13 +282,13 @@ export class DataImporterRepos {
const results: Record<string, ImportResult> = {};
const { data } = dbData;
- // 初始化ID映射表和冲突记录
+ // Initialize ID mapping table and conflict records
this.idMaps = {};
this.conflictRecords = {};
try {
await this.db.transaction(async (trx) => {
- // 按配置顺序导入表
+ // Import tables in configuration order
for (const config of IMPORT_TABLE_CONFIG) {
const { table: tableName } = config;
@@ -299,7 +299,7 @@ export class DataImporterRepos {
continue;
}
- // 使用统一的导入方法
+ // Use unified import method
const result = await this.importTableData(trx, config, tableData, conflictStrategy);
console.log(`imported table: ${tableName}, records: ${tableData.length}`);
@@ -325,11 +325,11 @@ export class DataImporterRepos {
}
/**
- * 从错误中提取详细信息
+ * Extract detailed information from error
*/
private extractErrorDetails(error: any) {
if (error.code === '23505') {
- // PostgreSQL 唯一约束错误码
+ // PostgreSQL unique constraint error code
const match = error.detail?.match(/Key \((.+?)\)=\((.+?)\) already exists/);
if (match) {
return {
@@ -344,7 +344,7 @@ export class DataImporterRepos {
}
/**
- * 统一的表数据导入函数 - 处理所有类型的表
+ * Unified table data import function - Handles all types of tables
*/
private async importTableData(
trx: any,
@@ -368,13 +368,13 @@ export class DataImporterRepos {
const table = EXPORT_TABLES[tableName];
const result: ImportResult = { added: 0, errors: 0, skips: 0, updated: 0 };
- // 初始化该表的ID映射
+ // Initialize ID mapping for this table
if (!this.idMaps[tableName]) {
this.idMaps[tableName] = {};
}
try {
- // 1. 查找已存在的记录(基于clientId和userId)
+ // 1. Find existing records (based on clientId and userId)
let existingRecords: any[] = [];
if ('clientId' in table && 'userId' in table) {
@@ -387,7 +387,7 @@ export class DataImporterRepos {
}
}
- // 如果需要保留原始ID,还需要检查ID是否已存在
+ // If need to preserve original ID, also check if ID already exists
if (preserveId && !isCompositeKey) {
const ids = tableData.map((item) => item.id).filter(Boolean);
if (ids.length > 0) {
@@ -395,7 +395,7 @@ export class DataImporterRepos {
where: inArray(table.id, ids),
});
- // 合并到已存在记录集合中
+ // Merge into existing records set
existingRecords = [
...existingRecords,
...idExistingRecords.filter(
@@ -407,28 +407,28 @@ export class DataImporterRepos {
result.skips = existingRecords.length;
- // 2. 为已存在的记录建立ID映射
+ // 2. Establish ID mapping for existing records
for (const record of existingRecords) {
- // 只有非复合主键表才需要ID映射
+ // Only non-composite key tables need ID mapping
if (!isCompositeKey) {
this.idMaps[tableName][record.id] = record.id;
if (record.clientId) {
this.idMaps[tableName][record.clientId] = record.id;
}
- // 记录中可能使用的任何其他ID标识符
+ // Any other ID identifiers that may be used in records
const originalRecord = tableData.find(
(item) => item.id === record.id || item.clientId === record.clientId,
);
if (originalRecord) {
- // 确保原始记录ID也映射到数据库记录ID
+ // Ensure original record ID also maps to database record ID
this.idMaps[tableName][originalRecord.id] = record.id;
}
}
}
- // 3. 筛选出需要插入的记录
+ // 3. Filter out records that need to be inserted
const recordsToInsert = tableData.filter(
(item) =>
!existingRecords.some(
@@ -442,22 +442,22 @@ export class DataImporterRepos {
return result;
}
- // 4. 准备导入数据
+ // 4. Prepare import data
const preparedData = recordsToInsert.map((item) => {
const originalId = item.id;
- // 处理日期字段
+ // Process date fields
const dateFields: any = {};
if (item.createdAt) dateFields.createdAt = new Date(item.createdAt);
if (item.updatedAt) dateFields.updatedAt = new Date(item.updatedAt);
if (item.accessedAt) dateFields.accessedAt = new Date(item.accessedAt);
- // 创建新记录对象
+ // Create new record object
let newRecord: any = {};
- // 根据是否复合主键和是否保留ID决定如何处理
+ // Decide how to process based on whether it's composite key and whether to preserve ID
if (isCompositeKey) {
- // 对于复合主键表,不包含id字段
+ // For composite key tables, don't include id field
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { id: _, ...rest } = item;
newRecord = {
@@ -467,7 +467,7 @@ export class DataImporterRepos {
userId: this.userId,
};
} else {
- // 非复合主键表处理
+ // Non-composite key table processing
newRecord = {
...(preserveId ? item : { ...item, id: undefined }),
...dateFields,
@@ -476,19 +476,19 @@ export class DataImporterRepos {
};
}
- // 应用字段处理器
+ // Apply field processors
for (const field in fieldProcessors) {
if (newRecord[field] !== undefined) {
newRecord[field] = fieldProcessors[field](newRecord[field]);
}
}
- // 特殊表处理
+ // Special table processing
if (tableName === 'userSettings') {
newRecord.id = this.userId;
}
- // 处理关系字段(外键引用)
+ // Process relation fields (foreign key references)
for (const relation of relations) {
const { field, sourceTable } = relation;
@@ -498,7 +498,7 @@ export class DataImporterRepos {
if (mappedId) {
newRecord[field] = mappedId;
} else {
- // 找不到映射,设为null
+ // Cannot find mapping, set to null
console.warn(
`Could not find mapped ID for ${field}=${newRecord[field]} in table ${sourceTable}`,
);
@@ -507,7 +507,7 @@ export class DataImporterRepos {
}
}
- // 简化处理自引用字段 - 直接设为null
+ // Simplified processing of self-reference fields - directly set to null
for (const selfRef of selfReferences) {
const { field } = selfRef;
if (newRecord[field] !== undefined) {
@@ -518,15 +518,15 @@ export class DataImporterRepos {
return { newRecord, originalId };
});
- // 5. 检查唯一约束并应用冲突策略
+ // 5. Check unique constraints and apply conflict strategy
for (const record of preparedData) {
if (isCompositeKey && uniqueConstraints.length > 0) {
- // 对于复合主键表,将所有唯一约束字段作为一个组合条件
+ // For composite key tables, treat all unique constraint fields as a combined condition
const whereConditions = uniqueConstraints
.filter((field) => record.newRecord[field] !== undefined)
.map((field) => eq(table[field], record.newRecord[field]));
- // 添加userId条件(如果表有userId字段)
+ // Add userId condition (if table has userId field)
if ('userId' in table) {
whereConditions.push(eq(table.userId, this.userId));
}
@@ -537,7 +537,7 @@ export class DataImporterRepos {
});
if (exists) {
- // 记录冲突
+ // Record conflict
if (!this.conflictRecords[tableName]) this.conflictRecords[tableName] = [];
this.conflictRecords[tableName].push({
field: uniqueConstraints.join(','),
@@ -546,13 +546,13 @@ export class DataImporterRepos {
.join(','),
});
- // 应用冲突策略
+ // Apply conflict strategy
switch (conflictStrategy) {
case 'skip': {
record.newRecord._skip = true;
result.skips++;
- // 关键改进:即使跳过,也建立ID映射关系
+ // Key improvement: establish ID mapping even if skipped
if (!isCompositeKey) {
this.idMaps[tableName][record.originalId] = exists.id;
if (record.newRecord.clientId) {
@@ -562,11 +562,11 @@ export class DataImporterRepos {
break;
}
case 'override': {
- // 不需要额外操作,插入时会覆盖
+ // No additional operation needed, will be overridden on insert
break;
}
case 'merge': {
- // 合并数据
+ // Merge data
await trx
.update(table)
.set(record.newRecord)
@@ -582,30 +582,30 @@ export class DataImporterRepos {
}
}
} else {
- // 处理唯一约束
+ // Process unique constraints
for (const field of uniqueConstraints) {
if (!record.newRecord[field]) continue;
- // 检查字段值是否已存在
+ // Check if field value already exists
const exists = await trx.query[tableName].findFirst({
where: eq(table[field], record.newRecord[field]),
});
if (exists) {
- // 记录冲突
+ // Record conflict
if (!this.conflictRecords[tableName]) this.conflictRecords[tableName] = [];
this.conflictRecords[tableName].push({
field,
value: record.newRecord[field],
});
- // 应用冲突策略
+ // Apply conflict strategy
switch (conflictStrategy) {
case 'skip': {
record.newRecord._skip = true;
result.skips++;
- // 关键改进:即使跳过,也建立ID映射关系
+ // Key improvement: establish ID mapping even if skipped
if (!isCompositeKey) {
this.idMaps[tableName][record.originalId] = exists.id;
if (record.newRecord.clientId) {
@@ -615,7 +615,7 @@ export class DataImporterRepos {
break;
}
case 'override': {
- // 应用字段处理器
+ // Apply field processor
if (field in fieldProcessors) {
record.newRecord[field] = fieldProcessors[field](record.newRecord[field]);
}
@@ -623,7 +623,7 @@ export class DataImporterRepos {
}
case 'merge': {
- // 合并数据
+ // Merge data
await trx
.update(table)
.set(record.newRecord)
@@ -641,13 +641,13 @@ export class DataImporterRepos {
}
}
- // 过滤掉标记为跳过的记录
+ // Filter out records marked to be skipped
const filteredData = preparedData.filter((record) => !record.newRecord._skip);
- // 清除临时标记
+ // Clear temporary markers
filteredData.forEach((record) => delete record.newRecord._skip);
- // 6. 批量插入数据
+ // 6. Batch insert data
const BATCH_SIZE = 100;
for (let i = 0; i < filteredData.length; i += BATCH_SIZE) {
@@ -657,12 +657,12 @@ export class DataImporterRepos {
const originalIds = batch.map((item) => item.originalId);
try {
- // 插入并返回结果
+ // Insert and return result
const insertQuery = trx.insert(table).values(itemsToInsert);
let insertResult;
- // 只对非复合主键表需要返回ID
+ // Only non-composite key tables need to return ID
if (!isCompositeKey) {
const res = await insertQuery.returning();
insertResult = res.map((item: any) => ({
@@ -671,18 +671,18 @@ export class DataImporterRepos {
}));
} else {
await insertQuery;
- insertResult = itemsToInsert.map(() => ({})); // 创建空结果以维持计数
+ insertResult = itemsToInsert.map(() => ({})); // Create empty result to maintain count
}
result.added += insertResult.length;
- // 建立ID映射关系 (只对非复合主键表)
+ // Establish ID mapping relationship (only for non-composite key tables)
if (!isCompositeKey) {
for (const [j, newRecord] of insertResult.entries()) {
const originalId = originalIds[j];
this.idMaps[tableName][originalId] = newRecord.id;
- // 同时确保clientId也能映射到正确的ID
+ // Also ensure clientId can map to the correct ID
const originalRecord = tableData.find((item) => item.id === originalId);
if (originalRecord && originalRecord.clientId) {
this.idMaps[tableName][originalRecord.clientId] = newRecord.id;
@@ -692,7 +692,7 @@ export class DataImporterRepos {
} catch (error) {
console.error(`Error batch inserting ${tableName}:`, error);
- // 处理错误并记录
+ // Handle error and record
if ((error as any).code === '23505') {
const match = (error as any).detail?.match(/Key \((.+?)\)=\((.+?)\) already exists/);
if (match) {
diff --git a/packages/database/src/schemas/generation.ts b/packages/database/src/schemas/generation.ts
index 32a1abc169d..0b984353933 100644
--- a/packages/database/src/schemas/generation.ts
+++ b/packages/database/src/schemas/generation.ts
@@ -10,7 +10,7 @@ import { files } from './file';
import { users } from './user';
/**
- * 生成主题表 - 用于组织和管理 AI 生成内容的主题
+ * Generation topics table - Used to organize and manage AI-generated content topics
*/
export const generationTopics = pgTable('generation_topics', {
id: text('id')
@@ -22,10 +22,10 @@ export const generationTopics = pgTable('generation_topics', {
.references(() => users.id, { onDelete: 'cascade' })
.notNull(),
- /** 简要描述主题内容,由 LLM 生成 */
+ /** Brief description of topic content, generated by LLM */
title: text('title'),
- /** 主题封面图片 URL */
+ /** Topic cover image URL */
coverUrl: text('cover_url'),
...timestamps,
@@ -37,7 +37,7 @@ export type NewGenerationTopic = typeof generationTopics.$inferInsert;
export type GenerationTopicItem = typeof generationTopics.$inferSelect;
/**
- * 生成批次表 - 存储一次生成请求的配置信息
+ * Generation batches table - Stores configuration information for a single generation request
*/
export const generationBatches = pgTable('generation_batches', {
id: text('id')
@@ -53,25 +53,25 @@ export const generationBatches = pgTable('generation_batches', {
.notNull()
.references(() => generationTopics.id, { onDelete: 'cascade' }),
- /** 服务商名称 */
+ /** Provider name */
provider: text('provider').notNull(),
- /** 模型名称 */
+ /** Model name */
model: text('model').notNull(),
- /** 生成提示词 */
+ /** Generation prompt */
prompt: text('prompt').notNull(),
- /** 图片宽度 */
+ /** Image width */
width: integer('width'),
- /** 图片高度 */
+ /** Image height */
height: integer('height'),
- /** 图片比例 */
+ /** Image aspect ratio */
ratio: varchar('ratio', { length: 64 }),
- /** 存储生成批次的配置,存放不需要建立索引的公共配置 */
+ /** Stores generation batch configuration for common settings that don't need indexing */
config: jsonb('config'),
...timestamps,
@@ -86,7 +86,7 @@ export type GenerationBatchWithGenerations = GenerationBatchItem & {
};
/**
- * 存储单个 AI 生成信息
+ * Stores individual AI generation information
*/
export const generations = pgTable('generations', {
id: text('id')
@@ -102,18 +102,18 @@ export const generations = pgTable('generations', {
.notNull()
.references(() => generationBatches.id, { onDelete: 'cascade' }),
- /** 关联的异步任务 ID */
+ /** Associated async task ID */
asyncTaskId: uuid('async_task_id').references(() => asyncTasks.id, {
onDelete: 'set null',
}),
- /** 关联的生成文件 ID,删除文件时连带删除生成记录 */
+ /** Associated generated file ID, deletes generation record when file is deleted */
fileId: text('file_id').references(() => files.id, { onDelete: 'cascade' }),
- /** 生成种子值 */
+ /** Generation seed value */
seed: integer('seed'),
- /** 生成的资源信息,包含存储在 s3 上的 key, 图片实际宽高,缩略图 key 等 */
+ /** Generated asset information, including S3 storage key, actual image dimensions, thumbnail key, etc. */
asset: jsonb('asset').$type<ImageGenerationAsset>(),
...timestamps,
diff --git a/packages/database/src/schemas/oidc.ts b/packages/database/src/schemas/oidc.ts
index b1e1e91a89a..179b9ab1ae8 100644
--- a/packages/database/src/schemas/oidc.ts
+++ b/packages/database/src/schemas/oidc.ts
@@ -6,8 +6,8 @@ import { timestamps, timestamptz } from './_helpers';
import { users } from './user';
/**
- * OIDC 授权码
- * oidc-provider 需要持久化的模型之一
+ * OIDC authorization code
+ * One of the models that oidc-provider needs to persist
*/
export const oidcAuthorizationCodes = pgTable('oidc_authorization_codes', {
id: varchar('id', { length: 255 }).primaryKey(),
@@ -23,8 +23,8 @@ export const oidcAuthorizationCodes = pgTable('oidc_authorization_codes', {
});
/**
- * OIDC 访问令牌
- * oidc-provider 需要持久化的模型之一
+ * OIDC access token
+ * One of the models that oidc-provider needs to persist
*/
export const oidcAccessTokens = pgTable('oidc_access_tokens', {
id: varchar('id', { length: 255 }).primaryKey(),
@@ -40,8 +40,8 @@ export const oidcAccessTokens = pgTable('oidc_access_tokens', {
});
/**
- * OIDC 刷新令牌
- * oidc-provider 需要持久化的模型之一
+ * OIDC refresh token
+ * One of the models that oidc-provider needs to persist
*/
export const oidcRefreshTokens = pgTable('oidc_refresh_tokens', {
id: varchar('id', { length: 255 }).primaryKey(),
@@ -57,8 +57,8 @@ export const oidcRefreshTokens = pgTable('oidc_refresh_tokens', {
});
/**
- * OIDC 设备代码
- * oidc-provider 需要持久化的模型之一
+ * OIDC device code
+ * One of the models that oidc-provider needs to persist
*/
export const oidcDeviceCodes = pgTable('oidc_device_codes', {
id: varchar('id', { length: 255 }).primaryKey(),
@@ -73,8 +73,8 @@ export const oidcDeviceCodes = pgTable('oidc_device_codes', {
});
/**
- * OIDC 交互会话
- * oidc-provider 需要持久化的模型之一
+ * OIDC interaction session
+ * One of the models that oidc-provider needs to persist
*/
export const oidcInteractions = pgTable('oidc_interactions', {
id: varchar('id', { length: 255 }).primaryKey(),
@@ -84,8 +84,8 @@ export const oidcInteractions = pgTable('oidc_interactions', {
});
/**
- * OIDC 授权记录
- * oidc-provider 需要持久化的模型之一
+ * OIDC grant record
+ * One of the models that oidc-provider needs to persist
*/
export const oidcGrants = pgTable('oidc_grants', {
id: varchar('id', { length: 255 }).primaryKey(),
@@ -100,14 +100,14 @@ export const oidcGrants = pgTable('oidc_grants', {
});
/**
- * OIDC 客户端配置
- * 存储 OIDC 客户端配置信息
+ * OIDC client configuration
+ * Stores OIDC client configuration information
*/
export const oidcClients = pgTable('oidc_clients', {
id: varchar('id', { length: 255 }).primaryKey(), // client_id
name: text('name').notNull(),
description: text('description'),
- clientSecret: varchar('client_secret', { length: 255 }), // 公共客户端可为 null
+ clientSecret: varchar('client_secret', { length: 255 }), // Can be null for public clients
redirectUris: text('redirect_uris').array().notNull(),
grants: text('grants').array().notNull(),
responseTypes: text('response_types').array().notNull(),
@@ -123,8 +123,8 @@ export const oidcClients = pgTable('oidc_clients', {
});
/**
- * OIDC 会话
- * oidc-provider 需要持久化的模型之一
+ * OIDC session
+ * One of the models that oidc-provider needs to persist
*/
export const oidcSessions = pgTable('oidc_sessions', {
id: varchar('id', { length: 255 }).primaryKey(),
@@ -137,8 +137,8 @@ export const oidcSessions = pgTable('oidc_sessions', {
});
/**
- * OIDC 授权同意记录
- * 记录用户对客户端的授权同意历史
+ * OIDC authorization consent record
+ * Records user authorization consent history for clients
*/
export const oidcConsents = pgTable(
'oidc_consents',
@@ -159,39 +159,39 @@ export const oidcConsents = pgTable(
);
/**
- * 通用认证凭证传递表
- * 用于在不同客户端(桌面端、浏览器插件、移动端等)之间安全传递认证凭证
+ * Generic authentication credential handoff table
+ * Used to securely pass authentication credentials between different clients (desktop, browser extension, mobile, etc.)
*
- * 工作流程:
- * 1. 客户端生成唯一的 handoff ID
- * 2. 将 handoff ID 作为参数附加到 OAuth redirect_uri
- * 3. 认证成功后,中间页将凭证存储到此表
- * 4. 客户端轮询此表获取凭证
- * 5. 成功获取后立即删除记录
+ * Workflow:
+ * 1. Client generates a unique handoff ID
+ * 2. Appends handoff ID as a parameter to OAuth redirect_uri
+ * 3. After successful authentication, intermediate page stores credentials in this table
+ * 4. Client polls this table to retrieve credentials
+ * 5. Record is immediately deleted after successful retrieval
*/
export const oauthHandoffs = pgTable('oauth_handoffs', {
/**
- * 由客户端生成的一次性唯一标识符
- * 用于客户端轮询时认领自己的凭证
+ * One-time unique identifier generated by the client
+ * Used for client polling to claim its own credentials
*/
id: text('id').primaryKey(),
/**
- * 客户端类型标识
- * 如: 'desktop', 'browser-extension', 'mobile-app' 等
+ * Client type identifier
+ * Examples: 'desktop', 'browser-extension', 'mobile-app', etc.
*/
client: varchar('client', { length: 50 }).notNull(),
/**
- * 凭证数据的 JSON 载荷
- * 灵活存储不同认证流程所需的各种数据
- * 当前主要包含: { code: string; state: string }
+ * JSON payload for credential data
+ * Flexible storage for various data required by different authentication flows
+ * Currently mainly contains: { code: string; state: string }
*/
payload: jsonb('payload').$type<Record<string, unknown>>().notNull(),
/**
- * 时间戳字段,用于 TTL 控制
- * 凭证应在创建后 5 分钟内被消费,否则视为过期
+ * Timestamp fields for TTL control
+ * Credentials should be consumed within 5 minutes of creation, otherwise considered expired
*/
...timestamps,
});