Initial stage
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
CREATE DATABASE IF NOT EXISTS check_list CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
USE check_list;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS templates (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
code VARCHAR(100) NOT NULL,
|
||||
name VARCHAR(200) NOT NULL,
|
||||
description TEXT 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_templates_code (code)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS template_versions (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
template_id BIGINT UNSIGNED NOT NULL,
|
||||
version_number INT NOT NULL,
|
||||
status ENUM('draft', 'active', 'retired') NOT NULL DEFAULT 'draft',
|
||||
definition_json JSON NOT NULL,
|
||||
published_at DATETIME NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_template_version (template_id, version_number),
|
||||
KEY idx_template_versions_template_status (template_id, status),
|
||||
CONSTRAINT fk_template_versions_template
|
||||
FOREIGN KEY (template_id) REFERENCES templates (id)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS lookup_sets (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
code VARCHAR(100) NOT NULL,
|
||||
name VARCHAR(200) NOT NULL,
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_lookup_sets_code (code)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS lookup_values (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
lookup_set_id BIGINT UNSIGNED NOT NULL,
|
||||
value VARCHAR(100) NOT NULL,
|
||||
label VARCHAR(200) NOT NULL,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
is_default TINYINT(1) NOT NULL DEFAULT 0,
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_lookup_value (lookup_set_id, value),
|
||||
KEY idx_lookup_values_lookup_set (lookup_set_id),
|
||||
CONSTRAINT fk_lookup_values_lookup_set
|
||||
FOREIGN KEY (lookup_set_id) REFERENCES lookup_sets (id)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS image_rules (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
code VARCHAR(100) NOT NULL,
|
||||
name VARCHAR(200) NOT NULL,
|
||||
allowed_mime_types_json JSON NOT NULL,
|
||||
max_file_size_bytes INT UNSIGNED NOT NULL,
|
||||
max_width_px INT UNSIGNED NOT NULL,
|
||||
max_height_px INT UNSIGNED NOT NULL,
|
||||
jpeg_quality INT UNSIGNED NOT NULL,
|
||||
oversize_behavior ENUM('auto_optimize', 'warn_then_optimize', 'block') NOT NULL DEFAULT 'auto_optimize',
|
||||
max_attachments_per_field INT UNSIGNED NOT NULL DEFAULT 5,
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_image_rules_code (code)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS export_profiles (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
code VARCHAR(100) NOT NULL,
|
||||
name VARCHAR(200) NOT NULL,
|
||||
zip_image_dir VARCHAR(100) NOT NULL DEFAULT 'images',
|
||||
excel_sheet_name VARCHAR(100) NOT NULL DEFAULT 'Checklist',
|
||||
include_template_version TINYINT(1) NOT NULL DEFAULT 1,
|
||||
include_export_timestamp TINYINT(1) NOT NULL DEFAULT 1,
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_export_profiles_code (code)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS app_config (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
config_key VARCHAR(100) NOT NULL,
|
||||
config_value_json JSON 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_app_config_key (config_key)
|
||||
);
|
||||
@@ -0,0 +1,220 @@
|
||||
USE check_list;
|
||||
|
||||
INSERT INTO templates (code, name, description)
|
||||
VALUES (
|
||||
'incoming-inspection',
|
||||
'Incoming Inspection Checklist',
|
||||
'PoC template for supplier or incoming goods quality inspection.'
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
name = VALUES(name),
|
||||
description = VALUES(description);
|
||||
|
||||
SET @template_id = (SELECT id FROM templates WHERE code = 'incoming-inspection');
|
||||
|
||||
INSERT INTO template_versions (
|
||||
template_id,
|
||||
version_number,
|
||||
status,
|
||||
definition_json,
|
||||
published_at
|
||||
)
|
||||
VALUES (
|
||||
@template_id,
|
||||
1,
|
||||
'active',
|
||||
'{
|
||||
"templateId": "incoming-inspection",
|
||||
"templateName": "Incoming Inspection Checklist",
|
||||
"version": 1,
|
||||
"reportNumberPattern": "QC-{yyyy}-{seq:4}",
|
||||
"exportProfileCode": "default-report-export",
|
||||
"imageRuleCode": "standard-mobile-images",
|
||||
"sections": [
|
||||
{
|
||||
"id": "header",
|
||||
"title": "Report Header",
|
||||
"type": "group",
|
||||
"fields": [
|
||||
{
|
||||
"id": "reportNumber",
|
||||
"label": "Report Number",
|
||||
"type": "text",
|
||||
"required": true,
|
||||
"readOnly": false
|
||||
},
|
||||
{
|
||||
"id": "inspectionDate",
|
||||
"label": "Inspection Date",
|
||||
"type": "date",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"id": "supplierName",
|
||||
"label": "Supplier",
|
||||
"type": "text",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"id": "batchNumber",
|
||||
"label": "Batch Number",
|
||||
"type": "text",
|
||||
"required": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "check-items",
|
||||
"title": "Inspection Items",
|
||||
"type": "group",
|
||||
"fields": [
|
||||
{
|
||||
"id": "packagingCondition",
|
||||
"label": "Packaging Condition",
|
||||
"type": "lookup",
|
||||
"lookupCode": "pass-fail",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"id": "labelCheck",
|
||||
"label": "Label Verification",
|
||||
"type": "lookup",
|
||||
"lookupCode": "pass-fail",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"id": "quantityVerified",
|
||||
"label": "Quantity Verified",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"validation": {
|
||||
"min": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "damageFound",
|
||||
"label": "Visible Damage Found",
|
||||
"type": "checkbox",
|
||||
"required": false,
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"id": "damagePhoto",
|
||||
"label": "Damage Photo",
|
||||
"type": "attachment",
|
||||
"requiredWhen": {
|
||||
"field": "damageFound",
|
||||
"equals": true
|
||||
},
|
||||
"maxAttachments": 3
|
||||
},
|
||||
{
|
||||
"id": "inspectorComment",
|
||||
"label": "Inspector Comment",
|
||||
"type": "comment",
|
||||
"required": false,
|
||||
"maxLength": 1000
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}',
|
||||
NOW()
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
status = VALUES(status),
|
||||
definition_json = VALUES(definition_json),
|
||||
published_at = VALUES(published_at);
|
||||
|
||||
INSERT INTO lookup_sets (code, name)
|
||||
VALUES
|
||||
('pass-fail', 'Pass/Fail'),
|
||||
('draft-status', 'Draft Status')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
name = VALUES(name);
|
||||
|
||||
SET @pass_fail_id = (SELECT id FROM lookup_sets WHERE code = 'pass-fail');
|
||||
SET @draft_status_id = (SELECT id FROM lookup_sets WHERE code = 'draft-status');
|
||||
|
||||
INSERT INTO lookup_values (lookup_set_id, value, label, sort_order, is_default)
|
||||
VALUES
|
||||
(@pass_fail_id, 'pass', 'Pass', 1, 1),
|
||||
(@pass_fail_id, 'fail', 'Fail', 2, 0),
|
||||
(@draft_status_id, 'draft', 'Draft', 1, 1),
|
||||
(@draft_status_id, 'in_progress', 'In Progress', 2, 0),
|
||||
(@draft_status_id, 'ready_for_export', 'Ready for Export', 3, 0),
|
||||
(@draft_status_id, 'exported', 'Exported', 4, 0),
|
||||
(@draft_status_id, 'archived', 'Archived', 5, 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
label = VALUES(label),
|
||||
sort_order = VALUES(sort_order),
|
||||
is_default = VALUES(is_default);
|
||||
|
||||
INSERT INTO image_rules (
|
||||
code,
|
||||
name,
|
||||
allowed_mime_types_json,
|
||||
max_file_size_bytes,
|
||||
max_width_px,
|
||||
max_height_px,
|
||||
jpeg_quality,
|
||||
oversize_behavior,
|
||||
max_attachments_per_field,
|
||||
is_active
|
||||
)
|
||||
VALUES (
|
||||
'standard-mobile-images',
|
||||
'Standard Mobile Image Policy',
|
||||
'["image/jpeg", "image/png", "image/webp"]',
|
||||
5242880,
|
||||
1920,
|
||||
1920,
|
||||
82,
|
||||
'auto_optimize',
|
||||
5,
|
||||
1
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
name = VALUES(name),
|
||||
allowed_mime_types_json = VALUES(allowed_mime_types_json),
|
||||
max_file_size_bytes = VALUES(max_file_size_bytes),
|
||||
max_width_px = VALUES(max_width_px),
|
||||
max_height_px = VALUES(max_height_px),
|
||||
jpeg_quality = VALUES(jpeg_quality),
|
||||
oversize_behavior = VALUES(oversize_behavior),
|
||||
max_attachments_per_field = VALUES(max_attachments_per_field),
|
||||
is_active = VALUES(is_active);
|
||||
|
||||
INSERT INTO export_profiles (
|
||||
code,
|
||||
name,
|
||||
zip_image_dir,
|
||||
excel_sheet_name,
|
||||
include_template_version,
|
||||
include_export_timestamp,
|
||||
is_active
|
||||
)
|
||||
VALUES (
|
||||
'default-report-export',
|
||||
'Default Report Export',
|
||||
'images',
|
||||
'Checklist',
|
||||
1,
|
||||
1,
|
||||
1
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
name = VALUES(name),
|
||||
zip_image_dir = VALUES(zip_image_dir),
|
||||
excel_sheet_name = VALUES(excel_sheet_name),
|
||||
include_template_version = VALUES(include_template_version),
|
||||
include_export_timestamp = VALUES(include_export_timestamp),
|
||||
is_active = VALUES(is_active);
|
||||
|
||||
INSERT INTO app_config (config_key, config_value_json)
|
||||
VALUES
|
||||
('autosave', '{"enabled": true, "intervalSeconds": 20}'),
|
||||
('offlineCache', '{"templateTtlHours": 24, "refreshOnStartup": true}'),
|
||||
('reportStatuses', '["draft", "in_progress", "ready_for_export", "exported", "archived"]')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
config_value_json = VALUES(config_value_json);
|
||||
Reference in New Issue
Block a user