| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- CREATE TABLE "attendance" (
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
- "student_id" uuid,
- "class_id" uuid,
- "section_id" uuid,
- "teacher_id" uuid,
- "date" date NOT NULL,
- "status" varchar(20) NOT NULL,
- "reason" text,
- "created_at" timestamp DEFAULT now()
- );
- --> statement-breakpoint
- CREATE TABLE "classes" (
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
- "name" varchar(100) NOT NULL,
- "code" varchar(20) NOT NULL,
- "period_id" uuid,
- "is_active" boolean DEFAULT true,
- "created_at" timestamp DEFAULT now(),
- "updated_at" timestamp DEFAULT now(),
- CONSTRAINT "classes_code_unique" UNIQUE("code")
- );
- --> statement-breakpoint
- CREATE TABLE "partials" (
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
- "name" varchar(100) NOT NULL,
- "period_id" uuid,
- "is_active" boolean DEFAULT true,
- "created_at" timestamp DEFAULT now(),
- "updated_at" timestamp DEFAULT now()
- );
- --> statement-breakpoint
- CREATE TABLE "periods" (
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
- "name" varchar(100) NOT NULL,
- "start_date" date NOT NULL,
- "end_date" date NOT NULL,
- "is_active" boolean DEFAULT true,
- "created_at" timestamp DEFAULT now(),
- "updated_at" timestamp DEFAULT now()
- );
- --> statement-breakpoint
- CREATE TABLE "sections" (
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
- "name" varchar(50) NOT NULL,
- "class_id" uuid,
- "is_active" boolean DEFAULT true,
- "created_at" timestamp DEFAULT now(),
- "updated_at" timestamp DEFAULT now()
- );
- --> statement-breakpoint
- CREATE TABLE "student_enrollments" (
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
- "student_id" uuid,
- "class_id" uuid,
- "section_id" uuid,
- "is_active" boolean DEFAULT true,
- "created_at" timestamp DEFAULT now()
- );
- --> statement-breakpoint
- CREATE TABLE "teacher_assignments" (
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
- "teacher_id" uuid,
- "class_id" uuid,
- "section_id" uuid,
- "is_active" boolean DEFAULT true,
- "created_at" timestamp DEFAULT now()
- );
- --> statement-breakpoint
- CREATE TABLE "users" (
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
- "email" varchar(255) NOT NULL,
- "password" text NOT NULL,
- "first_name" varchar(100) NOT NULL,
- "last_name" varchar(100) NOT NULL,
- "cedula" varchar(20) NOT NULL,
- "phone" varchar(20),
- "role" varchar(20) NOT NULL,
- "admission_number" varchar(50),
- "is_active" boolean DEFAULT true,
- "created_at" timestamp DEFAULT now(),
- "updated_at" timestamp DEFAULT now(),
- CONSTRAINT "users_email_unique" UNIQUE("email"),
- CONSTRAINT "users_cedula_unique" UNIQUE("cedula")
- );
- --> statement-breakpoint
- ALTER TABLE "attendance" ADD CONSTRAINT "attendance_student_id_users_id_fk" FOREIGN KEY ("student_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "attendance" ADD CONSTRAINT "attendance_class_id_classes_id_fk" FOREIGN KEY ("class_id") REFERENCES "public"."classes"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "attendance" ADD CONSTRAINT "attendance_section_id_sections_id_fk" FOREIGN KEY ("section_id") REFERENCES "public"."sections"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "attendance" ADD CONSTRAINT "attendance_teacher_id_users_id_fk" FOREIGN KEY ("teacher_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "classes" ADD CONSTRAINT "classes_period_id_periods_id_fk" FOREIGN KEY ("period_id") REFERENCES "public"."periods"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "partials" ADD CONSTRAINT "partials_period_id_periods_id_fk" FOREIGN KEY ("period_id") REFERENCES "public"."periods"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "sections" ADD CONSTRAINT "sections_class_id_classes_id_fk" FOREIGN KEY ("class_id") REFERENCES "public"."classes"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "student_enrollments" ADD CONSTRAINT "student_enrollments_student_id_users_id_fk" FOREIGN KEY ("student_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "student_enrollments" ADD CONSTRAINT "student_enrollments_class_id_classes_id_fk" FOREIGN KEY ("class_id") REFERENCES "public"."classes"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "student_enrollments" ADD CONSTRAINT "student_enrollments_section_id_sections_id_fk" FOREIGN KEY ("section_id") REFERENCES "public"."sections"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "teacher_assignments" ADD CONSTRAINT "teacher_assignments_teacher_id_users_id_fk" FOREIGN KEY ("teacher_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "teacher_assignments" ADD CONSTRAINT "teacher_assignments_class_id_classes_id_fk" FOREIGN KEY ("class_id") REFERENCES "public"."classes"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
- ALTER TABLE "teacher_assignments" ADD CONSTRAINT "teacher_assignments_section_id_sections_id_fk" FOREIGN KEY ("section_id") REFERENCES "public"."sections"("id") ON DELETE no action ON UPDATE no action;
|