Sindbad~EG File Manager

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

-- Officership Management System Tables
-- Tables for tracking ordination, retirement, and transfer details for church officers

-- =====================================================
-- Ordination Details Table
-- =====================================================
CREATE TABLE IF NOT EXISTS `ordination` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `member_id` INT(11) NOT NULL,
  `date_ordained` DATE NOT NULL,
  `ordained_by` VARCHAR(255) NOT NULL COMMENT 'Name of the ordaining minister',
  `venue_ordained` VARCHAR(255) DEFAULT NULL COMMENT 'Location/venue of ordination',
  `district_ordained_in` INT(11) DEFAULT NULL COMMENT 'District ID where ordained',
  `area_ordained_in` INT(11) DEFAULT NULL COMMENT 'Area ID where ordained',
  `assembly_ordained_in` INT(11) DEFAULT NULL COMMENT 'Assembly ID where ordained',
  `card_no` VARCHAR(50) DEFAULT NULL COMMENT 'Officership/Pastorate card number',
  `ordination_title` VARCHAR(50) NOT NULL COMMENT 'Title ordained as (Pastor, Elder, etc)',
  `certificate_no` VARCHAR(100) DEFAULT NULL COMMENT 'Certificate number',
  `is_suspended` TINYINT(1) DEFAULT 0 COMMENT '0=Active, 1=Suspended',
  `suspended_by` VARCHAR(255) DEFAULT NULL COMMENT 'Name of person who suspended',
  `suspended_date` DATE DEFAULT NULL COMMENT 'Date of suspension',
  `suspension_reason` TEXT DEFAULT NULL COMMENT 'Reason for suspension',
  `reactivated_date` DATE DEFAULT NULL COMMENT 'Date reactivated if applicable',
  `notes` TEXT DEFAULT NULL COMMENT 'Additional notes',
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `created_by` INT(11) DEFAULT NULL,
  `updated_by` INT(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_member_id` (`member_id`),
  KEY `idx_district` (`district_ordained_in`),
  KEY `idx_area` (`area_ordained_in`),
  KEY `idx_assembly` (`assembly_ordained_in`),
  KEY `idx_date_ordained` (`date_ordained`),
  KEY `idx_ordination_title` (`ordination_title`),
  KEY `idx_is_suspended` (`is_suspended`),
  CONSTRAINT `fk_ordination_member` FOREIGN KEY (`member_id`) REFERENCES `members` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Ordination details for church officers and pastorate';

-- =====================================================
-- Retiree Details Table
-- =====================================================
CREATE TABLE IF NOT EXISTS `retiree_details` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `member_id` INT(11) NOT NULL,
  `ordination_id` INT(11) DEFAULT NULL COMMENT 'Link to ordination record',
  `date_retired` DATE NOT NULL,
  `retired_by` VARCHAR(255) NOT NULL COMMENT 'Name of person who conducted retirement',
  `venue_retired` VARCHAR(255) DEFAULT NULL COMMENT 'Location/venue of retirement ceremony',
  `district_retired_in` INT(11) DEFAULT NULL COMMENT 'District ID where retired',
  `area_retired_in` INT(11) DEFAULT NULL COMMENT 'Area ID where retired',
  `assembly_retired_in` INT(11) DEFAULT NULL COMMENT 'Assembly ID where retired',
  `years_of_service` INT(11) DEFAULT NULL COMMENT 'Total years served',
  `retirement_reason` VARCHAR(255) DEFAULT NULL COMMENT 'Reason for retirement (Age, Health, Voluntary, etc)',
  `retirement_type` ENUM('voluntary', 'mandatory_age', 'health', 'other') DEFAULT 'voluntary',
  `benefits_status` VARCHAR(100) DEFAULT NULL COMMENT 'Retirement benefits status',
  `certificate_issued` TINYINT(1) DEFAULT 0 COMMENT '0=No, 1=Yes',
  `certificate_no` VARCHAR(100) DEFAULT NULL,
  `notes` TEXT DEFAULT NULL COMMENT 'Additional notes',
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `created_by` INT(11) DEFAULT NULL,
  `updated_by` INT(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_member_id` (`member_id`),
  KEY `idx_ordination_id` (`ordination_id`),
  KEY `idx_district` (`district_retired_in`),
  KEY `idx_area` (`area_retired_in`),
  KEY `idx_assembly` (`assembly_retired_in`),
  KEY `idx_date_retired` (`date_retired`),
  KEY `idx_retirement_type` (`retirement_type`),
  CONSTRAINT `fk_retiree_member` FOREIGN KEY (`member_id`) REFERENCES `members` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_retiree_ordination` FOREIGN KEY (`ordination_id`) REFERENCES `ordination` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Retirement details for church officers and pastorate';

-- =====================================================
-- Officer Transfers Table
-- =====================================================
CREATE TABLE IF NOT EXISTS `officer_transfers` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `member_id` INT(11) NOT NULL,
  `ordination_id` INT(11) DEFAULT NULL COMMENT 'Link to ordination record',
  `transfer_type` ENUM('in', 'out') NOT NULL COMMENT 'Transfer direction',
  `transfer_date` DATE NOT NULL,
  `from_district_id` INT(11) DEFAULT NULL,
  `from_area_id` INT(11) DEFAULT NULL,
  `from_assembly_id` INT(11) DEFAULT NULL,
  `to_district_id` INT(11) DEFAULT NULL,
  `to_area_id` INT(11) DEFAULT NULL,
  `to_assembly_id` INT(11) DEFAULT NULL,
  `officer_title` VARCHAR(50) DEFAULT NULL COMMENT 'Title during transfer (Pastor, Elder, etc)',
  `transfer_reason` TEXT DEFAULT NULL,
  `approved_by` VARCHAR(255) DEFAULT NULL COMMENT 'Name of approving authority',
  `approval_date` DATE DEFAULT NULL,
  `status` ENUM('pending', 'approved', 'rejected', 'completed') DEFAULT 'pending',
  `effective_date` DATE DEFAULT NULL COMMENT 'When transfer becomes effective',
  `notes` TEXT DEFAULT NULL,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `created_by` INT(11) DEFAULT NULL,
  `updated_by` INT(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_member_id` (`member_id`),
  KEY `idx_ordination_id` (`ordination_id`),
  KEY `idx_transfer_type` (`transfer_type`),
  KEY `idx_transfer_date` (`transfer_date`),
  KEY `idx_from_district` (`from_district_id`),
  KEY `idx_to_district` (`to_district_id`),
  KEY `idx_status` (`status`),
  KEY `idx_officer_title` (`officer_title`),
  CONSTRAINT `fk_transfer_member` FOREIGN KEY (`member_id`) REFERENCES `members` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_transfer_ordination` FOREIGN KEY (`ordination_id`) REFERENCES `ordination` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Transfer records for church officers and pastorate';

-- =====================================================
-- Indexes for Performance
-- =====================================================

-- Additional composite indexes for common queries
CREATE INDEX idx_ordination_member_title ON ordination(member_id, ordination_title);
CREATE INDEX idx_ordination_district_title ON ordination(district_ordained_in, ordination_title);
CREATE INDEX idx_retiree_member_date ON retiree_details(member_id, date_retired);
CREATE INDEX idx_transfer_member_type ON officer_transfers(member_id, transfer_type);
CREATE INDEX idx_transfer_district_type ON officer_transfers(to_district_id, transfer_type);

-- =====================================================
-- Sample Data (Optional - for testing)
-- =====================================================

-- Note: These inserts would require actual member_id values from your members table
-- Uncomment and modify when ready to test

/*
-- Sample Ordination Records
INSERT INTO ordination (member_id, date_ordained, ordained_by, venue_ordained, district_ordained_in, ordination_title, card_no) 
VALUES 
(1, '2020-01-15', 'Bishop John Smith', 'Central Church', 1, 'Pastor', 'PAST-001'),
(2, '2019-05-20', 'Apostle David Brown', 'District Conference Hall', 1, 'Elder', 'ELD-001');

-- Sample Retirement Records  
INSERT INTO retiree_details (member_id, ordination_id, date_retired, retired_by, venue_retired, years_of_service, retirement_reason)
VALUES
(3, 3, '2024-06-30', 'Bishop James Wilson', 'Annual Conference', 35, 'Age Retirement');

-- Sample Transfer Records
INSERT INTO officer_transfers (member_id, transfer_type, transfer_date, from_district_id, to_district_id, officer_title, status)
VALUES
(1, 'out', '2024-01-15', 1, 2, 'Pastor', 'completed'),
(4, 'in', '2024-01-15', 2, 1, 'Elder', 'completed');
*/

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