Skip to content

add hostedDatabaseId to CreateConnectionForHostedDbDto and update use case implementation#1701

Merged
Artuomka merged 1 commit into
mainfrom
backend_created_db_sync
Apr 3, 2026
Merged

add hostedDatabaseId to CreateConnectionForHostedDbDto and update use case implementation#1701
Artuomka merged 1 commit into
mainfrom
backend_created_db_sync

Conversation

@Artuomka

@Artuomka Artuomka commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings April 3, 2026 09:56
@Artuomka Artuomka merged commit 1230ce8 into main Apr 3, 2026
16 of 18 checks passed
@Artuomka Artuomka deleted the backend_created_db_sync branch April 3, 2026 09:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the SaaS “create hosted DB connection” flow to accept an externally supplied identifier and use it as the persisted connection primary key, enabling stable mapping between the hosted DB entity and the created ConnectionEntity.

Changes:

  • Added hostedDatabaseId to CreateConnectionForHostedDbDto.
  • Updated CreateConnectionForHostedDbUseCase to read hostedDatabaseId and assign it to connection.id before persisting.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
backend/src/microservices/saas-microservice/use-cases/create-connection-for-hosted-db.use.case.ts Uses hostedDatabaseId from input as the saved ConnectionEntity.id.
backend/src/microservices/saas-microservice/data-structures/create-connecttion-for-selfhosted-db.dto.ts Extends the hosted-DB create DTO with a required hostedDatabaseId field.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 65 to 67
const connection = new ConnectionEntity();
connection.id = hostedDatabaseId;
connection.type = ConnectionTypesEnum.postgres;

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting connection.id from untrusted request data and then calling connectionRepository.saveNewConnection() (which uses TypeORM save) can turn this "create" endpoint into an implicit update: if a connection with the same id already exists, TypeORM will update that row instead of failing. This can lead to accidental overwrites/collisions and potentially cross-company data corruption. Add an explicit uniqueness check (e.g., query by id and throw a Conflict/BadRequest if it exists) or use an insert-only repository method that fails on duplicate ids; alternatively persist hostedDatabaseId in a dedicated column instead of overriding the primary key.

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +68
@ApiProperty()
@IsString()
@IsNotEmpty()
hostedDatabaseId: string;

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hostedDatabaseId is persisted as ConnectionEntity.id, which is a varchar with length 38 (ConnectionEntity uses @PrimaryColumn('varchar', { length: 38 })). The DTO currently only validates non-empty string, so oversized values can cause DB errors. Add an explicit length constraint (e.g., @MaxLength(38) / @Length(...)) and document the expected format in @ApiProperty (description/example), so callers know what to send.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants