2024-12-17 03:22:56 +00:00
|
|
|
CREATE TABLE classroom_compliance_class (
|
2025-01-23 17:10:32 +00:00
|
|
|
id BIGSERIAL PRIMARY KEY,
|
|
|
|
number INT NOT NULL
|
|
|
|
CONSTRAINT class_number_check CHECK (number > 0),
|
|
|
|
school_year VARCHAR(9) NOT NULL,
|
|
|
|
user_id BIGINT NOT NULL
|
|
|
|
REFERENCES auth_user(id)
|
|
|
|
ON UPDATE CASCADE ON DELETE CASCADE
|
2024-12-17 03:22:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE classroom_compliance_student (
|
2025-01-23 17:10:32 +00:00
|
|
|
id BIGSERIAL PRIMARY KEY,
|
|
|
|
name VARCHAR(255) NOT NULL,
|
|
|
|
class_id BIGINT NOT NULL
|
|
|
|
REFERENCES classroom_compliance_class(id)
|
|
|
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
|
|
|
desk_number INT NOT NULL DEFAULT 0,
|
|
|
|
removed BOOLEAN NOT NULL DEFAULT FALSE
|
2024-12-17 03:22:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE classroom_compliance_entry (
|
2025-01-23 17:10:32 +00:00
|
|
|
id BIGSERIAL PRIMARY KEY,
|
|
|
|
class_id BIGINT NOT NULL
|
|
|
|
REFERENCES classroom_compliance_class(id)
|
|
|
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
|
|
|
student_id BIGINT NOT NULL
|
|
|
|
REFERENCES classroom_compliance_student(id)
|
|
|
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
|
|
|
date DATE NOT NULL,
|
|
|
|
created_at BIGINT NOT NULL
|
|
|
|
DEFAULT EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000,
|
|
|
|
absent BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
comment VARCHAR(2000) NOT NULL DEFAULT '',
|
|
|
|
phone_compliant BOOLEAN NULL DEFAULT NULL,
|
|
|
|
behavior_rating INT NULL DEFAULT NULL,
|
|
|
|
CONSTRAINT absence_nulls_check CHECK (
|
|
|
|
(absent AND phone_compliant IS NULL AND behavior_rating IS NULL) OR
|
|
|
|
(NOT absent AND phone_compliant IS NOT NULL AND behavior_rating IS NOT NULL)
|
|
|
|
)
|
2024-12-17 03:22:56 +00:00
|
|
|
);
|