Reduce noisy runtime logging in frontend flows.
This keeps chat, notification, and post interactions cleaner in production while preserving error-level visibility.
This commit is contained in:
@@ -35,19 +35,16 @@ export const initDatabase = async (userId?: string): Promise<void> => {
|
||||
|
||||
// 如果存在旧的数据库连接且用户ID变化,需要关闭旧连接
|
||||
if (db && currentDbUserId !== userId) {
|
||||
console.log(`[Database] 切换用户数据库: ${currentDbUserId} -> ${userId}`);
|
||||
await closeDatabase();
|
||||
}
|
||||
|
||||
// 如果已经打开了正确的数据库,直接返回
|
||||
if (db && currentDbUserId === userId) {
|
||||
console.log(`[Database] 数据库已初始化: ${dbName}`);
|
||||
return;
|
||||
}
|
||||
|
||||
db = await SQLite.openDatabaseAsync(dbName);
|
||||
currentDbUserId = userId || null;
|
||||
console.log(`[Database] 打开数据库: ${dbName}`);
|
||||
|
||||
// 创建消息表(包含新字段 seq, status, segments)
|
||||
await db.execAsync(`
|
||||
@@ -153,7 +150,6 @@ export const initDatabase = async (userId?: string): Promise<void> => {
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_conversation_seq ON messages(conversationId, seq);
|
||||
`);
|
||||
|
||||
console.log('数据库初始化成功');
|
||||
} catch (error) {
|
||||
console.error('数据库初始化失败:', error);
|
||||
throw error;
|
||||
@@ -167,7 +163,6 @@ export const closeDatabase = async (): Promise<void> => {
|
||||
if (db) {
|
||||
try {
|
||||
await db.closeAsync();
|
||||
console.log('[Database] 数据库连接已关闭');
|
||||
} catch (error) {
|
||||
console.error('[Database] 关闭数据库失败:', error);
|
||||
}
|
||||
@@ -198,19 +193,16 @@ const migrateDatabase = async (): Promise<void> => {
|
||||
// 添加 seq 列
|
||||
if (!columns.includes('seq')) {
|
||||
await database.execAsync(`ALTER TABLE messages ADD COLUMN seq INTEGER DEFAULT 0`);
|
||||
console.log('数据库迁移:添加 seq 列');
|
||||
}
|
||||
|
||||
// 添加 status 列
|
||||
if (!columns.includes('status')) {
|
||||
await database.execAsync(`ALTER TABLE messages ADD COLUMN status TEXT DEFAULT 'normal'`);
|
||||
console.log('数据库迁移:添加 status 列');
|
||||
}
|
||||
|
||||
// 添加 segments 列(用于存储消息的 segments JSON)
|
||||
if (!columns.includes('segments')) {
|
||||
await database.execAsync(`ALTER TABLE messages ADD COLUMN segments TEXT`);
|
||||
console.log('数据库迁移:添加 segments 列');
|
||||
}
|
||||
|
||||
// 检查 conversations 表是否有 lastSeq 列
|
||||
@@ -221,7 +213,6 @@ const migrateDatabase = async (): Promise<void> => {
|
||||
|
||||
if (!convColumns.includes('lastSeq')) {
|
||||
await database.execAsync(`ALTER TABLE conversations ADD COLUMN lastSeq INTEGER DEFAULT 0`);
|
||||
console.log('数据库迁移:添加 lastSeq 列');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('数据库迁移失败:', error);
|
||||
|
||||
Reference in New Issue
Block a user