This commit is contained in:
2026-06-25 14:43:13 -05:00
parent 6f77fac58e
commit aaa6a9ee26
25 changed files with 1542 additions and 67 deletions

View File

@@ -3,10 +3,11 @@ import { camelHost } from './mappers.js';
export function listHosts(userId) {
return db.prepare(`
SELECT h.*, c.name AS credential_name, g.name AS group_name
SELECT h.*, c.name AS credential_name, g.name AS group_name, vc.name AS source_connection_name
FROM hosts h
LEFT JOIN credentials c ON c.id = h.credential_id
LEFT JOIN groups g ON g.id = h.group_id
LEFT JOIN vcenter_connections vc ON vc.id = h.source_connection_id
WHERE ${visibleClause('h')}
ORDER BY h.name
`).all(userId, userId).map(camelHost);
@@ -20,8 +21,9 @@ export function createHost(payload, userId) {
const hostId = id('hst');
db.prepare(`
INSERT INTO hosts (id, name, fqdn, address, os_family, transport, port, credential_id, tags, notes,
visibility, owner_user_id, group_id, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
visibility, owner_user_id, group_id, source_type, source_connection_id, source_ref,
created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`).run(
hostId,
payload.name,
@@ -36,6 +38,9 @@ export function createHost(payload, userId) {
payload.visibility || 'shared',
userId,
scopedGroupId(payload),
payload.sourceType || 'manual',
payload.sourceConnectionId || null,
payload.sourceRef || '',
now(),
now()
);
@@ -69,7 +74,7 @@ export function updateHost(hostId, payload, userId) {
db.prepare(`
UPDATE hosts
SET name = ?, fqdn = ?, address = ?, os_family = ?, transport = ?, port = ?, credential_id = ?,
tags = ?, notes = ?, visibility = ?, group_id = ?, updated_at = ?
tags = ?, notes = ?, visibility = ?, group_id = ?, source_type = ?, source_connection_id = ?, source_ref = ?, updated_at = ?
WHERE id = ?
`).run(
payload.name || existing.name,
@@ -83,6 +88,9 @@ export function updateHost(hostId, payload, userId) {
payload.notes ?? existing.notes,
visibility,
visibility === 'group' ? (payload.groupId ?? existing.group_id) : null,
payload.sourceType ?? existing.source_type ?? 'manual',
payload.sourceConnectionId ?? existing.source_connection_id,
payload.sourceRef ?? existing.source_ref ?? '',
now(),
hostId
);