A normalized (3NF) relational design for a children's robotics club, built from the structure of a real CRM export (AlfaCRM): branches and teachers, parents and students, the lead pipeline and contact history, groups and weekly schedules, lessons and attendance, summer camps, tariffs, subscriptions, invoices and payments. 28 tables, 45 one-to-many relationships.
? nullable
TEACHER_SUBJECT, TEACHER_BRANCH, LESSON_TEACHER, CAMP_ENROLLMENT, GROUP_MEMBER), which use composite keys.GROUP_MEMBER keys on (group_id, customer_id, joined_on), so a student can leave a group and rejoin it later.ATTENDANCE has UNIQUE (lesson_id, customer_id); PARENT_PHONE.phone and INVOICE.invoice_no are unique.CHECK; a camp invoice points to the enrolment through the composite foreign key (camp_id, customer_id), so it can only bill a child who is enrolled.CUSTOMER.customer_type IN ('LEAD','CLIENT'); only clients may have a study status.LESSON.status IN ('PLANNED','HELD','CANCELLED'); lesson_type IN ('GROUP','TRIAL','INDIVIDUAL').CONTACT_LOG.outcome IN ('ANSWERED','NO_ANSWER','REJECTED','MESSAGE_SENT','INBOUND').CHAR(1) IN ('Y','N'); date pairs are ordered (end ≥ start); prices and amounts are never negative.'HH24:MI' text checked with REGEXP_LIKE, so time_to > time_from is a valid comparison.LESSON.subject_id is a fact of the lesson, not of the group: groups rotate modules (programming, 3D modelling, electronics).LESSON.branch_id is needed for lessons without a group; trigger TRG_LESSON_CONSISTENCY keeps it equal to the group's branch and checks the room and schedule.SUBSCRIPTION.price and ATTENDANCE.amount_charged freeze prices at the time of sale; the remaining credit is computed, never stored.TRG_ATTENDANCE_VALIDATE, TRG_INVOICE_CONSISTENCY and TRG_PAYMENT_SETTLES_INVOICE.LESSON.group_id and schedule_id are null for trial and one-off lessons.ATTENDANCE.subscription_id is null for free lessons; absence_reason_id only applies when is_present = 'N'.CUSTOMER.lead_status_id is used by leads, study_status_id by students; reject_reason_id only once someone leaves.TARIFF.branch_id is null when a tariff applies to every branch.PARENT_PHONE (1NF).LESSON_TEACHER, ATTENDANCE (1NF).PARENT (3NF).CONTACT_LOG, INVOICE, REJECT_REASON.| Parent (one) | Min..max | Child side | Child (many) | Foreign key |
|---|---|---|---|---|
ABSENCE_REASON | 0..1 | 0..N | ATTENDANCE | ATTENDANCE.absence_reason_id |
BRANCH | 1 | 0..N | CAMP_SESSION | CAMP_SESSION.branch_id |
BRANCH | 1 | 0..N | CUSTOMER | CUSTOMER.branch_id |
BRANCH | 1 | 0..N | LESSON | LESSON.branch_id |
BRANCH | 1 | 0..N | PAYMENT | PAYMENT.branch_id |
BRANCH | 1 | 0..N | ROOM | ROOM.branch_id |
BRANCH | 1 | 0..N | STUDY_GROUP | STUDY_GROUP.branch_id |
BRANCH | 0..1 | 0..N | TARIFF | TARIFF.branch_id |
BRANCH | 1 | 0..N | TEACHER_BRANCH | TEACHER_BRANCH.branch_id |
CAMP_ENROLLMENT | 0..1 | 0..N | INVOICE | INVOICE.(camp_id, customer_id) |
CAMP_SESSION | 1 | 0..N | CAMP_ENROLLMENT | CAMP_ENROLLMENT.camp_id |
CONTACT_CHANNEL | 1 | 0..N | CONTACT_LOG | CONTACT_LOG.channel_id |
CUSTOMER | 1 | 0..N | ATTENDANCE | ATTENDANCE.customer_id |
CUSTOMER | 1 | 0..N | CAMP_ENROLLMENT | CAMP_ENROLLMENT.customer_id |
CUSTOMER | 1 | 0..N | CONTACT_LOG | CONTACT_LOG.customer_id |
CUSTOMER | 1 | 0..N | GROUP_MEMBER | GROUP_MEMBER.customer_id |
CUSTOMER | 1 | 0..N | INVOICE | INVOICE.customer_id |
CUSTOMER | 1 | 0..N | PAYMENT | PAYMENT.customer_id |
CUSTOMER | 1 | 0..N | SUBSCRIPTION | SUBSCRIPTION.customer_id |
INVOICE | 0..1 | 0..N | PAYMENT | PAYMENT.invoice_id |
LEAD_SOURCE | 0..1 | 0..N | CUSTOMER | CUSTOMER.lead_source_id |
LEAD_STATUS | 0..1 | 0..N | CUSTOMER | CUSTOMER.lead_status_id |
LESSON | 1 | 0..N | ATTENDANCE | ATTENDANCE.lesson_id |
LESSON | 1 | 0..N | LESSON_TEACHER | LESSON_TEACHER.lesson_id |
PARENT | 0..1 | 0..N | CUSTOMER | CUSTOMER.parent_id |
PARENT | 1 | 0..N | PARENT_PHONE | PARENT_PHONE.parent_id |
REGULAR_SCHEDULE | 0..1 | 0..N | LESSON | LESSON.schedule_id |
REJECT_REASON | 0..1 | 0..N | CUSTOMER | CUSTOMER.reject_reason_id |
ROOM | 0..1 | 0..N | LESSON | LESSON.room_id |
ROOM | 0..1 | 0..N | REGULAR_SCHEDULE | REGULAR_SCHEDULE.room_id |
STUDY_GROUP | 1 | 0..N | GROUP_MEMBER | GROUP_MEMBER.group_id |
STUDY_GROUP | 0..1 | 0..N | LESSON | LESSON.group_id |
STUDY_GROUP | 1 | 0..N | REGULAR_SCHEDULE | REGULAR_SCHEDULE.group_id |
STUDY_STATUS | 0..1 | 0..N | CUSTOMER | CUSTOMER.study_status_id |
SUBJECT | 1 | 0..N | LESSON | LESSON.subject_id |
SUBJECT | 1 | 0..N | STUDY_GROUP | STUDY_GROUP.subject_id |
SUBJECT | 1 | 0..N | TEACHER_SUBJECT | TEACHER_SUBJECT.subject_id |
SUBSCRIPTION | 0..1 | 0..N | ATTENDANCE | ATTENDANCE.subscription_id |
SUBSCRIPTION | 0..1 | 0..N | INVOICE | INVOICE.subscription_id |
TARIFF | 1 | 0..N | CAMP_SESSION | CAMP_SESSION.tariff_id |
TARIFF | 1 | 0..N | SUBSCRIPTION | SUBSCRIPTION.tariff_id |
TEACHER | 1 | 0..N | LESSON_TEACHER | LESSON_TEACHER.teacher_id |
TEACHER | 1 | 0..N | REGULAR_SCHEDULE | REGULAR_SCHEDULE.teacher_id |
TEACHER | 1 | 0..N | TEACHER_BRANCH | TEACHER_BRANCH.teacher_id |
TEACHER | 1 | 0..N | TEACHER_SUBJECT | TEACHER_SUBJECT.teacher_id |