Finalize history admin tools and semantic UI navigation

This commit is contained in:
2026-02-23 16:59:09 +03:00
parent 4e8554f5f0
commit 8aa8b26184
43 changed files with 5543 additions and 270 deletions

View File

@@ -0,0 +1,23 @@
SET @sql = (
SELECT IF(
EXISTS(
SELECT 1 FROM information_schema.statistics
WHERE table_schema = DATABASE() AND table_name = 'installations' AND index_name = 'idx_installations_machine_slot_open'
),
'ALTER TABLE installations DROP INDEX idx_installations_machine_slot_open',
'SELECT 1'
)
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = (
SELECT IF(
EXISTS(
SELECT 1 FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'installations' AND column_name = 'slot_name'
),
'ALTER TABLE installations DROP COLUMN slot_name',
'SELECT 1'
)
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

View File

@@ -0,0 +1,4 @@
ALTER TABLE installations
ADD COLUMN slot_name VARCHAR(255) NULL;
CREATE INDEX idx_installations_machine_slot_open ON installations(machine_id, slot_name, removed_at);

View File

@@ -0,0 +1,23 @@
SET @sql = (
SELECT IF(
EXISTS(
SELECT 1 FROM information_schema.statistics
WHERE table_schema = DATABASE() AND table_name = 'parts' AND index_name = 'idx_parts_component_type'
),
'ALTER TABLE parts DROP INDEX idx_parts_component_type',
'SELECT 1'
)
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = (
SELECT IF(
EXISTS(
SELECT 1 FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'parts' AND column_name = 'component_type'
),
'ALTER TABLE parts DROP COLUMN component_type',
'SELECT 1'
)
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

View File

@@ -0,0 +1,36 @@
ALTER TABLE parts
ADD COLUMN component_type VARCHAR(128) NULL;
CREATE INDEX idx_parts_component_type ON parts(component_type);
UPDATE parts p
LEFT JOIN observations o ON o.id = (
SELECT o2.id
FROM observations o2
WHERE o2.part_id = p.id
AND JSON_EXTRACT(o2.details, '$.component_type') IS NOT NULL
ORDER BY o2.observed_at DESC, o2.created_at DESC, o2.id DESC
LIMIT 1
)
SET p.component_type = NULLIF(JSON_UNQUOTE(JSON_EXTRACT(o.details, '$.component_type')), '')
WHERE p.component_type IS NULL;
UPDATE installations i
LEFT JOIN observations o ON o.id = (
SELECT o2.id
FROM observations o2
WHERE o2.part_id = i.part_id
ORDER BY o2.observed_at DESC, o2.created_at DESC, o2.id DESC
LIMIT 1
)
SET i.slot_name = COALESCE(
i.slot_name,
NULLIF(JSON_UNQUOTE(JSON_EXTRACT(o.details, '$.slot')), ''),
NULLIF(JSON_UNQUOTE(JSON_EXTRACT(o.details, '$.attributes.location')), ''),
CASE
WHEN JSON_EXTRACT(o.details, '$.attributes.socket') IS NULL THEN NULL
ELSE CONCAT('Socket ', JSON_UNQUOTE(JSON_EXTRACT(o.details, '$.attributes.socket')))
END,
NULLIF(JSON_UNQUOTE(JSON_EXTRACT(o.details, '$.attributes.bdf')), '')
)
WHERE i.removed_at IS NULL AND (i.slot_name IS NULL OR i.slot_name = '');