fix: harden portable host installation

This commit is contained in:
Marco0300
2026-09-01 19:26:10 +02:00
parent 5b2c64ff39
commit 323afaf832
6 changed files with 37 additions and 24 deletions
+16 -16
View File
@@ -1,17 +1,17 @@
CREATE TABLE roles (
CREATE TABLE IF NOT EXISTS roles (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(80) NOT NULL UNIQUE,
description VARCHAR(255) NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;
CREATE TABLE permissions (
CREATE TABLE IF NOT EXISTS permissions (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(120) NOT NULL UNIQUE,
description VARCHAR(255) NULL
) ENGINE=InnoDB;
CREATE TABLE role_permissions (
CREATE TABLE IF NOT EXISTS role_permissions (
role_id BIGINT UNSIGNED NOT NULL,
permission_id BIGINT UNSIGNED NOT NULL,
PRIMARY KEY (role_id, permission_id),
@@ -19,7 +19,7 @@ CREATE TABLE role_permissions (
FOREIGN KEY (permission_id) REFERENCES permissions(id) ON DELETE CASCADE
) ENGINE=InnoDB;
CREATE TABLE users (
CREATE TABLE IF NOT EXISTS users (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
role_id BIGINT UNSIGNED NOT NULL,
email VARCHAR(190) NOT NULL UNIQUE,
@@ -32,7 +32,7 @@ CREATE TABLE users (
FOREIGN KEY (role_id) REFERENCES roles(id)
) ENGINE=InnoDB;
CREATE TABLE clients (
CREATE TABLE IF NOT EXISTS clients (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(190) NOT NULL,
registration_number VARCHAR(120) NULL,
@@ -51,7 +51,7 @@ CREATE TABLE clients (
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB;
CREATE TABLE client_contacts (
CREATE TABLE IF NOT EXISTS client_contacts (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
client_id BIGINT UNSIGNED NOT NULL,
name VARCHAR(120) NOT NULL,
@@ -65,7 +65,7 @@ CREATE TABLE client_contacts (
INDEX contacts_client_idx (client_id)
) ENGINE=InnoDB;
CREATE TABLE sla_agreements (
CREATE TABLE IF NOT EXISTS sla_agreements (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
client_id BIGINT UNSIGNED NOT NULL,
enabled BOOLEAN NOT NULL DEFAULT TRUE,
@@ -82,7 +82,7 @@ CREATE TABLE sla_agreements (
INDEX sla_client_idx (client_id)
) ENGINE=InnoDB;
CREATE TABLE jobcards (
CREATE TABLE IF NOT EXISTS jobcards (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
reference_no VARCHAR(40) NOT NULL UNIQUE,
client_id BIGINT UNSIGNED NOT NULL,
@@ -103,7 +103,7 @@ CREATE TABLE jobcards (
INDEX jobcards_created_idx (created_at)
) ENGINE=InnoDB;
CREATE TABLE jobcard_assignments (
CREATE TABLE IF NOT EXISTS jobcard_assignments (
jobcard_id BIGINT UNSIGNED NOT NULL,
user_id BIGINT UNSIGNED NOT NULL,
assigned_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -114,7 +114,7 @@ CREATE TABLE jobcard_assignments (
FOREIGN KEY (assigned_by) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB;
CREATE TABLE time_entries (
CREATE TABLE IF NOT EXISTS time_entries (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
jobcard_id BIGINT UNSIGNED NOT NULL,
technician_id BIGINT UNSIGNED NOT NULL,
@@ -134,7 +134,7 @@ CREATE TABLE time_entries (
INDEX time_date_idx (work_date)
) ENGINE=InnoDB;
CREATE TABLE audit_events (
CREATE TABLE IF NOT EXISTS audit_events (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT UNSIGNED NULL,
action VARCHAR(120) NOT NULL,
@@ -148,12 +148,12 @@ CREATE TABLE audit_events (
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB;
INSERT INTO roles (name, description) VALUES
INSERT IGNORE INTO roles (name, description) VALUES
('Administrator', 'Full system access'),
('Accounts', 'Client, jobcard and reporting access'),
('Technician', 'Assigned support work access');
INSERT INTO permissions (name, description) VALUES
INSERT IGNORE INTO permissions (name, description) VALUES
('dashboard.view', 'View the operational dashboard'),
('clients.view', 'View client records'),
('clients.manage', 'Create and edit client records'),
@@ -166,15 +166,15 @@ INSERT INTO permissions (name, description) VALUES
('audit.view', 'View audit events'),
('credentials.view', 'View protected credentials');
INSERT INTO role_permissions (role_id, permission_id)
INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id FROM roles r CROSS JOIN permissions p WHERE r.name = 'Administrator';
INSERT INTO role_permissions (role_id, permission_id)
INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id FROM roles r JOIN permissions p ON p.name IN
('dashboard.view','clients.view','jobcards.view','reports.view','reports.export')
WHERE r.name = 'Accounts';
INSERT INTO role_permissions (role_id, permission_id)
INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id FROM roles r JOIN permissions p ON p.name IN
('dashboard.view','clients.view','jobcards.view','jobcards.manage')
WHERE r.name = 'Technician';