Skip to main content

HazCom Plan Builder Schema

Overview

The HazCom Plan Builder uses the plan_hazcom_ prefix for all tables. The schema supports two-tier plan creation (Basic + Premium), versioning, approval workflows, audit logging, and AI content generation via JSONB metadata.

Tables

TablePurposeStatus
plan_hazcom_plansMaster plan records with versioningImplemented
plan_hazcom_plan_sectionsSection content per plan (7 OSHA sections)Implemented
plan_hazcom_question_templatesGlobal question bankImplemented
plan_hazcom_audit_logsDedicated audit trailImplemented
plan_hazcom_pending_changesChange detection alertsPlanned
plan_hazcom_review_tasksAnnual review tasksPlanned

plan_hazcom_plans

Master record for each HazCom plan version. One active plan per site enforced via partial unique index.

Key Columns

ColumnTypeDescription
plan_idUUID, PKPrimary identifier
company_idUUID, FKCompany ownership
site_idUUID, FKSite scope
plan_nameString(255)Plan title
plan_typeString(30)basic or premium
version_numberString(20)Semantic version (e.g., "1.0", "2.0")
version_statusString(30)draft, pending_approval, approved, active, archived

Coordinator Fields

ColumnTypeDescription
coordinator_user_idUUID, FKLinks to users table
coordinator_nameString(255)Coordinator name
coordinator_titleString(100)Job title
coordinator_emailString(255)Contact email
coordinator_phoneString(50)Contact phone
ColumnTypeDescription
previous_version_idUUID, FK (self)Links to prior version
superseded_by_idUUID, FK (self)Links to newer version
created_by_user_idUUID, FKUser who created

Indexes

  • ix_plan_hazcom_plans_company_site — Composite (company_id, site_id)
  • ix_plan_hazcom_plans_status — B-tree on version_status
  • ix_plan_hazcom_plans_unique_active — Partial unique: one active plan per site

Status Workflow

DRAFT → PENDING_APPROVAL → APPROVED → ACTIVE → ARCHIVED

(Create New Version → new DRAFT)

plan_hazcom_plan_sections

Stores questionnaire answers and generated content for each of the 7 OSHA sections per plan.

Section Codes

CodeTitleOSHA Reference
company_infoCompany & Site InformationGeneral
inventoryChemical Inventory§1910.1200(e)
labelingContainer Labeling§1910.1200(f)
sdsSafety Data Sheets§1910.1200(g)
trainingEmployee Training§1910.1200(h)
non_routineNon-Routine Tasks§1910.1200(e)(1)(ii)
contractorsContractor Coordination§1910.1200(e)(2)

Key Columns

ColumnTypeDescription
section_idUUID, PKPrimary identifier
plan_idUUID, FKParent plan
section_codeString(50)Section identifier
section_orderIntegerDisplay order (1-7)
content_typeString(30)manual, ai_generated, hybrid
questionnaire_answersJSONBUser's answers to section questions
generated_contentTextFinal rendered section content (markdown)
content_metadataJSONBAI metadata, dynamic questions, prefill data
completion_percentageInteger0-100

AI Tracking Columns

ColumnTypeDescription
ai_generated_atTimestampWhen AI content was generated
ai_model_versionString(50)AI model identifier
user_editedBooleanTrue if user modified AI content

content_metadata JSONB Structure

Used by Phases 3-5 for AI operations:

{
"dynamic_questions": [
{
"question_code": "dq_flammable_storage",
"question_text": "How are flammable chemicals stored?",
"question_type": "textarea",
"section_code": "inventory",
"is_required": true,
"ai_generated": true
}
],
"prefill_data": {
"question_code": {
"suggested_answer": "Receiving personnel verify...",
"confidence": 0.85,
"source": "company_profile"
}
},
"ai_task_id": "uuid",
"ai_task_status": "questions_ready",
"confidence_score": 0.92,
"ai_contribution": {
"ai_assisted_answer_count": 12,
"total_answer_count": 25,
"ai_generated_section_count": 7,
"total_section_count": 7
}
}

plan_hazcom_question_templates

Global question bank defining the questionnaire structure. Shared across all companies.

Key Columns

ColumnTypeDescription
template_idUUID, PKPrimary identifier
section_codeString(50)OSHA section
question_codeString(100)Unique within section
question_orderIntegerDisplay order
question_textTextThe question
question_typeString(30)text, textarea, select, select_multiple, yes_no, date
optionsJSONBOptions for select types (value + text + paragraph)
is_requiredBooleanMust be answered
ai_prefillableBooleanCan be pre-populated by AI
available_for_basicBooleanShow in Basic plans
available_for_premiumBooleanShow in Premium plans

plan_hazcom_audit_logs

Dedicated audit trail for all plan actions. Implemented in Phase 2.

Key Columns

ColumnTypeDescription
log_idUUID, PKPrimary identifier
plan_idUUID, FKRelated plan
company_idUUID, FKCompany scope
actionString(50)Action type (16 types)
action_categoryString(30)general, section, workflow, export, version
action_detailsJSONBStructured action metadata
plan_versionString(20)Version at time of action
plan_statusString(30)Status at time of action
user_idUUID, FKUser who performed action
user_emailString(255)Denormalized for fast reads
user_ipString(45)IPv6-compatible IP
user_agentString(500)Browser user agent

Action Types

ActionCategory
createdgeneral
updatedgeneral
deletedgeneral
viewedgeneral
section_updatedsection
section_content_editedsection
submittedworkflow
approvedworkflow
rejectedworkflow
publishedworkflow
archivedversion
exported_pdfexport
exported_docxexport
preview_generatedexport
version_createdversion
version_restoredversion

Entity Relationships

core_data_companies ──┐

core_data_company_sites ──┐

v
plan_hazcom_plans (Master)

┌───────────┼────────────┐
v v v
sections audit_logs (self-ref: previous_version)
(7 per plan)

plan_hazcom_question_templates (Global, no FK to plans)