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

Fix sign up broken because of missing workspace schema #6013

Merged
merged 1 commit into from
Jun 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
workspaceId: string,
): Promise<DataSourceEntity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export class WorkspaceDatasourceFactory {
private readonly environmentService: EnvironmentService,
) {}

public async create(entities: EntitySchema[], workspaceId: string) {
public async create(
entities: EntitySchema[],
workspaceId: string,
): Promise<WorkspaceDataSource | null> {
const storedWorkspaceDataSource =
DataSourceStorage.getDataSource(workspaceId);

Expand All @@ -23,10 +26,14 @@ export class WorkspaceDatasourceFactory {
}

const dataSourceMetadata =
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceIdOrFail(
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceId(
workspaceId,
);

if (!dataSourceMetadata) {
return null;
}

const workspaceDataSource = new WorkspaceDataSource({
url:
dataSourceMetadata.url ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export class TwentyORMManager {
entities,
workspaceId,
);

if (!workspaceDataSource) {
throw new Error('Workspace data source not found');
}

const entitySchema = this.entitySchemaFactory.create(entityClass);

return workspaceDataSource.getRepository<T>(entitySchema);
Expand Down
Loading