Add unique constraints for ssh login user and login user mapping tables

This commit is contained in:
Tuan Dang
2025-04-11 00:52:50 -07:00
parent 5c40347c52
commit 9e0fdb10b1
2 changed files with 2 additions and 14 deletions

View File

@@ -29,6 +29,7 @@ export async function up(knex: Knex): Promise<void> {
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<void> {
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);
}

View File

@@ -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,