Fix sign up broken because of missing workspace schema (#6013)
Allow workspace datasource factory to return null if the workspace schema has not been created yet
This commit is contained in:
@ -46,6 +46,15 @@ export class DataSourceService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getLastDataSourceMetadataFromWorkspaceId(
|
||||||
|
workspaceId: string,
|
||||||
|
): Promise<DataSourceEntity | null> {
|
||||||
|
return this.dataSourceMetadataRepository.findOne({
|
||||||
|
where: { workspaceId },
|
||||||
|
order: { createdAt: 'DESC' },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async getLastDataSourceMetadataFromWorkspaceIdOrFail(
|
async getLastDataSourceMetadataFromWorkspaceIdOrFail(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
): Promise<DataSourceEntity> {
|
): Promise<DataSourceEntity> {
|
||||||
|
|||||||
@ -14,7 +14,10 @@ export class WorkspaceDatasourceFactory {
|
|||||||
private readonly environmentService: EnvironmentService,
|
private readonly environmentService: EnvironmentService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public async create(entities: EntitySchema[], workspaceId: string) {
|
public async create(
|
||||||
|
entities: EntitySchema[],
|
||||||
|
workspaceId: string,
|
||||||
|
): Promise<WorkspaceDataSource | null> {
|
||||||
const storedWorkspaceDataSource =
|
const storedWorkspaceDataSource =
|
||||||
DataSourceStorage.getDataSource(workspaceId);
|
DataSourceStorage.getDataSource(workspaceId);
|
||||||
|
|
||||||
@ -23,10 +26,14 @@ export class WorkspaceDatasourceFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dataSourceMetadata =
|
const dataSourceMetadata =
|
||||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceIdOrFail(
|
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceId(
|
||||||
workspaceId,
|
workspaceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!dataSourceMetadata) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const workspaceDataSource = new WorkspaceDataSource({
|
const workspaceDataSource = new WorkspaceDataSource({
|
||||||
url:
|
url:
|
||||||
dataSourceMetadata.url ??
|
dataSourceMetadata.url ??
|
||||||
|
|||||||
@ -35,6 +35,11 @@ export class TwentyORMManager {
|
|||||||
entities,
|
entities,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!workspaceDataSource) {
|
||||||
|
throw new Error('Workspace data source not found');
|
||||||
|
}
|
||||||
|
|
||||||
const entitySchema = this.entitySchemaFactory.create(entityClass);
|
const entitySchema = this.entitySchemaFactory.create(entityClass);
|
||||||
|
|
||||||
return workspaceDataSource.getRepository<T>(entitySchema);
|
return workspaceDataSource.getRepository<T>(entitySchema);
|
||||||
|
|||||||
Reference in New Issue
Block a user