Database Schema
Database Schema
Section titled “Database Schema”Analysis Basis
Section titled “Analysis Basis”This summary is based on the database artifacts found in the repository:
- the full schema dump in
motmaina-website/migrations/20250722_full_ddl_dump.sql - incremental SQL migrations in
motmaina-website/migrations
I did not find a dedicated seeder structure in the repository. In practice, the schema understanding comes from:
- DDL table creation statements
- later
ALTER TABLE,CREATE INDEX, andINSERTmigrations - configuration and route usage that reveal the active product domains
Schema Shape
Section titled “Schema Shape”The current database is a large monolithic relational schema that supports multiple product surfaces inside one application.
It includes:
- public website content
- customer accounts
- consultations and appointments
- courses and subscriptions
- notifications and operational logs
- admin RBAC
- integrations and payment records
This is not a narrowly scoped website database. It is the shared operational database for the broader motmaina platform.
Main Functional Domains
Section titled “Main Functional Domains”Relationship Diagrams
Section titled “Relationship Diagrams”The following Mermaid diagrams simplify the most important relationships in the current schema.
They are documentation-level diagrams, not a full foreign-key specification.
Consultation and Medical Flow
Section titled “Consultation and Medical Flow”erDiagram CUSTOMERS ||--o{ CUSTOMER_CONSULTATIONS : books CONSULTANTS ||--o{ CUSTOMER_CONSULTATIONS : handles CONSULTANTS ||--o{ CONSULTANTS_SCHEDULE : owns CONSULTATIONS_CATEGORIES ||--o{ CUSTOMER_CONSULTATIONS : classifies BRANCHES ||--o{ CUSTOMER_CONSULTATIONS : hosts CONSULTANTS_SCHEDULE ||--o{ CUSTOMER_CONSULTATIONS : schedules CUSTOMER_CONSULTATIONS ||--o{ CONSULTATION_CANCEL_REQUESTS : may_create CUSTOMER_CONSULTATIONS ||--o{ CONSULTATIONS_REPORTS : may_generate CUSTOMER_CONSULTATIONS ||--o{ CONSULTATIONS_PRESCRIPTIONS : may_generate CONSULTATIONS_DIAGNOSIS ||--o{ CONSULTATIONS_PRESCRIPTIONS : references CONSULTATIONS_PRESCRIPTIONS ||--o{ CONSULTATIONS_PRESCRIPTION_MEDICINES : contains CONSULTATIONS_MEDICIN ||--o{ CONSULTATIONS_PRESCRIPTION_MEDICINES : selectedAppointment Inquiry and Booking Flow
Section titled “Appointment Inquiry and Booking Flow”erDiagram BRANCHES ||--o{ APPOINTMENTS : receives CONSULTANTS ||--o{ APPOINTMENTS : may_assign SERVICES ||--o{ APPOINTMENTS : may_reference CUSTOMERS ||--o{ APPOINTMENTS : may_belong_to APPOINTMENTS ||--o{ APPOINTMENT_STATUS_LOG : tracks APPOINTMENTS ||--o{ APPOINTMENT_ACTIVITIES : recordsCourses, Cart, and Subscription Flow
Section titled “Courses, Cart, and Subscription Flow”erDiagram COURSES_CATEGORIES ||--o{ COURSES : groups TRAINERS ||--o{ COURSES : teaches COURSES ||--o{ COURSES_CLASSES : contains COURSES_CLASSES ||--o{ COURSES_LESSONS : contains COURSES_LESSONS ||--o{ COURSES_LESSONS_FILES : attaches COLLECTIONS ||--o{ COLLECTION_COURSES : maps COURSES ||--o{ COLLECTION_COURSES : maps CUSTOMERS ||--o{ CUSTOMER_SUBSCRIPTIONS : owns CUSTOMERS ||--o{ CUSTOMER_SUBSCRIPTION_HISTORY : pays_for CUSTOMERS ||--o{ CUSTOMER_ORDERS : purchases COURSES ||--o{ CUSTOMER_COURSE_CERTIFICATES : awards CUSTOMERS ||--o{ CUSTOMER_COURSE_CERTIFICATES : receivesContent and Engagement Flow
Section titled “Content and Engagement Flow”erDiagram ARTICLES_CATEGORIES ||--o{ ARTICLES : groups ARTICLES ||--o{ ARTICLES_PAGES_VIEWS : tracks NEWS_CATEGORIES ||--o{ NEWS : groups NEWS ||--o{ NEWS_COMMENTS : receives NEWS ||--o{ NEWS_PAGES_VIEWS : tracks FORUM_CATEGORIES ||--o{ FORUM : groups FORUM ||--o{ FORUM_COMMENTS : receives FORUM ||--o{ FORUM_LIKES : receives LIBRARY_CATEGORIES ||--o{ LIBRARY : groups LIBRARY ||--o{ LIBRARY_PAGES_VIEWS : tracks1. Website and CMS Content
Section titled “1. Website and CMS Content”The public website content is stored in classic content tables, including:
articlesarticles_categoriesnewsnews_categoriesforumforum_categorieslibrarylibrary_categoriescustome_pagescustome_pages_categorieswebsite_sliderwebsite_slider_categorieswebsite_settingswebsite_featureswebsite_contactsaboutus
These tables generally use bilingual fields such as:
Title_enandTitle_arContent_enandContent_arName_enandName_ar
This confirms a multilingual content model with Arabic and English stored directly in the same rows.
Content-related support tables
Section titled “Content-related support tables”The schema also tracks engagement and moderation through tables such as:
articles_pages_viewsnews_pages_viewslibrary_pages_viewsnews_commentsforum_commentsforum_likes
This shows that the database supports both content publishing and audience interaction.
2. Branches, Services, and Public Discovery
Section titled “2. Branches, Services, and Public Discovery”The public healthcare and service discovery layer is represented through tables such as:
branchesbranches_specialistsservicesservices_categoriessectionsteams-like public information represented through consultant and management-related entities
The branches table stores location-facing information such as:
- multilingual name and address
- weekly schedule and time
- phone
- map coordinates
- ordering and status
This indicates that the branch model is used directly for public website presentation, not only internal operations.
3. Customers and Identity
Section titled “3. Customers and Identity”Customer identity is centered around the customers table.
Important fields in customers include:
- name and email
- password
- phone and verification flags
- role-related flags such as trainer and consultant status
- guest state
- app token and app default mode
Related customer-supporting tables include:
customers_docscustomer_device_tokenscustomer_feedbackcustomer_ticketscustomer_ticket_commentscustomer_change_acc_requestscustomer_wallet
Later migrations also add fields and related entities for NFQT integration and extra identity details, including:
customer_nfqt_infonfqt_nationalitiesnfqt_regionsqualification_levels- national ID additions on
customers
This means the customer domain is broader than simple website login and includes compliance, verification, support, and integration data.
4. Appointments and Public Requests
Section titled “4. Appointments and Public Requests”The appointment entry flow is represented by the appointments table.
Core appointment fields include:
- customer identity or guest-submitted contact details
- specialist, consultant, and branch references
- booking type
- notes
- status
- created timestamp
Later migrations extend this table with:
sourceto distinguish website vs app- richer appointment statuses such as
booked,call_later,inquire_only, andbooking_in_progress appointment_status_logappointment_activities
This shows the appointment system evolved from simple inquiry capture into a richer operational workflow with auditability.
5. Consultation Domain
Section titled “5. Consultation Domain”The consultation domain is one of the largest areas in the schema.
The main structural tables include:
consultantsconsultants_branchesconsultants_categoriesconsultants_scheduleconsultant_contractconsultant_transactionsconsultant_status_logsconsultationsconsultations_categoriesconsultations_scheduleconsultations_timeconsultation_department
The transaction and user-facing execution side includes:
customer_consultationsimmediate_customer_consultationsconsultation_cancel_requestsconsultation_cancel_requests_auditconsultation_action_auditconsultations_reportsconsultation_report_requests_auditconsultation_absence_reportsconsultation_absence_status_audit
The medical and diagnostic side includes:
consultations_diagnosisconsultations_prescriptionsconsultations_prescription_medicinesconsultations_medicinconsultations_medicins_unitsconsultations_units
The psychological assessment side includes:
consultations_psychological_measuresconsultations_psychological_measures_questionsconsultations_psychological_measures_optionsconsultations_psychological_measures_answerconsultations_psychological_questions_evaluation
The intake and supporting data side includes:
customer_case_study_questionscustomer_case_study_answers
Consultation evolution from migrations
Section titled “Consultation evolution from migrations”The migrations show active enhancement of this domain:
- payment transaction IDs added to consultation records
- payment source added as
apporweb - reviewer fields added to
customer_consultations - refund workflow and split refund support added to cancellation requests
- auto-cancel absence reporting introduced
- audit tables added for cancellation, action, and medical report workflows
- performance indexes added for high-traffic consultation activity tables
This is a mature, business-critical domain with both operational and clinical data responsibilities.
6. Courses, Collections, and Subscriptions
Section titled “6. Courses, Collections, and Subscriptions”The e-learning and paid content area is also a major schema domain.
Core catalog tables include:
coursescourses_categoriescourses_classescourses_lessonscourses_lessons_filescollectionscollection_coursestrainerscertificatescertificate_images
Customer learning and subscription tables include:
customer_subscriptionscustomer_subscription_historycustomer_orderscartcustomer_course_certificatescourse_attendancewatch_video
Learning interaction tables include:
courses_commentscourses_homeworkscourses_homework_answerscourses_pages_views
The migration history shows performance optimization around course subscription history and cart-related access patterns, which suggests these tables are used in production-heavy flows.
7. Careers and Applications
Section titled “7. Careers and Applications”The recruitment workflow appears as its own domain with tables such as:
careerscareer_applicationscareer_applicants_status_logscareers_requests
The status enums were expanded over time to support recruitment pipeline stages such as:
newin_progressscheduledcandidateno_show_oncejoined_training
This indicates the website handles real candidate workflow tracking rather than only collecting static CV submissions.
8. Payments, Promotions, and Commerce
Section titled “8. Payments, Promotions, and Commerce”Commerce-related tables are spread across multiple domains and include:
payment_logspayment_response_logspayment_response_log_refernecepayment_settingsinvoicespromocodespromocodes_consultationspromocodes_usagepromo_codespromo_code_usage
The migrations show:
- consultation coupon support
- minimum purchase and maximum discount fields for promocodes
- payment entity naming improvements
- payment source tracking for both consultations and subscriptions
This indicates a shared payment subsystem used by courses, consultations, and potentially other monetized areas.
9. Notifications and Messaging
Section titled “9. Notifications and Messaging”Notification-related tables include:
notificationsnotification_public_sentnotification_templatesnotification_typesnotify_consultant_availability
Later migrations add new notification types and templates for:
- appointments
- medical report approval and rejection
- other operational workflow alerts
This suggests notifications are template-driven and tied closely to product events.
10. Admin and RBAC
Section titled “10. Admin and RBAC”The admin authorization model uses RBAC tables:
rbac_actionsrbac_menusrbac_menu_actionsrbac_roles_permissionsrbac_user_rolesusersusers_roles
Migration inserts also show that new reports and workflow screens are introduced through RBAC menu additions instead of being hardcoded only in the UI.
This means menu visibility and admin access are partially data-driven.
Relationship Patterns
Section titled “Relationship Patterns”Across the schema, the most common relationship pattern is explicit integer foreign-key-style references by naming convention, for example:
Customer_IDConsultant_IDCategory_IDBranch_IDCourse_IDConsultation_ID
The DDL dump appears to rely heavily on application-managed relationships rather than a strongly normalized, foreign-key-enforced relational model throughout the entire database.
In practice, the application logic likely enforces much of the referential behavior.
Important Recent Schema Changes
Section titled “Important Recent Schema Changes”Recent migrations show the product is actively evolving in these areas:
- appointment workflow states and status logs
- consultation cancellation and refund handling
- medical report workflows and auditability
- notification templates and notification types
- NFQT-related customer and user data
- performance indexes on consultation and subscription tables
- content metadata such as
SchemaandTagsfor articles and news
This indicates the schema is still growing and is not static.
Seed and Reference Data Observations
Section titled “Seed and Reference Data Observations”I did not find a dedicated seeder framework or seeder directory in the repository.
Instead, reference and setup data appears to be created through SQL migrations, especially for:
configuration_settingsrbac_menusrbac_actionsrbac_menu_actionsrbac_roles_permissionsnotification_typesnotification_templatesqualification_levelsnfqt_nationalitiesnfqt_regions
This means production and staging bootstrap data likely depends on running SQL migration files in the correct order.
Documentation-Level Interpretation
Section titled “Documentation-Level Interpretation”At documentation level, the current database can be described as:
- one large operational relational database
- shared by website, customer, consultation, education, admin, and API flows
- bilingual at the content layer
- workflow-heavy in consultations and appointments
- increasingly audit-oriented in newer business-critical domains
Key Risk to Keep in Mind
Section titled “Key Risk to Keep in Mind”Because the schema is broad and application-managed, changes in one area can have side effects across multiple modules. The consultation, customer, payment, and notification domains appear especially interconnected and should be treated carefully in future schema changes.