Sindbad~EG File Manager
-- COP News Portal Database Schema
-- Church of Pentecost News Management System
CREATE DATABASE IF NOT EXISTS copmadinaarea_cop_news_portal;
USE copmadinaarea_cop_news_portal;
-- Users table for authentication and profile management
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
username VARCHAR(50) UNIQUE NOT NULL,
telephone VARCHAR(20),
password VARCHAR(255) NOT NULL,
address TEXT,
description TEXT,
account_type ENUM('superuser', 'admin', 'user') DEFAULT 'user',
user_picture VARCHAR(255),
location_id INT NULL,
status ENUM('active', 'inactive') DEFAULT 'active',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (location_id) REFERENCES locations(id) ON DELETE SET NULL
);
-- Categories table for program types
CREATE TABLE categories (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
type ENUM('area_program', 'district_program', 'local_program', 'general') NOT NULL,
description TEXT,
created_by INT,
status ENUM('active', 'inactive') DEFAULT 'active',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
);
-- News articles table
CREATE TABLE news (
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
location_id INT NOT NULL,
description TEXT,
content LONGTEXT NOT NULL,
written_by VARCHAR(100) NOT NULL,
category_id INT,
user_id INT NOT NULL,
featured_image VARCHAR(255),
status ENUM('draft', 'published', 'archived') DEFAULT 'draft',
views INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (location_id) REFERENCES locations(id) ON DELETE RESTRICT
);
-- Notifications table
CREATE TABLE notifications (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT NOT NULL,
title VARCHAR(255) NOT NULL,
message TEXT NOT NULL,
type ENUM('info', 'warning', 'success', 'error') DEFAULT 'info',
is_read BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Audit log table for tracking system activities
CREATE TABLE audit_logs (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT,
action VARCHAR(100) NOT NULL,
table_name VARCHAR(50) NOT NULL,
record_id INT,
old_values JSON,
new_values JSON,
ip_address VARCHAR(45),
user_agent TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
);
-- Settings table for system configuration
CREATE TABLE settings (
id INT PRIMARY KEY AUTO_INCREMENT,
setting_key VARCHAR(100) UNIQUE NOT NULL,
setting_value TEXT,
setting_type ENUM('text', 'number', 'boolean', 'json') DEFAULT 'text',
description TEXT,
updated_by INT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL
);
-- Sessions table for user session management
CREATE TABLE user_sessions (
id VARCHAR(128) PRIMARY KEY,
user_id INT NOT NULL,
ip_address VARCHAR(45),
user_agent TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
expires_at TIMESTAMP NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Locations table for managing church locations
CREATE TABLE locations (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
type ENUM('area', 'district', 'assembly') NOT NULL,
parent_id INT NULL,
address TEXT,
contact_person VARCHAR(100),
contact_phone VARCHAR(20),
contact_email VARCHAR(100),
description TEXT,
status ENUM('active', 'inactive') DEFAULT 'active',
created_by INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (parent_id) REFERENCES locations(id) ON DELETE SET NULL,
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
UNIQUE KEY unique_location (name, type)
);
-- Insert default categories
INSERT INTO categories (name, type, description) VALUES
('Area Programs', 'area_program', 'Programs organized at area level'),
('District Programs', 'district_program', 'Programs organized at district level'),
('Local Assembly Programs', 'local_program', 'Programs organized at local assembly level'),
('General Announcements', 'general', 'General church announcements');
-- Insert sample locations
INSERT INTO locations (name, type, parent_id, address, contact_person, contact_phone, contact_email, description, created_by) VALUES
('Greater Accra Area', 'area', NULL, 'Accra, Ghana', 'Elder John Mensah', '+233244123456', 'accra.area@cop.org', 'Greater Accra Area Office', 1),
('Ashanti Area', 'area', NULL, 'Kumasi, Ghana', 'Elder Grace Owusu', '+233244123457', 'ashanti.area@cop.org', 'Ashanti Area Office', 1),
('Northern Area', 'area', NULL, 'Tamale, Ghana', 'Elder Isaac Alhassan', '+233244123458', 'northern.area@cop.org', 'Northern Area Office', 1),
('Tema District', 'district', 1, 'Tema, Ghana', 'Pastor Samuel Osei', '+233244234567', 'tema.district@cop.org', 'Tema District Office', 1),
('Accra Central District', 'district', 1, 'Accra Central, Ghana', 'Pastor Rebecca Adjei', '+233244234568', 'accra.central@cop.org', 'Accra Central District Office', 1),
('Kumasi District', 'district', 2, 'Kumasi, Ghana', 'Pastor Emmanuel Boateng', '+233244234569', 'kumasi.district@cop.org', 'Kumasi District Office', 1),
('Community 1 Assembly', 'assembly', 4, 'Community 1, Tema', 'Elder Mary Asante', '+233244345678', 'comm1.assembly@cop.org', 'Community 1 Local Assembly', 1),
('Community 9 Assembly', 'assembly', 4, 'Community 9, Tema', 'Elder Joseph Tetteh', '+233244345679', 'comm9.assembly@cop.org', 'Community 9 Local Assembly', 1),
('Osu Assembly', 'assembly', 5, 'Osu, Accra', 'Elder Sarah Mensah', '+233244345680', 'osu.assembly@cop.org', 'Osu Local Assembly', 1),
('Adum Assembly', 'assembly', 6, 'Adum, Kumasi', 'Elder Peter Asante', '+233244345681', 'adum.assembly@cop.org', 'Adum Local Assembly', 1);
-- Insert default settings
INSERT INTO settings (setting_key, setting_value, setting_type, description) VALUES
('site_title', 'COP News Portal', 'text', 'Website title'),
('site_logo', 'assets/images/cop-logo.png', 'text', 'Website logo path'),
('footer_title', 'Church of Pentecost News Portal', 'text', 'Footer title'),
('theme_primary_color', '#3B82F6', 'text', 'Primary theme color'),
('theme_secondary_color', '#6B7280', 'text', 'Secondary theme color'),
('backup_frequency', 'daily', 'text', 'Backup frequency setting'),
('maintenance_mode', 'false', 'boolean', 'Maintenance mode status'),
('max_file_upload_size', '5242880', 'number', 'Maximum file upload size in bytes (5MB)'),
('tinymce_api_key', 'cy1it2xoa81hi6fiynvv5pcgjnms5lqa8uhr1n5vdukymhud', 'text', 'TinyMCE API key for rich text editor');
-- Insert superuser account
INSERT INTO users (name, email, username, telephone, password, account_type, location_id, status) VALUES
('System Administrator', 'nabibo2@yahoo.co.uk', 'superadmin', '', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'superuser', 1, 'active');
-- Note: Password: 'Swanzy10@' - Use this to login as superuser
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists