Add multi-language support and new repository methods for book synchronization
- Extend repository methods to handle API requests for fetching books, chapters, characters, and other entities with multilingual support (`lang: 'fr' | 'en'`). - Add `uploadBookForSync` logic to consolidate and decrypt book data for synchronization. - Refactor schema migration logic to remove console logs and streamline table recreation. - Enhance error handling across database repositories and IPC methods.
This commit is contained in:
@@ -483,7 +483,6 @@ function dropColumnIfExists(db: Database, tableName: string, columnName: string)
|
||||
if (columnExists(db, tableName, columnName)) {
|
||||
try {
|
||||
db.exec(`ALTER TABLE ${tableName} DROP COLUMN ${columnName}`);
|
||||
console.log(`[Migration] Dropped column ${columnName} from ${tableName}`);
|
||||
} catch (e) {
|
||||
console.error(`[Migration] Failed to drop column ${columnName} from ${tableName}:`, e);
|
||||
}
|
||||
@@ -502,7 +501,6 @@ function recreateTable(db: Database, tableName: string, newSchema: string, colum
|
||||
db.exec(`INSERT INTO ${tableName} (${columnsToKeep}) SELECT ${columnsToKeep} FROM ${tableName}_backup`);
|
||||
db.exec(`DROP TABLE ${tableName}_backup`);
|
||||
db.exec('PRAGMA foreign_keys = ON');
|
||||
console.log(`[Migration] Recreated table ${tableName}`);
|
||||
} catch (e) {
|
||||
console.error(`[Migration] Failed to recreate table ${tableName}:`, e);
|
||||
db.exec('PRAGMA foreign_keys = ON');
|
||||
@@ -519,12 +517,8 @@ export function runMigrations(db: Database): void {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`[Migration] Upgrading schema from version ${currentVersion} to ${SCHEMA_VERSION}`);
|
||||
|
||||
// Migration v2: Remove NOT NULL constraints to allow null values from server sync
|
||||
if (currentVersion < 2) {
|
||||
console.log('[Migration] Running migration v2: Allowing NULL in certain columns...');
|
||||
|
||||
// Recreate erit_books with nullable hashed_sub_title and summary
|
||||
recreateTable(db, 'erit_books', `
|
||||
CREATE TABLE erit_books (
|
||||
@@ -578,11 +572,8 @@ export function runMigrations(db: Database): void {
|
||||
FOREIGN KEY (plot_point_id) REFERENCES book_plot_points(plot_point_id) ON DELETE CASCADE
|
||||
)
|
||||
`, 'chapter_info_id, chapter_id, act_id, incident_id, plot_point_id, book_id, author_id, summary, goal, last_update');
|
||||
|
||||
console.log('[Migration] Migration v2 completed');
|
||||
}
|
||||
|
||||
// Update schema version
|
||||
setDbSchemaVersion(db, SCHEMA_VERSION);
|
||||
console.log(`[Migration] Schema updated to version ${SCHEMA_VERSION}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user