Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/sql/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/sql/ministry_executives.sql

-- Ministry Executives Module Database Schema
-- Created: 2025-11-20

-- Ministry Executive Assignments Table
CREATE TABLE IF NOT EXISTS ministry_executives (
    id INT AUTO_INCREMENT PRIMARY KEY,
    ministry_id INT NOT NULL,
    member_id INT NOT NULL,
    position_id INT NOT NULL,
    start_date DATE NOT NULL,
    end_date DATE,
    appointment_type ENUM('elected', 'appointed', 'interim') DEFAULT 'appointed',
    status ENUM('active', 'completed', 'resigned', 'removed') DEFAULT 'active',
    appointed_by INT,
    appointment_letter VARCHAR(255), -- file path
    notes TEXT,
    performance_rating DECIMAL(3,2), -- 0.00 to 5.00
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (ministry_id) REFERENCES ministries(id) ON DELETE CASCADE,
    FOREIGN KEY (member_id) REFERENCES members(id) ON DELETE CASCADE,
    FOREIGN KEY (position_id) REFERENCES ministry_positions(id) ON DELETE CASCADE,
    FOREIGN KEY (appointed_by) REFERENCES users(id) ON DELETE SET NULL,
    INDEX idx_ministry (ministry_id),
    INDEX idx_member (member_id),
    INDEX idx_position (position_id),
    INDEX idx_status (status),
    INDEX idx_dates (start_date, end_date),
    UNIQUE KEY unique_active_position (ministry_id, position_id, member_id, status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Executive History/Transitions Table
CREATE TABLE IF NOT EXISTS executive_history (
    id INT AUTO_INCREMENT PRIMARY KEY,
    executive_id INT NOT NULL,
    ministry_id INT NOT NULL,
    member_id INT NOT NULL,
    position_id INT NOT NULL,
    action_type ENUM('appointed', 'promoted', 'resigned', 'removed', 'term_completed') NOT NULL,
    action_date DATE NOT NULL,
    reason TEXT,
    performed_by INT,
    notes TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (executive_id) REFERENCES ministry_executives(id) ON DELETE CASCADE,
    FOREIGN KEY (ministry_id) REFERENCES ministries(id) ON DELETE CASCADE,
    FOREIGN KEY (member_id) REFERENCES members(id) ON DELETE CASCADE,
    FOREIGN KEY (position_id) REFERENCES ministry_positions(id) ON DELETE CASCADE,
    FOREIGN KEY (performed_by) REFERENCES users(id) ON DELETE SET NULL,
    INDEX idx_executive (executive_id),
    INDEX idx_ministry (ministry_id),
    INDEX idx_member (member_id),
    INDEX idx_action (action_type),
    INDEX idx_date (action_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Executive Achievements Table
CREATE TABLE IF NOT EXISTS executive_achievements (
    id INT AUTO_INCREMENT PRIMARY KEY,
    executive_id INT NOT NULL,
    achievement_title VARCHAR(255) NOT NULL,
    achievement_description TEXT,
    achievement_date DATE,
    category VARCHAR(100), -- 'milestone', 'award', 'project_completion', etc.
    visibility ENUM('public', 'internal', 'private') DEFAULT 'internal',
    created_by INT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (executive_id) REFERENCES ministry_executives(id) ON DELETE CASCADE,
    FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
    INDEX idx_executive (executive_id),
    INDEX idx_date (achievement_date),
    INDEX idx_category (category)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Executive Reports Table (for term reports, handover notes, etc.)
CREATE TABLE IF NOT EXISTS executive_reports (
    id INT AUTO_INCREMENT PRIMARY KEY,
    executive_id INT NOT NULL,
    report_type ENUM('monthly', 'quarterly', 'annual', 'handover', 'special') NOT NULL,
    report_title VARCHAR(255) NOT NULL,
    report_content LONGTEXT,
    report_period_start DATE,
    report_period_end DATE,
    report_file VARCHAR(255), -- file path
    submitted_date DATE,
    approved_by INT,
    approval_date DATE,
    status ENUM('draft', 'submitted', 'approved', 'rejected') DEFAULT 'draft',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (executive_id) REFERENCES ministry_executives(id) ON DELETE CASCADE,
    FOREIGN KEY (approved_by) REFERENCES users(id) ON DELETE SET NULL,
    INDEX idx_executive (executive_id),
    INDEX idx_type (report_type),
    INDEX idx_status (status),
    INDEX idx_period (report_period_start, report_period_end)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists