0000_goofy_obadiah_stane.sql 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. CREATE TABLE "attendance" (
  2. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  3. "student_id" uuid,
  4. "class_id" uuid,
  5. "section_id" uuid,
  6. "teacher_id" uuid,
  7. "date" date NOT NULL,
  8. "status" varchar(20) NOT NULL,
  9. "reason" text,
  10. "created_at" timestamp DEFAULT now()
  11. );
  12. --> statement-breakpoint
  13. CREATE TABLE "classes" (
  14. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  15. "name" varchar(100) NOT NULL,
  16. "code" varchar(20) NOT NULL,
  17. "period_id" uuid,
  18. "is_active" boolean DEFAULT true,
  19. "created_at" timestamp DEFAULT now(),
  20. "updated_at" timestamp DEFAULT now(),
  21. CONSTRAINT "classes_code_unique" UNIQUE("code")
  22. );
  23. --> statement-breakpoint
  24. CREATE TABLE "partials" (
  25. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  26. "name" varchar(100) NOT NULL,
  27. "period_id" uuid,
  28. "is_active" boolean DEFAULT true,
  29. "created_at" timestamp DEFAULT now(),
  30. "updated_at" timestamp DEFAULT now()
  31. );
  32. --> statement-breakpoint
  33. CREATE TABLE "periods" (
  34. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  35. "name" varchar(100) NOT NULL,
  36. "start_date" date NOT NULL,
  37. "end_date" date NOT NULL,
  38. "is_active" boolean DEFAULT true,
  39. "created_at" timestamp DEFAULT now(),
  40. "updated_at" timestamp DEFAULT now()
  41. );
  42. --> statement-breakpoint
  43. CREATE TABLE "sections" (
  44. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  45. "name" varchar(50) NOT NULL,
  46. "class_id" uuid,
  47. "is_active" boolean DEFAULT true,
  48. "created_at" timestamp DEFAULT now(),
  49. "updated_at" timestamp DEFAULT now()
  50. );
  51. --> statement-breakpoint
  52. CREATE TABLE "student_enrollments" (
  53. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  54. "student_id" uuid,
  55. "class_id" uuid,
  56. "section_id" uuid,
  57. "is_active" boolean DEFAULT true,
  58. "created_at" timestamp DEFAULT now()
  59. );
  60. --> statement-breakpoint
  61. CREATE TABLE "teacher_assignments" (
  62. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  63. "teacher_id" uuid,
  64. "class_id" uuid,
  65. "section_id" uuid,
  66. "is_active" boolean DEFAULT true,
  67. "created_at" timestamp DEFAULT now()
  68. );
  69. --> statement-breakpoint
  70. CREATE TABLE "users" (
  71. "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  72. "email" varchar(255) NOT NULL,
  73. "password" text NOT NULL,
  74. "first_name" varchar(100) NOT NULL,
  75. "last_name" varchar(100) NOT NULL,
  76. "cedula" varchar(20) NOT NULL,
  77. "phone" varchar(20),
  78. "role" varchar(20) NOT NULL,
  79. "admission_number" varchar(50),
  80. "is_active" boolean DEFAULT true,
  81. "created_at" timestamp DEFAULT now(),
  82. "updated_at" timestamp DEFAULT now(),
  83. CONSTRAINT "users_email_unique" UNIQUE("email"),
  84. CONSTRAINT "users_cedula_unique" UNIQUE("cedula")
  85. );
  86. --> statement-breakpoint
  87. 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
  88. 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
  89. 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
  90. 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
  91. 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
  92. 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
  93. 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
  94. 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
  95. 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
  96. 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
  97. 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
  98. 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
  99. 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;