Sindbad~EG File Manager
-- Demography Data Table
-- Add this to your existing database
CREATE TABLE demography_data (
id INT AUTO_INCREMENT PRIMARY KEY,
area_id INT NOT NULL,
district_id INT NOT NULL,
assembly_id INT NOT NULL,
-- Children's Membership (below 13yrs)
children_male INT DEFAULT 0,
children_female INT DEFAULT 0,
children_total INT GENERATED ALWAYS AS (children_male + children_female) STORED,
-- Youth Membership - Teens (13-19yrs)
teens_male INT DEFAULT 0,
teens_female INT DEFAULT 0,
teens_total INT GENERATED ALWAYS AS (teens_male + teens_female) STORED,
-- Youth Membership - Young Adults (20-35yrs)
young_adults_male INT DEFAULT 0,
young_adults_female INT DEFAULT 0,
young_adults_total INT GENERATED ALWAYS AS (young_adults_male + young_adults_female) STORED,
-- Youth Total (Teens + Young Adults)
youth_total INT GENERATED ALWAYS AS (teens_total + young_adults_total) STORED,
-- Other Adults (above 35 years)
other_adults_male INT DEFAULT 0,
other_adults_female INT DEFAULT 0,
other_adults_total INT GENERATED ALWAYS AS (other_adults_male + other_adults_female) STORED,
-- Total Adult Members (Youth + Other Adults)
total_adult_members INT GENERATED ALWAYS AS (youth_total + other_adults_total) STORED,
-- Overall Members (Adults & Children)
overall_members INT GENERATED ALWAYS AS (children_total + total_adult_members) STORED,
-- Metadata
created_by INT NOT NULL,
updated_by INT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-- Foreign Keys
FOREIGN KEY (area_id) REFERENCES areas(id) ON DELETE CASCADE,
FOREIGN KEY (district_id) REFERENCES districts(id) ON DELETE CASCADE,
FOREIGN KEY (assembly_id) REFERENCES assemblies(id) ON DELETE CASCADE,
FOREIGN KEY (created_by) REFERENCES users(id),
FOREIGN KEY (updated_by) REFERENCES users(id),
-- Unique constraint to prevent duplicate entries for same assembly
UNIQUE KEY unique_assembly_entry (assembly_id),
-- Indexes for better performance
INDEX idx_area_district (area_id, district_id),
INDEX idx_created_by (created_by),
INDEX idx_created_at (created_at)
);
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists