Refacor electron app and add migrations

This commit is contained in:
2026-03-04 01:38:43 +01:00
parent 4e95ae77c5
commit be91b6dfe8
70 changed files with 1824 additions and 923 deletions

43
electron/data-source.ts Normal file
View File

@@ -0,0 +1,43 @@
/**
* TypeORM DataSource used by the CLI migration tools (generate / run / revert).
*
* At **runtime** the DataSource is constructed inside `main.ts` and
* pointed at the user's Electron `userData` directory instead.
*
* For CLI use, the database is stored at the project root (`metoyou.sqlite`)
* so TypeORM can diff entity metadata against the current schema when
* generating new migrations.
*/
import 'reflect-metadata';
import { DataSource } from 'typeorm';
import * as path from 'path';
import * as fs from 'fs';
import { settings } from './settings';
import {
MessageEntity,
UserEntity,
RoomEntity,
ReactionEntity,
BanEntity,
AttachmentEntity,
MetaEntity
} from './entities';
const projectRootDatabaseFilePath = path.join(__dirname, '..', '..', settings.databaseName);
let databaseFileBuffer: Uint8Array | undefined;
if (fs.existsSync(projectRootDatabaseFilePath)) {
databaseFileBuffer = fs.readFileSync(projectRootDatabaseFilePath);
}
export const AppDataSource = new DataSource({
type: 'sqljs',
database: databaseFileBuffer,
entities: [MessageEntity, UserEntity, RoomEntity, ReactionEntity, BanEntity, AttachmentEntity, MetaEntity],
migrations: [path.join(__dirname, 'migrations', '*.{ts,js}')],
synchronize: false,
logging: false,
autoSave: true,
location: projectRootDatabaseFilePath
});