57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
|
|
import type { SQLiteDatabase } from 'expo-sqlite';
|
||
|
|
import {
|
||
|
|
CREATE_MESSAGES_TABLE,
|
||
|
|
CREATE_MESSAGES_INDEXES,
|
||
|
|
MIGRATE_MESSAGES_TABLE,
|
||
|
|
} from './MessageSchema';
|
||
|
|
import {
|
||
|
|
CREATE_CONVERSATIONS_TABLE,
|
||
|
|
CREATE_CONVERSATION_CACHE_TABLE,
|
||
|
|
CREATE_CONVERSATION_LIST_CACHE_TABLE,
|
||
|
|
MIGRATE_CONVERSATIONS_TABLE,
|
||
|
|
} from './ConversationSchema';
|
||
|
|
import {
|
||
|
|
CREATE_USERS_TABLE,
|
||
|
|
CREATE_CURRENT_USER_CACHE_TABLE,
|
||
|
|
} from './UserSchema';
|
||
|
|
import {
|
||
|
|
CREATE_GROUPS_TABLE,
|
||
|
|
CREATE_GROUP_MEMBERS_TABLE,
|
||
|
|
CREATE_GROUP_INDEXES,
|
||
|
|
} from './GroupSchema';
|
||
|
|
import {
|
||
|
|
CREATE_POSTS_CACHE_TABLE,
|
||
|
|
} from './PostSchema';
|
||
|
|
|
||
|
|
export async function runMigrations(db: SQLiteDatabase): Promise<void> {
|
||
|
|
if (typeof window !== 'undefined') {
|
||
|
|
try {
|
||
|
|
await db.execAsync(`PRAGMA locking_mode = EXCLUSIVE;`);
|
||
|
|
await db.execAsync(`PRAGMA journal_mode = MEMORY;`);
|
||
|
|
await db.execAsync(`PRAGMA temp_store = MEMORY;`);
|
||
|
|
console.log('[MigrationManager] Web: 已设置 EXCLUSIVE locking + MEMORY journal/temp 模式');
|
||
|
|
} catch (e) {
|
||
|
|
console.warn('[MigrationManager] 设置 PRAGMA 失败:', e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
await db.execAsync(CREATE_MESSAGES_TABLE);
|
||
|
|
await db.execAsync(CREATE_CONVERSATIONS_TABLE);
|
||
|
|
await db.execAsync(CREATE_CONVERSATION_CACHE_TABLE);
|
||
|
|
await db.execAsync(CREATE_CONVERSATION_LIST_CACHE_TABLE);
|
||
|
|
await db.execAsync(CREATE_USERS_TABLE);
|
||
|
|
await db.execAsync(CREATE_CURRENT_USER_CACHE_TABLE);
|
||
|
|
await db.execAsync(CREATE_GROUPS_TABLE);
|
||
|
|
await db.execAsync(CREATE_GROUP_MEMBERS_TABLE);
|
||
|
|
await db.execAsync(CREATE_POSTS_CACHE_TABLE);
|
||
|
|
|
||
|
|
for (const indexSql of CREATE_MESSAGES_INDEXES) {
|
||
|
|
await db.execAsync(indexSql);
|
||
|
|
}
|
||
|
|
for (const indexSql of CREATE_GROUP_INDEXES) {
|
||
|
|
await db.execAsync(indexSql);
|
||
|
|
}
|
||
|
|
|
||
|
|
await MIGRATE_MESSAGES_TABLE(db);
|
||
|
|
await MIGRATE_CONVERSATIONS_TABLE(db);
|
||
|
|
}
|