Working version before modification.
This commit is contained in:
+208
-1
@@ -129,7 +129,7 @@ CREATE TABLE IF NOT EXISTS reports (
|
||||
report_number VARCHAR(100) NOT NULL,
|
||||
template_code VARCHAR(100) NOT NULL,
|
||||
template_version INT NOT NULL,
|
||||
status ENUM('draft', 'in_progress', 'ready_for_export', 'exported', 'archived') NOT NULL DEFAULT 'draft',
|
||||
status ENUM('draft', 'final', 'in_progress', 'ready_for_export', 'exported', 'archived') NOT NULL DEFAULT 'draft',
|
||||
answers_json JSON NOT NULL,
|
||||
submitted_at DATETIME NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
@@ -155,3 +155,210 @@ CREATE TABLE IF NOT EXISTS audit_log (
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_audit_entity (entity_type, entity_code)
|
||||
);
|
||||
|
||||
-- Report images are stored as binary BLOBs in the database alongside metadata.
|
||||
-- This keeps image storage self-contained without filesystem dependencies.
|
||||
CREATE TABLE IF NOT EXISTS report_images (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
report_uuid CHAR(36) NOT NULL,
|
||||
record_id VARCHAR(100) NOT NULL,
|
||||
image_index SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
file_name VARCHAR(500) NOT NULL,
|
||||
file_size INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
mime_type VARCHAR(100) NOT NULL DEFAULT 'image/jpeg',
|
||||
width_px INT UNSIGNED NULL,
|
||||
height_px INT UNSIGNED NULL,
|
||||
exif_json JSON NULL,
|
||||
image_data LONGBLOB NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_report_images_report (report_uuid),
|
||||
KEY idx_report_images_record (report_uuid, record_id),
|
||||
CONSTRAINT fk_report_images_report
|
||||
FOREIGN KEY (report_uuid) REFERENCES reports (report_uuid)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- ═══════════════════════════════════════════════════════════════════════════════
|
||||
-- Admin entity tables — store all admin-managed data relationally so it
|
||||
-- persists across Docker restarts and browser sessions.
|
||||
-- ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
-- Categories for template settings (e.g. "Electrical", "Mechanical")
|
||||
CREATE TABLE IF NOT EXISTS admin_categories (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
value VARCHAR(200) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_admin_categories_value (value)
|
||||
);
|
||||
|
||||
-- Sub-categories are children of categories
|
||||
CREATE TABLE IF NOT EXISTS admin_sub_categories (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
value VARCHAR(200) NOT NULL,
|
||||
category_id BIGINT UNSIGNED NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_sub_categories_category (category_id),
|
||||
CONSTRAINT fk_sub_categories_category
|
||||
FOREIGN KEY (category_id) REFERENCES admin_categories (id)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Severity levels
|
||||
CREATE TABLE IF NOT EXISTS admin_severities (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
value VARCHAR(200) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_admin_severities_value (value)
|
||||
);
|
||||
|
||||
-- Status options
|
||||
CREATE TABLE IF NOT EXISTS admin_statuses (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
value VARCHAR(200) NOT NULL,
|
||||
require_handled_by TINYINT(1) NOT NULL DEFAULT 0,
|
||||
require_comment TINYINT(1) NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_admin_statuses_value (value)
|
||||
);
|
||||
|
||||
-- Handled By options
|
||||
CREATE TABLE IF NOT EXISTS admin_handled_by (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
value VARCHAR(200) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_admin_handled_by_value (value)
|
||||
);
|
||||
|
||||
-- Projects for task settings
|
||||
CREATE TABLE IF NOT EXISTS admin_projects (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
value VARCHAR(200) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_admin_projects_value (value)
|
||||
);
|
||||
|
||||
-- Processes are children of projects
|
||||
CREATE TABLE IF NOT EXISTS admin_processes (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
value VARCHAR(200) NOT NULL,
|
||||
project_id BIGINT UNSIGNED NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_processes_project (project_id),
|
||||
CONSTRAINT fk_processes_project
|
||||
FOREIGN KEY (project_id) REFERENCES admin_projects (id)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Users managed by the admin console
|
||||
CREATE TABLE IF NOT EXISTS admin_users (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
password_hash VARCHAR(255) NOT NULL DEFAULT '',
|
||||
name VARCHAR(200) NOT NULL,
|
||||
family_name VARCHAR(200) NOT NULL,
|
||||
company VARCHAR(200) NOT NULL DEFAULT '',
|
||||
role VARCHAR(50) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_admin_users_email (email)
|
||||
);
|
||||
|
||||
-- Sites managed by the admin console
|
||||
CREATE TABLE IF NOT EXISTS admin_sites (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
site_code VARCHAR(100) NOT NULL,
|
||||
host VARCHAR(50) NOT NULL DEFAULT '',
|
||||
obe_site_code VARCHAR(100) NOT NULL DEFAULT '',
|
||||
pxs_site_code VARCHAR(100) NOT NULL DEFAULT '',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_admin_sites_code (site_code)
|
||||
);
|
||||
|
||||
-- Check list records (inspection items)
|
||||
CREATE TABLE IF NOT EXISTS admin_cl_records (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
category VARCHAR(200) NOT NULL DEFAULT '',
|
||||
sub_category VARCHAR(200) NOT NULL DEFAULT '',
|
||||
severity VARCHAR(200) NOT NULL DEFAULT '',
|
||||
image_required TINYINT(1) NOT NULL DEFAULT 0,
|
||||
description_en TEXT NOT NULL,
|
||||
description_fr TEXT NOT NULL,
|
||||
description_nl TEXT NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_admin_cl_records_sort (sort_order)
|
||||
);
|
||||
|
||||
-- Check list templates
|
||||
CREATE TABLE IF NOT EXISTS admin_cl_templates (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
name VARCHAR(200) NOT NULL,
|
||||
scope VARCHAR(50) NOT NULL DEFAULT '',
|
||||
version VARCHAR(50) NOT NULL DEFAULT '',
|
||||
valid_from DATE NULL,
|
||||
valid_till DATE NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
-- Join table: which records belong to which template
|
||||
CREATE TABLE IF NOT EXISTS admin_cl_template_records (
|
||||
template_id BIGINT UNSIGNED NOT NULL,
|
||||
record_id BIGINT UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (template_id, record_id),
|
||||
CONSTRAINT fk_tpl_rec_template
|
||||
FOREIGN KEY (template_id) REFERENCES admin_cl_templates (id)
|
||||
ON DELETE CASCADE,
|
||||
CONSTRAINT fk_tpl_rec_record
|
||||
FOREIGN KEY (record_id) REFERENCES admin_cl_records (id)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Task assignments (user + site + template + project/process)
|
||||
CREATE TABLE IF NOT EXISTS admin_tasks (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
site_id BIGINT UNSIGNED NOT NULL,
|
||||
user_id BIGINT UNSIGNED NOT NULL,
|
||||
template_id BIGINT UNSIGNED NOT NULL,
|
||||
project VARCHAR(200) NOT NULL DEFAULT '',
|
||||
process VARCHAR(200) NOT NULL DEFAULT '',
|
||||
status VARCHAR(50) NOT NULL DEFAULT 'pending',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_tasks_user (user_id),
|
||||
KEY idx_tasks_site (site_id),
|
||||
CONSTRAINT fk_tasks_site
|
||||
FOREIGN KEY (site_id) REFERENCES admin_sites (id)
|
||||
ON DELETE CASCADE,
|
||||
CONSTRAINT fk_tasks_user
|
||||
FOREIGN KEY (user_id) REFERENCES admin_users (id)
|
||||
ON DELETE CASCADE,
|
||||
CONSTRAINT fk_tasks_template
|
||||
FOREIGN KEY (template_id) REFERENCES admin_cl_templates (id)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Admin credentials for application administrator login
|
||||
CREATE TABLE IF NOT EXISTS admin_credentials (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
username VARCHAR(100) NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_admin_credentials_username (username)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user