Remove typeorm service (#14116)

## Context
To simplify the way we inject our default datasource, I've recently
removed the token injection that was confusion since we only had once
configured on the module level. Now I'm removing TypeORM service which
allows us to instantiate a new Datasource with the same parameters as
the default one, it was redundant and confusing.
This commit is contained in:
Weiko
2025-08-28 13:21:26 +02:00
committed by GitHub
parent f1706670f5
commit dec2239ae7
35 changed files with 240 additions and 399 deletions
@@ -1,8 +1,8 @@
import { Injectable } from '@nestjs/common';
import { InjectDataSource } from '@nestjs/typeorm';
import { type DataSource, type EntityManager } from 'typeorm';
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
import {
PermissionsException,
@@ -14,26 +14,10 @@ import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/ge
export class WorkspaceDataSourceService {
constructor(
private readonly dataSourceService: DataSourceService,
private readonly typeormService: TypeORMService,
@InjectDataSource()
private readonly coreDataSource: DataSource,
) {}
/**
*
* Connect to the workspace data source
*
* @param workspaceId
* @returns
*/
public async connectToMainDataSource(): Promise<DataSource> {
const dataSource = this.typeormService.getMainDataSource();
if (!dataSource) {
throw new Error(`Could not connect to workspace data source`);
}
return dataSource;
}
public async checkSchemaExists(workspaceId: string) {
const dataSource =
await this.dataSourceService.getDataSourcesMetadataFromWorkspaceId(
@@ -53,7 +37,13 @@ export class WorkspaceDataSourceService {
public async createWorkspaceDBSchema(workspaceId: string): Promise<string> {
const schemaName = getWorkspaceSchemaName(workspaceId);
return await this.typeormService.createSchema(schemaName);
const queryRunner = this.coreDataSource.createQueryRunner();
await queryRunner.createSchema(schemaName, true);
await queryRunner.release();
return schemaName;
}
/**
@@ -66,7 +56,11 @@ export class WorkspaceDataSourceService {
public async deleteWorkspaceDBSchema(workspaceId: string): Promise<void> {
const schemaName = getWorkspaceSchemaName(workspaceId);
return await this.typeormService.deleteSchema(schemaName);
const queryRunner = this.coreDataSource.createQueryRunner();
await queryRunner.dropSchema(schemaName, true);
await queryRunner.release();
}
public async executeRawQuery(