CREATE TABLE classroom_compliance_class (
    id INTEGER PRIMARY KEY,
    number INTEGER NOT NULL,
    school_year TEXT NOT NULL,
    user_id INTEGER NOT NULL REFERENCES user(id)
        ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE classroom_compliance_student (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    class_id INTEGER NOT NULL REFERENCES classroom_compliance_class(id)
        ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE classroom_compliance_desk_assignment (
    id INTEGER PRIMARY KEY,
    class_id INTEGER NOT NULL REFERENCES classroom_compliance_class(id)
        ON UPDATE CASCADE ON DELETE CASCADE,
    desk_number INTEGER NOT NULL,
    student_id INTEGER REFERENCES classroom_compliance_student(id)
        ON UPDATE CASCADE ON DELETE SET NULL
);

CREATE TABLE classroom_compliance_entry (
    id INTEGER PRIMARY KEY,
    class_id INTEGER NOT NULL REFERENCES classroom_compliance_class(id)
        ON UPDATE CASCADE ON DELETE CASCADE,
    class_description TEXT NOT NULL,
    student_id INTEGER NOT NULL REFERENCES classroom_compliance_student(id),
    date TEXT NOT NULL,
    created_at INTEGER NOT NULL,
    absent INTEGER NOT NULL DEFAULT 0
);

CREATE TABLE classroom_compliance_entry_phone (
    entry_id INTEGER PRIMARY KEY REFERENCES classroom_compliance_entry(id)
        ON UPDATE CASCADE ON DELETE CASCADE,
    compliant INTEGER NOT NULL DEFAULT 1
);

CREATE TABLE classroom_compliance_entry_behavior (
    entry_id INTEGER PRIMARY KEY REFERENCES classroom_compliance_entry(id)
        ON UPDATE CASCADE ON DELETE CASCADE,
    rating INTEGER NOT NULL,
    comment TEXT
);
