Some database improvements and associated changes in webgui

This commit is contained in:
2026-09-14 10:12:32 +02:00
parent 2250fb9743
commit 57c42d1398
23 changed files with 203 additions and 39 deletions
+72 -27
View File
@@ -3,10 +3,12 @@
/* MariaDB Scheme
Version: 1 */
/* TODO
/* REMARKS
- there are by design no created_at, updated_at, updates_by or similar fields
TODO
- check all values if unsigned can be used or not
- implement foreign keys where missing and possible
- add referential actions where appropriate
- add referential actions where appropriate
- rename provisions to provision(?)
- review defaults
*/
@@ -66,6 +68,7 @@ CREATE TABLE dropdown (
PRIMARY KEY (ddid, ddval)
) ENGINE=InnoDB;
/* compid is signed because negative values needed for special purpose */
CREATE TABLE company (
compid smallint(6) NOT NULL AUTO_INCREMENT,
compname varchar(60) NOT NULL,
@@ -110,6 +113,7 @@ CREATE TABLE vessel (
PRIMARY KEY (vid),
FOREIGN KEY fk_vessel_shipyard (shipyard)
REFERENCES company(compid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
CREATE TABLE storage (
@@ -131,13 +135,15 @@ CREATE TABLE storage (
PRIMARY KEY (sid),
FOREIGN KEY fk_storage_vessel (vid)
REFERENCES vessel(vid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
/* intentionally after storage creation */
ALTER TABLE vessel
ADD CONSTRAINT fk_vessel_storage
FOREIGN KEY (sid_default)
REFERENCES storage(sid);
REFERENCES storage(sid)
ON DELETE RESTRICT;
CREATE TABLE tag (
tagid smallint(6) UNSIGNED NOT NULL AUTO_INCREMENT,
@@ -153,13 +159,14 @@ CREATE TABLE tagref (
objid int(10) UNSIGNED NOT NULL,
objtype enum('equip','inv','prov','doc', 'proj', 'task', 'maint') NOT NULL,
PRIMARY KEY (tagid, objid, objtype),
INDEX ix_tagref_obj (objid, objtype),
FOREIGN KEY fk_tagref_tag (tagid)
REFERENCES tag(tagid)
ON DELETE CASCADE
) ENGINE=InnoDB;
/* TODO Boxes can be nested via parent
TODO boxsize: (LxWxH) in cm? */
/* TODO Boxes can be nested via parent,
very low priority because perhaps rarely used */
CREATE TABLE box (
boxid smallint(6) UNSIGNED NOT NULL AUTO_INCREMENT,
sid smallint(6) UNSIGNED NOT NULL,
@@ -169,11 +176,18 @@ CREATE TABLE box (
color char(6) DEFAULT NULL,
content varchar(60) DEFAULT NULL,
weight float(5,2) UNSIGNED DEFAULT NULL,
wx smallint(6) UNSIGNED NOT NULL DEFAULT 0,
wy smallint(6) UNSIGNED NOT NULL DEFAULT 0,
wz smallint(6) UNSIGNED NOT NULL DEFAULT 0,
remarks varchar(150) DEFAULT NULL,
PRIMARY KEY (boxid),
INDEX ix_label (label),
FOREIGN KEY fk_box_storage (sid)
REFERENCES storage(sid)
ON DELETE RESTRICT,
FOREIGN KEY fk_box_parent (parent)
REFERENCES box(boxid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
CREATE TABLE equipment (
@@ -196,6 +210,9 @@ CREATE TABLE equipment (
REFERENCES vessel(vid)
ON DELETE RESTRICT,
FOREIGN KEY fk_equipment_supplier (supplier)
REFERENCES company(compid)
ON DELETE RESTRICT,
FOREIGN KEY fk_equipment_manufacturer (manufacturer)
REFERENCES company(compid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
@@ -206,7 +223,7 @@ CREATE TABLE inventory (
conttype enum('storage','box') NOT NULL DEFAULT 'storage',
sid smallint(6) UNSIGNED DEFAULT NULL,
boxid smallint(6) UNSIGNED DEFAULT NULL,
eid smallint(6) UNSIGNED DEFAULT NULL,
eid smallint(6) UNSIGNED DEFAULT NULL, -- spare part reference to equipment
number smallint(6) UNSIGNED NOT NULL DEFAULT 1,
weight float(5,2) UNSIGNED DEFAULT NULL,
price decimal(12,2) DEFAULT NULL,
@@ -217,11 +234,14 @@ CREATE TABLE inventory (
PRIMARY KEY (invid),
INDEX ix_invname (invname),
FOREIGN KEY fk_inventory_storage (sid)
REFERENCES storage(sid),
REFERENCES storage(sid)
ON DELETE RESTRICT,
FOREIGN KEY fk_inventory_box (boxid)
REFERENCES box(boxid),
REFERENCES box(boxid)
ON DELETE RESTRICT,
FOREIGN KEY fk_inventory_equipment (eid)
REFERENCES equipment(eid),
REFERENCES equipment(eid)
ON DELETE RESTRICT,
CHECK (
(sid IS NOT NULL AND boxid IS NULL)
OR
@@ -248,11 +268,14 @@ CREATE TABLE cable (
PRIMARY KEY (cableid),
INDEX ix_cablename (vid, cablename),
FOREIGN KEY fk_cable_vessel (vid)
REFERENCES vessel(vid),
REFERENCES vessel(vid)
ON DELETE RESTRICT,
FOREIGN KEY fk_cable_supplier (supplier)
REFERENCES company(compid),
REFERENCES company(compid)
ON DELETE RESTRICT,
FOREIGN KEY fk_cable_manufacturer (manufacturer)
REFERENCES company(compid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
CREATE table fuse (
@@ -269,11 +292,14 @@ CREATE table fuse (
PRIMARY KEY (fuseid),
UNIQUE INDEX ix_fusenumber (vid, fnumber),
FOREIGN KEY fk_fuse_vessel (vid)
REFERENCES vessel(vid),
REFERENCES vessel(vid)
ON DELETE RESTRICT,
FOREIGN KEY fk_fuse_cable (cableid)
REFERENCES cable(cableid),
REFERENCES cable(cableid)
ON DELETE RESTRICT,
FOREIGN KEY fk_fuse_equipment (eid)
REFERENCES equipment(eid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
-- change vals to decimal(12,4)?
@@ -292,9 +318,11 @@ CREATE TABLE measurement (
note varchar(80) DEFAULT NULL,
PRIMARY KEY (mid),
FOREIGN KEY fk_measurement_vessel (vid)
REFERENCES vessel(vid),
REFERENCES vessel(vid)
ON DELETE RESTRICT,
FOREIGN KEY fk_measurement_equipment (eid)
REFERENCES equipment(eid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
CREATE TABLE provisions (
@@ -315,9 +343,11 @@ CREATE TABLE provisions (
remarks varchar(150) DEFAULT NULL,
PRIMARY KEY (provid),
FOREIGN KEY fk_provisions_storage (sid)
REFERENCES storage(sid),
REFERENCES storage(sid)
ON DELETE RESTRICT,
FOREIGN KEY fk_provisions_box (boxid)
REFERENCES box(boxid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
/* TODO
@@ -345,19 +375,19 @@ CREATE TABLE document (
CREATE TABLE docref (
drid int(10) NOT NULL AUTO_INCREMENT,
reftype enum('vessel','box','equipment','project','task','user','company') NOT NULL DEFAULT 'vessel',
reftype enum('vessel','box','equipment','project','maint', 'task','user','company') NOT NULL DEFAULT 'vessel',
docid smallint(6) NOT NULL,
refid int(10) NOT NULL,
PRIMARY KEY (drid),
UNIQUE INDEX ix_docref (docid, refid, reftype),
INDEX ix_docref_ref (refid, reftype),
FOREIGN KEY fk_docref_doc (docid)
REFERENCES document (docid)
ON DELETE RESTRICT
ON UPDATE CASCADE
ON DELETE CASCADE
) ENGINE=InnoDB;
/* TODO optional fields: plan date, target date, completion date
interval_hours, last_hours
/* TODO optional fields: target date?
responsible?
signalk: operating hours current vs maint every n operating hours in separate
*/
CREATE TABLE maintenance (
@@ -374,13 +404,14 @@ CREATE TABLE maintenance (
maintstate enum('new','plan','ongoing','done') NOT NULL DEFAULT 'new',
PRIMARY KEY (maintid),
FOREIGN KEY fk_maintenance_vessel (vid)
REFERENCES vessel(vid),
REFERENCES vessel(vid)
ON DELETE RESTRICT,
FOREIGN KEY fk_maintenance_equipment (eid)
REFERENCES equipment(eid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
/* TODO? time recording */
/* TODO time recording? */
CREATE TABLE project (
projid smallint(6) NOT NULL AUTO_INCREMENT,
projname varchar(40) NOT NULL,
@@ -394,9 +425,11 @@ CREATE TABLE project (
projstate enum('new','plan','ongoing','paused','finished') NOT NULL DEFAULT 'new',
PRIMARY KEY (projid),
FOREIGN KEY fk_project_vessel (vid)
REFERENCES vessel(vid),
REFERENCES vessel(vid)
ON DELETE RESTRICT,
FOREIGN KEY fk_project_user (responsible)
REFERENCES user(userid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
/* TODO executed_by : company or user? or both? */
@@ -413,13 +446,17 @@ CREATE TABLE task (
started datetime DEFAULT NULL,
finished datetime DEFAULT NULL,
responsible smallint(6) NOT NULL,
remarks varchar(150) DEFAULT NULL,
PRIMARY KEY (taskid),
FOREIGN KEY fk_task_user (responsible)
REFERENCES user(userid),
REFERENCES user(userid)
ON DELETE RESTRICT,
FOREIGN KEY fk_task_vessel (vid)
REFERENCES vessel(vid),
REFERENCES vessel(vid)
ON DELETE RESTRICT,
FOREIGN KEY fk_task_project (projid)
REFERENCES project(projid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
/* Notes can be assigned to tasks, maintenances and equipment */
@@ -428,7 +465,12 @@ CREATE TABLE note (
notetype enum('task','maint','equip') NOT NULL DEFAULT 'task',
refid int(10) NOT NULL,
annotation text NOT NULL,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
created_by smallint(6) DEFAULT NULL,
PRIMARY KEY (noteid)
FOREIGN KEY fk_note_user (created_by)
REFERENCES user(userid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
CREATE TABLE checklist (
@@ -439,6 +481,7 @@ CREATE TABLE checklist (
PRIMARY KEY (clid),
FOREIGN KEY fk_checklist_parent (parent)
REFERENCES checklist(clid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
CREATE TABLE checkgroup (
@@ -455,6 +498,7 @@ CREATE TABLE checkitem (
PRIMARY KEY (checkid),
FOREIGN KEY fk_checkitem_group (groupid)
REFERENCES checkgroup(groupid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
CREATE TABLE checkref (
@@ -483,6 +527,7 @@ CREATE TABLE signalk (
(vid, objtype, objid, datatype),
FOREIGN KEY fk_signalk_vessel (vid)
REFERENCES vessel(vid)
ON DELETE RESTRICT
) ENGINE=InnoDB;
/* Token