diff --git a/backend/src/db/migrations/20250405185753_ssh-mgmt-v2.ts b/backend/src/db/migrations/20250405185753_ssh-mgmt-v2.ts index 3f7b4e2bf..560fca9b1 100644 --- a/backend/src/db/migrations/20250405185753_ssh-mgmt-v2.ts +++ b/backend/src/db/migrations/20250405185753_ssh-mgmt-v2.ts @@ -29,6 +29,7 @@ export async function up(knex: Knex): Promise { t.uuid("sshHostId").notNullable(); t.foreign("sshHostId").references("id").inTable(TableName.SshHost).onDelete("CASCADE"); t.string("loginUser").notNullable(); // e.g. ubuntu, root, ec2-user, ... + t.unique(["sshHostId", "loginUser"]); }); await createOnUpdateTrigger(knex, TableName.SshHostLoginUser); } @@ -41,6 +42,7 @@ export async function up(knex: Knex): Promise { t.foreign("sshHostLoginUserId").references("id").inTable(TableName.SshHostLoginUser).onDelete("CASCADE"); t.uuid("userId").nullable(); t.foreign("userId").references("id").inTable(TableName.Users).onDelete("CASCADE"); + t.unique(["sshHostLoginUserId", "userId"]); }); await createOnUpdateTrigger(knex, TableName.SshHostLoginUserMapping); } diff --git a/backend/src/ee/services/ssh-host/ssh-host-service.ts b/backend/src/ee/services/ssh-host/ssh-host-service.ts index 20d363957..69807431a 100644 --- a/backend/src/ee/services/ssh-host/ssh-host-service.ts +++ b/backend/src/ee/services/ssh-host/ssh-host-service.ts @@ -188,20 +188,6 @@ export const sshHostServiceFactory = ({ }); const newSshHost = await sshHostDAL.transaction(async (tx) => { - const existingHost = await sshHostDAL.findOne( - { - projectId, - hostname - }, - tx - ); - - if (existingHost) { - throw new BadRequestError({ - message: `SSH host with hostname ${hostname} already exists` - }); - } - const host = await sshHostDAL.create( { projectId,