Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge-mercury #140

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/http-server/controllers/SyncRepositoriesController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Request, Response } from "express";
import { SimpleGit, simpleGit, SimpleGitOptions } from "simple-git";
import { dataSource } from "src/shared/db/postgres/infrastructure/data-source";

import { SQLiteTypeORM } from "../../shared/db/postgres/infrastructure/SQLiteTypeORM";
import { Logger } from "../../shared/logger/domain/Logger";
Expand Down Expand Up @@ -49,7 +50,7 @@ export class SyncRepositoriesController {

this.logger.info(`Databases difference: ${JSON.stringify(diffSummary)}`);

const database = new SQLiteTypeORM();
const database = new SQLiteTypeORM(dataSource, "./databases/evolution");
await database.initialize();
}
}
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Pino } from "src/shared/logger/infrastructure/Pino";

import { Server } from "./http-server/Server";
import { MercuryBanListLoader } from "./mercury/ban-list/infrastructure/MercuryBanListLoader";
import { dataSource, mercuryDataSource } from "./shared/db/postgres/infrastructure/data-source";
import { HostServer } from "./socket-server/HostServer";
import { MercuryServer } from "./socket-server/MercuryServer";
import WebSocketSingleton from "./web-socket-server/WebSocketSingleton";
Expand All @@ -19,13 +20,16 @@ async function start(): Promise<void> {
const server = new Server(logger);
const mercuryServer = new MercuryServer(logger);
const hostServer = new HostServer(logger);
const database = new SQLiteTypeORM();
const database = new SQLiteTypeORM(dataSource, "./databases/evolution");
const mercuryDatabase = new SQLiteTypeORM(mercuryDataSource, "./databases/mercury");
const banListLoader = new BanListLoader();
await banListLoader.loadDirectory("./banlists/evolution");
await BanListMemoryRepository.backup();
await MercuryBanListLoader.load("./mercury/lflist.conf");
await database.connect();
await database.initialize();
await mercuryDatabase.connect();
await mercuryDatabase.initialize();
await server.initialize();
WebSocketSingleton.getInstance();
hostServer.initialize();
Expand Down
14 changes: 4 additions & 10 deletions src/shared/db/postgres/infrastructure/SQLiteTypeORM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@ import { DataSource } from "typeorm";
import { CardEntity } from "../../../../edopro/card/infrastructure/postgres/CardEntity";
import { CardTextEntity } from "../../../../edopro/card/infrastructure/postgres/CardTextEntity";
import { Database } from "../../domain/Database";
import { dataSource } from "./data-source";

export class SQLiteTypeORM implements Database {
private readonly dataSource: DataSource;
private readonly directoryPath = "./databases/evolution";

constructor() {
this.dataSource = dataSource;
}
constructor(private readonly dataSource: DataSource, private readonly directoryPath: string) {}

async connect(): Promise<void> {
await this.dataSource.initialize();
Expand All @@ -34,7 +28,7 @@ export class SQLiteTypeORM implements Database {
}

private async merge(path: string): Promise<void> {
const queryRunner = dataSource.createQueryRunner();
const queryRunner = this.dataSource.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
Expand All @@ -52,8 +46,8 @@ export class SQLiteTypeORM implements Database {
}

private async isLoaded(): Promise<boolean> {
const cardRepository = dataSource.getRepository(CardEntity);
const cardTextRepository = dataSource.getRepository(CardTextEntity);
const cardRepository = this.dataSource.getRepository(CardEntity);
const cardTextRepository = this.dataSource.getRepository(CardTextEntity);

const cardsCount = await cardRepository.count();
const cardTextsCount = await cardTextRepository.count();
Expand Down
11 changes: 8 additions & 3 deletions src/shared/db/postgres/infrastructure/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { DataSource, DataSourceOptions } from "typeorm";
import { CardEntity } from "../../../../edopro/card/infrastructure/postgres/CardEntity";
import { CardTextEntity } from "../../../../edopro/card/infrastructure/postgres/CardTextEntity";

const options: DataSourceOptions = {
const createDataSourceOptions = (databasePath: string): DataSourceOptions => ({
type: "sqlite",
database: "jtp_evolution_cards.db",
database: databasePath,
synchronize: true,
logging: false,
entities: [CardEntity, CardTextEntity],
subscribers: [],
migrations: [],
};
});

const options = createDataSourceOptions("jtp_evolution_cards.db");
const mercuryOptions = createDataSourceOptions("./mercury/pre-releases/cards.cdb");

export const dataSource = new DataSource(options);
export const mercuryDataSource = new DataSource(mercuryOptions);
Loading