Files
CableGUI/internal/db/migrations/004_setup_templates.sql
mAi c206a331ec rename: mCables → CableGUI (project + repo + image + paths)
Full project rename per m's call. Single atomic commit because the
codebase rename is a coupled change — go module path, env vars, DB
default, Docker artefact names, and on-disk mDock paths all flip
together.

- go.mod: module mgit.msbls.de/m/mcables → mgit.msbls.de/m/cablegui
- cmd/mcables → cmd/cablegui (git mv)
- All Go imports rewritten to the new module path
- Env vars: MCABLES_ADDR/MCABLES_DB → CABLEGUI_ADDR/CABLEGUI_DB
- DB default path: data/mcables.db → data/cablegui.db
- Dockerfile + docker-compose.yml: image, container_name, env vars,
  bind-mount /home/m/stacks/mcables → /home/m/stacks/cablegui,
  secrets /home/m/secrets/mcables → /home/m/secrets/cablegui
- Makefile: bin target + run/build commands point at cmd/cablegui
- .gitignore + .dockerignore: /mcables → /cablegui
- README, docs/design.md, CLAUDE.md: prose + paths + image name
- web/static/index.html: <title> + brand
- web/static/main.js + web/web.go: header comment
- internal/exporter: Scene.Source "mcables" → "cablegui"
- internal/server/export.go: error-detail secrets path
- internal/db/migrations/*.sql: header comments (mCables vN → CableGUI vN)

Memory group_id kept as "mcables" to preserve existing memory continuity.
Documented as historical in CLAUDE.md.

go build ./... clean; go test -race ./... green
2026-05-16 15:35:42 +02:00

158 lines
8.9 KiB
SQL

-- CableGUI v4.1 setup templates. See docs/design.md §2.4.
--
-- A template is a named recipe of (device_types + requirements) that
-- bootstraps a project from blank to solver-ready in one apply call.
CREATE TABLE setup_templates (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
description TEXT NOT NULL DEFAULT '',
built_in INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE TABLE setup_template_devices (
id INTEGER PRIMARY KEY,
template_id INTEGER NOT NULL REFERENCES setup_templates(id) ON DELETE CASCADE,
device_type_id INTEGER NOT NULL REFERENCES device_types(id) ON DELETE RESTRICT,
suggested_name TEXT,
sort_order INTEGER NOT NULL DEFAULT 0
);
CREATE INDEX setup_template_devices_template_idx ON setup_template_devices(template_id);
CREATE TABLE setup_template_requirements (
id INTEGER PRIMARY KEY,
template_id INTEGER NOT NULL REFERENCES setup_templates(id) ON DELETE CASCADE,
from_template_device_id INTEGER NOT NULL REFERENCES setup_template_devices(id) ON DELETE CASCADE,
to_template_device_id INTEGER NOT NULL REFERENCES setup_template_devices(id) ON DELETE CASCADE,
preferred_cable_type_id INTEGER REFERENCES cable_types(id) ON DELETE SET NULL,
must_connect INTEGER NOT NULL DEFAULT 1 CHECK (must_connect IN (0, 1)),
CHECK (from_template_device_id != to_template_device_id)
);
CREATE INDEX setup_template_reqs_template_idx ON setup_template_requirements(template_id);
-- ---------------------------------------------------------------- Living Room
INSERT INTO setup_templates (name, description, built_in)
VALUES ('Living Room', 'TV + Soundbar + ChromeCast, HDMI between them.', 1);
INSERT INTO setup_template_devices (template_id, device_type_id, suggested_name, sort_order)
SELECT
(SELECT id FROM setup_templates WHERE name='Living Room'),
(SELECT id FROM device_types WHERE name='TV' AND project_id IS NULL),
'TV', 0;
INSERT INTO setup_template_devices (template_id, device_type_id, suggested_name, sort_order)
SELECT
(SELECT id FROM setup_templates WHERE name='Living Room'),
(SELECT id FROM device_types WHERE name='Soundbar' AND project_id IS NULL),
'Soundbar', 1;
INSERT INTO setup_template_devices (template_id, device_type_id, suggested_name, sort_order)
SELECT
(SELECT id FROM setup_templates WHERE name='Living Room'),
(SELECT id FROM device_types WHERE name='ChromeCast' AND project_id IS NULL),
'ChromeCast', 2;
-- TV ↔ Soundbar (HDMI, must)
INSERT INTO setup_template_requirements
(template_id, from_template_device_id, to_template_device_id, preferred_cable_type_id, must_connect)
SELECT
(SELECT id FROM setup_templates WHERE name='Living Room'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Living Room') AND suggested_name='TV'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Living Room') AND suggested_name='Soundbar'),
3, 1;
-- TV ↔ ChromeCast (HDMI, must)
INSERT INTO setup_template_requirements
(template_id, from_template_device_id, to_template_device_id, preferred_cable_type_id, must_connect)
SELECT
(SELECT id FROM setup_templates WHERE name='Living Room'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Living Room') AND suggested_name='TV'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Living Room') AND suggested_name='ChromeCast'),
3, 1;
-- ---------------------------------------------------------------- Home Office
INSERT INTO setup_templates (name, description, built_in)
VALUES ('Home Office', 'PC + Screen + Keyboard + Mouse. HDMI + USB.', 1);
INSERT INTO setup_template_devices (template_id, device_type_id, suggested_name, sort_order)
SELECT
(SELECT id FROM setup_templates WHERE name='Home Office'),
(SELECT id FROM device_types WHERE name='PC' AND project_id IS NULL),
'PC', 0;
INSERT INTO setup_template_devices (template_id, device_type_id, suggested_name, sort_order)
SELECT
(SELECT id FROM setup_templates WHERE name='Home Office'),
(SELECT id FROM device_types WHERE name='Screen' AND project_id IS NULL),
'Screen', 1;
INSERT INTO setup_template_devices (template_id, device_type_id, suggested_name, sort_order)
SELECT
(SELECT id FROM setup_templates WHERE name='Home Office'),
(SELECT id FROM device_types WHERE name='Keyboard' AND project_id IS NULL),
'Keyboard', 2;
INSERT INTO setup_template_devices (template_id, device_type_id, suggested_name, sort_order)
SELECT
(SELECT id FROM setup_templates WHERE name='Home Office'),
(SELECT id FROM device_types WHERE name='Mouse' AND project_id IS NULL),
'Mouse', 3;
-- PC ↔ Screen (HDMI, must)
INSERT INTO setup_template_requirements
(template_id, from_template_device_id, to_template_device_id, preferred_cable_type_id, must_connect)
SELECT
(SELECT id FROM setup_templates WHERE name='Home Office'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Home Office') AND suggested_name='PC'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Home Office') AND suggested_name='Screen'),
3, 1;
-- PC ↔ Keyboard (USB, must)
INSERT INTO setup_template_requirements
(template_id, from_template_device_id, to_template_device_id, preferred_cable_type_id, must_connect)
SELECT
(SELECT id FROM setup_templates WHERE name='Home Office'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Home Office') AND suggested_name='PC'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Home Office') AND suggested_name='Keyboard'),
2, 1;
-- PC ↔ Mouse (USB, must)
INSERT INTO setup_template_requirements
(template_id, from_template_device_id, to_template_device_id, preferred_cable_type_id, must_connect)
SELECT
(SELECT id FROM setup_templates WHERE name='Home Office'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Home Office') AND suggested_name='PC'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Home Office') AND suggested_name='Mouse'),
2, 1;
-- ---------------------------------------------------------------- Server Rack
INSERT INTO setup_templates (name, description, built_in)
VALUES ('Server Rack', 'NAS + Switch + fritz. Ethernet trunk + power.', 1);
INSERT INTO setup_template_devices (template_id, device_type_id, suggested_name, sort_order)
SELECT
(SELECT id FROM setup_templates WHERE name='Server Rack'),
(SELECT id FROM device_types WHERE name='NAS' AND project_id IS NULL),
'NAS', 0;
INSERT INTO setup_template_devices (template_id, device_type_id, suggested_name, sort_order)
SELECT
(SELECT id FROM setup_templates WHERE name='Server Rack'),
(SELECT id FROM device_types WHERE name='Switch' AND project_id IS NULL),
'Switch', 1;
INSERT INTO setup_template_devices (template_id, device_type_id, suggested_name, sort_order)
SELECT
(SELECT id FROM setup_templates WHERE name='Server Rack'),
(SELECT id FROM device_types WHERE name='fritz' AND project_id IS NULL),
'fritz', 2;
-- NAS ↔ Switch (RJ45, must)
INSERT INTO setup_template_requirements
(template_id, from_template_device_id, to_template_device_id, preferred_cable_type_id, must_connect)
SELECT
(SELECT id FROM setup_templates WHERE name='Server Rack'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Server Rack') AND suggested_name='NAS'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Server Rack') AND suggested_name='Switch'),
5, 1;
-- Switch ↔ fritz (RJ45, must)
INSERT INTO setup_template_requirements
(template_id, from_template_device_id, to_template_device_id, preferred_cable_type_id, must_connect)
SELECT
(SELECT id FROM setup_templates WHERE name='Server Rack'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Server Rack') AND suggested_name='Switch'),
(SELECT id FROM setup_template_devices WHERE template_id = (SELECT id FROM setup_templates WHERE name='Server Rack') AND suggested_name='fritz'),
5, 1;