feat(database-credentials): add password update functionality for MariaDB, MongoDB, MySQL, Postgres, and Redis

- Introduced a new `UpdateDatabasePassword` component to facilitate password updates for database credentials.
- Implemented password change mutations in the respective API routers for MariaDB, MongoDB, MySQL, Postgres, and Redis.
- Enhanced user experience by providing success notifications upon successful password updates.
- Updated UI components to include the new password update functionality, ensuring consistency across different database types.
This commit is contained in:
Mauricio Siu
2026-04-04 00:18:19 -06:00
parent 987cb41bfc
commit 8001304e98
11 changed files with 480 additions and 7 deletions

View File

@@ -3,11 +3,14 @@ import {
createMount,
createPostgres,
deployPostgres,
execAsync,
execAsyncRemote,
findBackupsByDbId,
findEnvironmentById,
findPostgresById,
findProjectById,
getMountPath,
getServiceContainerCommand,
IS_CLOUD,
rebuildDatabase,
removePostgresById,
@@ -394,6 +397,49 @@ export const postgresRouter = createTRPCRouter({
resourceId: postgresId,
resourceName: service.appName,
});
return true;
}),
changePassword: protectedProcedure
.input(
z.object({
postgresId: z.string().min(1),
password: z.string().min(1),
}),
)
.mutation(async ({ input, ctx }) => {
const { postgresId, password } = input;
await checkServicePermissionAndAccess(ctx, postgresId, {
service: ["create"],
});
const pg = await findPostgresById(postgresId);
const { appName, serverId, databaseUser } = pg;
const containerCmd = getServiceContainerCommand(appName);
const command = `
CONTAINER_ID=$(${containerCmd})
if [ -z "$CONTAINER_ID" ]; then
echo "No running container found for ${appName}" >&2
exit 1
fi
docker exec "$CONTAINER_ID" psql -U ${databaseUser} -c "ALTER USER \\"${databaseUser}\\" WITH PASSWORD '${password}';"
`;
if (serverId) {
await execAsyncRemote(serverId, command);
} else {
await execAsync(command, { shell: "/bin/bash" });
}
await updatePostgresById(postgresId, { databasePassword: password });
await audit(ctx, {
action: "update",
resourceType: "service",
resourceId: postgresId,
resourceName: appName,
});
return true;
}),
move: protectedProcedure