<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Create Service Checklist module tables.
*/
final class Version20260203100001 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create Service Checklist module tables: templates, checklists, sections, items, and defects';
}
public function up(Schema $schema): void
{
// Template tables
$this->addSql('
CREATE TABLE service_checklist_template (
id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(255) NOT NULL,
checklist_type VARCHAR(20) NOT NULL,
asset_type VARCHAR(100) DEFAULT NULL,
description LONGTEXT DEFAULT NULL,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
deleted_at DATETIME DEFAULT NULL,
UNIQUE INDEX UNIQ_template_type_asset (checklist_type, asset_type),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
');
$this->addSql('
CREATE TABLE service_checklist_template_section (
id INT AUTO_INCREMENT NOT NULL,
template_id INT DEFAULT NULL,
name VARCHAR(255) NOT NULL,
sort_order INT NOT NULL DEFAULT 0,
INDEX IDX_template_section_template (template_id),
PRIMARY KEY(id),
CONSTRAINT FK_template_section_template FOREIGN KEY (template_id)
REFERENCES service_checklist_template (id) ON DELETE CASCADE
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
');
$this->addSql('
CREATE TABLE service_checklist_template_item (
id INT AUTO_INCREMENT NOT NULL,
section_id INT DEFAULT NULL,
name VARCHAR(500) NOT NULL,
item_type VARCHAR(20) NOT NULL DEFAULT \'inspection\',
service_level VARCHAR(10) NOT NULL DEFAULT \'both\',
sort_order INT NOT NULL DEFAULT 0,
is_mandatory TINYINT(1) NOT NULL DEFAULT 0,
requires_photo TINYINT(1) NOT NULL DEFAULT 0,
requires_note TINYINT(1) NOT NULL DEFAULT 0,
min_value DECIMAL(10,2) DEFAULT NULL,
max_value DECIMAL(10,2) DEFAULT NULL,
unit VARCHAR(20) DEFAULT NULL,
INDEX IDX_template_item_section (section_id),
PRIMARY KEY(id),
CONSTRAINT FK_template_item_section FOREIGN KEY (section_id)
REFERENCES service_checklist_template_section (id) ON DELETE CASCADE
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
');
// Checklist instance tables
$this->addSql('
CREATE TABLE service_checklist (
id INT AUTO_INCREMENT NOT NULL,
uuid VARCHAR(36) NOT NULL,
job_id INT NOT NULL,
asset_lifecycle_period_id INT DEFAULT NULL,
template_id INT DEFAULT NULL,
checklist_type VARCHAR(20) NOT NULL,
service_level VARCHAR(1) DEFAULT NULL,
status VARCHAR(30) NOT NULL DEFAULT \'not_started\',
engineer_id INT DEFAULT NULL,
engineer_signed_at DATETIME DEFAULT NULL,
engineer_signature_id INT DEFAULT NULL,
customer_name VARCHAR(255) DEFAULT NULL,
customer_signed_at DATETIME DEFAULT NULL,
customer_signature_id INT DEFAULT NULL,
signoff_token VARCHAR(64) DEFAULT NULL,
signoff_token_expires_at DATETIME DEFAULT NULL,
pdf_path VARCHAR(500) DEFAULT NULL,
pdf_filename VARCHAR(255) DEFAULT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
completed_at DATETIME DEFAULT NULL,
synced_at DATETIME DEFAULT NULL,
deleted_at DATETIME DEFAULT NULL,
UNIQUE INDEX UNIQ_checklist_job (job_id),
INDEX IDX_checklist_asset (asset_lifecycle_period_id),
INDEX IDX_checklist_status (status),
INDEX IDX_checklist_template (template_id),
INDEX IDX_checklist_engineer (engineer_id),
INDEX IDX_checklist_engineer_sig (engineer_signature_id),
INDEX IDX_checklist_customer_sig (customer_signature_id),
PRIMARY KEY(id),
CONSTRAINT FK_checklist_job FOREIGN KEY (job_id)
REFERENCES job (id) ON DELETE CASCADE,
CONSTRAINT FK_checklist_alp FOREIGN KEY (asset_lifecycle_period_id)
REFERENCES asset_lifecycle_period (id) ON DELETE SET NULL,
CONSTRAINT FK_checklist_template FOREIGN KEY (template_id)
REFERENCES service_checklist_template (id) ON DELETE SET NULL,
CONSTRAINT FK_checklist_engineer FOREIGN KEY (engineer_id)
REFERENCES user (id) ON DELETE SET NULL,
CONSTRAINT FK_checklist_engineer_sig FOREIGN KEY (engineer_signature_id)
REFERENCES image (id) ON DELETE SET NULL,
CONSTRAINT FK_checklist_customer_sig FOREIGN KEY (customer_signature_id)
REFERENCES image (id) ON DELETE SET NULL
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
');
$this->addSql('
CREATE TABLE service_checklist_section (
id INT AUTO_INCREMENT NOT NULL,
checklist_id INT DEFAULT NULL,
template_section_id INT DEFAULT NULL,
name VARCHAR(255) NOT NULL,
sort_order INT NOT NULL DEFAULT 0,
INDEX IDX_section_checklist (checklist_id),
INDEX IDX_section_template (template_section_id),
PRIMARY KEY(id),
CONSTRAINT FK_section_checklist FOREIGN KEY (checklist_id)
REFERENCES service_checklist (id) ON DELETE CASCADE,
CONSTRAINT FK_section_template FOREIGN KEY (template_section_id)
REFERENCES service_checklist_template_section (id) ON DELETE SET NULL
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
');
$this->addSql('
CREATE TABLE service_checklist_item (
id INT AUTO_INCREMENT NOT NULL,
section_id INT DEFAULT NULL,
template_item_id INT DEFAULT NULL,
name VARCHAR(500) NOT NULL,
item_type VARCHAR(20) NOT NULL DEFAULT \'inspection\',
sort_order INT NOT NULL DEFAULT 0,
is_mandatory TINYINT(1) NOT NULL DEFAULT 0,
requires_photo TINYINT(1) NOT NULL DEFAULT 0,
requires_note TINYINT(1) NOT NULL DEFAULT 0,
min_value DECIMAL(10,2) DEFAULT NULL,
max_value DECIMAL(10,2) DEFAULT NULL,
unit VARCHAR(20) DEFAULT NULL,
outcome VARCHAR(20) DEFAULT NULL,
measured_value DECIMAL(10,2) DEFAULT NULL,
note LONGTEXT DEFAULT NULL,
completed_at DATETIME DEFAULT NULL,
INDEX IDX_item_section (section_id),
INDEX IDX_item_template (template_item_id),
INDEX IDX_item_outcome (outcome),
PRIMARY KEY(id),
CONSTRAINT FK_item_section FOREIGN KEY (section_id)
REFERENCES service_checklist_section (id) ON DELETE CASCADE,
CONSTRAINT FK_item_template FOREIGN KEY (template_item_id)
REFERENCES service_checklist_template_item (id) ON DELETE SET NULL
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
');
// Checklist item images (many-to-many)
$this->addSql('
CREATE TABLE service_checklist_item_images (
checklist_item_id INT NOT NULL,
image_id INT NOT NULL,
INDEX IDX_item_images_item (checklist_item_id),
INDEX IDX_item_images_image (image_id),
PRIMARY KEY(checklist_item_id, image_id),
CONSTRAINT FK_item_images_item FOREIGN KEY (checklist_item_id)
REFERENCES service_checklist_item (id) ON DELETE CASCADE,
CONSTRAINT FK_item_images_image FOREIGN KEY (image_id)
REFERENCES image (id) ON DELETE CASCADE
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
');
// Defects table
$this->addSql('
CREATE TABLE service_checklist_defect (
id INT AUTO_INCREMENT NOT NULL,
checklist_id INT DEFAULT NULL,
checklist_item_id INT DEFAULT NULL,
defect_type VARCHAR(20) NOT NULL,
severity VARCHAR(20) DEFAULT NULL,
status VARCHAR(20) NOT NULL DEFAULT \'open\',
description LONGTEXT NOT NULL,
office_notes LONGTEXT DEFAULT NULL,
severity_set_by_id INT DEFAULT NULL,
severity_set_at DATETIME DEFAULT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
resolved_at DATETIME DEFAULT NULL,
INDEX IDX_defect_checklist (checklist_id),
INDEX IDX_defect_item (checklist_item_id),
INDEX IDX_defect_severity (severity),
INDEX IDX_defect_status (status),
INDEX IDX_defect_set_by (severity_set_by_id),
PRIMARY KEY(id),
CONSTRAINT FK_defect_checklist FOREIGN KEY (checklist_id)
REFERENCES service_checklist (id) ON DELETE CASCADE,
CONSTRAINT FK_defect_item FOREIGN KEY (checklist_item_id)
REFERENCES service_checklist_item (id) ON DELETE CASCADE,
CONSTRAINT FK_defect_set_by FOREIGN KEY (severity_set_by_id)
REFERENCES user (id) ON DELETE SET NULL
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
');
}
public function down(Schema $schema): void
{
$this->addSql('DROP TABLE IF EXISTS service_checklist_defect');
$this->addSql('DROP TABLE IF EXISTS service_checklist_item_images');
$this->addSql('DROP TABLE IF EXISTS service_checklist_item');
$this->addSql('DROP TABLE IF EXISTS service_checklist_section');
$this->addSql('DROP TABLE IF EXISTS service_checklist');
$this->addSql('DROP TABLE IF EXISTS service_checklist_template_item');
$this->addSql('DROP TABLE IF EXISTS service_checklist_template_section');
$this->addSql('DROP TABLE IF EXISTS service_checklist_template');
}
}