-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_creation.sql
More file actions
1524 lines (1304 loc) · 71.2 KB
/
database_creation.sql
File metadata and controls
1524 lines (1304 loc) · 71.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Create identities table
CREATE TABLE identities (
id VARCHAR(255) NOT NULL,
type VARCHAR(255) NOT NULL,
number VARCHAR(255) NOT NULL,
issued_by VARCHAR(255) NOT NULL,
issued_date DATE NOT NULL,
expiry_date DATE NOT NULL,
has_chip BOOLEAN,
country VARCHAR(255),
notes VARCHAR(255),
CONSTRAINT pk_identities PRIMARY KEY (id)
);
CREATE TABLE addresses (
id VARCHAR(255) NOT NULL,
street VARCHAR(255),
ward VARCHAR(255),
district VARCHAR(255),
province VARCHAR(255),
country VARCHAR(255),
CONSTRAINT pk_addresses PRIMARY KEY (id)
);
CREATE TABLE settings (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name VARCHAR(255) NOT NULL,
details TEXT,
CONSTRAINT uc_settings_name UNIQUE (name)
);
-- Create faculties table
CREATE TABLE faculties (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name VARCHAR(255) NOT NULL UNIQUE,
deleted_at DATE
);
-- Create programs table
CREATE TABLE programs (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name VARCHAR(255) NOT NULL UNIQUE,
deleted_at DATE
);
-- Create statuses table
CREATE TABLE statuses (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name VARCHAR(255) NOT NULL UNIQUE,
deleted_at DATE
);
-- Create students table
CREATE TABLE students (
id VARCHAR(255) NOT NULL,
student_id VARCHAR(255),
name VARCHAR(255) NOT NULL,
dob DATE,
gender VARCHAR(255) NOT NULL,
faculty_id INTEGER NOT NULL,
school_year INTEGER,
program_id INTEGER NOT NULL,
email VARCHAR(255) NOT NULL,
phone VARCHAR(12) NOT NULL,
status_id INTEGER NOT NULL,
permanent_address_id VARCHAR(255),
temporary_address_id VARCHAR(255),
mailing_address_id VARCHAR(255),
identity_id VARCHAR(255),
CONSTRAINT pk_students PRIMARY KEY (id),
deleted_at DATE
);
CREATE TABLE status_transitions (
from_status_id INTEGER NOT NULL,
to_status_id INTEGER NOT NULL,
CONSTRAINT pk_status_transitions PRIMARY KEY (from_status_id, to_status_id),
CONSTRAINT fk_status_transitions_from_status FOREIGN KEY (from_status_id) REFERENCES statuses (id),
CONSTRAINT fk_status_transitions_to_status FOREIGN KEY (to_status_id) REFERENCES statuses (id)
);
CREATE TABLE subjects (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name VARCHAR(255) NOT NULL,
code VARCHAR(50) NOT NULL UNIQUE,
description TEXT,
is_active BOOLEAN DEFAULT TRUE,
credits INTEGER NOT NULL,
faculty_id INTEGER,
deleted_at DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_subjects_faculty FOREIGN KEY (faculty_id) REFERENCES faculties (id)
);
CREATE TABLE subject_prerequisites (
subject_id INTEGER NOT NULL,
prerequisite_id INTEGER NOT NULL,
CONSTRAINT pk_subject_prerequisites PRIMARY KEY (subject_id, prerequisite_id),
CONSTRAINT fk_subject_prerequisites_subject FOREIGN KEY (subject_id) REFERENCES subjects (id),
CONSTRAINT fk_subject_prerequisites_prerequisite FOREIGN KEY (prerequisite_id) REFERENCES subjects (id)
);
-- Create courses table
CREATE TABLE courses (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
code VARCHAR(50) NOT NULL,
year INTEGER NOT NULL,
semester INTEGER NOT NULL,
lecturer VARCHAR(255) NOT NULL,
max_student INTEGER NOT NULL,
room VARCHAR(50) NOT NULL,
schedule VARCHAR(50) NOT NULL,
start_date DATE NOT NULL,
program_id INTEGER NOT NULL,
subject_id INTEGER NOT NULL,
CONSTRAINT fk_courses_program FOREIGN KEY (program_id) REFERENCES programs (id),
CONSTRAINT fk_courses_subject FOREIGN KEY (subject_id) REFERENCES subjects (id),
CONSTRAINT uc_courses_code UNIQUE (code, subject_id)
);
-- Create enrollments table
CREATE TABLE enrollments (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
student_id VARCHAR(255) NOT NULL,
course_id INTEGER NOT NULL,
score_id INTEGER,
CONSTRAINT fk_enrollments_student FOREIGN KEY (student_id) REFERENCES students (id),
CONSTRAINT fk_enrollments_course FOREIGN KEY (course_id) REFERENCES courses (id),
CONSTRAINT uc_enrollments_student_course UNIQUE (student_id, course_id)
);
-- Create histories table to track enrollment actions
CREATE TABLE histories (
id VARCHAR(255) PRIMARY KEY,
action_type VARCHAR(50) NOT NULL, -- ENROLLED or DELETED
created_at TIMESTAMP NOT NULL,
student_id VARCHAR(255) NOT NULL,
course_id INTEGER NOT NULL,
CONSTRAINT fk_histories_student FOREIGN KEY (student_id) REFERENCES students (id),
CONSTRAINT fk_histories_course FOREIGN KEY (course_id) REFERENCES courses (id)
);
CREATE TABLE scores
(
id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL,
grade VARCHAR(255),
gpa DOUBLE PRECISION,
CONSTRAINT pk_scores PRIMARY KEY (id)
);
-- Add constraints to students table
ALTER TABLE students
ADD CONSTRAINT uc_students_email UNIQUE (email);
ALTER TABLE students
ADD CONSTRAINT uc_students_mailing_address UNIQUE (mailing_address_id);
ALTER TABLE students
ADD CONSTRAINT uc_students_permanent_address UNIQUE (permanent_address_id);
ALTER TABLE students
ADD CONSTRAINT uc_students_phone UNIQUE (phone);
ALTER TABLE students
ADD CONSTRAINT uc_students_student UNIQUE (student_id);
ALTER TABLE students
ADD CONSTRAINT uc_students_temporary_address UNIQUE (temporary_address_id);
-- Add foreign key constraints
ALTER TABLE students
ADD CONSTRAINT FK_STUDENTS_ON_FACULTY FOREIGN KEY (faculty_id) REFERENCES faculties (id);
ALTER TABLE students
ADD CONSTRAINT FK_STUDENTS_ON_PROGRAM FOREIGN KEY (program_id) REFERENCES programs (id);
ALTER TABLE students
ADD CONSTRAINT FK_STUDENTS_ON_STATUS FOREIGN KEY (status_id) REFERENCES statuses (id);
ALTER TABLE students
ADD CONSTRAINT FK_STUDENTS_ON_MAILING_ADDRESS FOREIGN KEY (mailing_address_id) REFERENCES addresses (id);
ALTER TABLE students
ADD CONSTRAINT FK_STUDENTS_ON_PERMANENT_ADDRESS FOREIGN KEY (permanent_address_id) REFERENCES addresses (id);
ALTER TABLE students
ADD CONSTRAINT FK_STUDENTS_ON_TEMPORARY_ADDRESS FOREIGN KEY (temporary_address_id) REFERENCES addresses (id);
ALTER TABLE students
ADD CONSTRAINT FK_STUDENTS_ON_IDENTITY FOREIGN KEY (identity_id) REFERENCES identities (id);
ALTER TABLE students
ADD CONSTRAINT uc_students_identity UNIQUE (identity_id);
-- Add foreign key constraints for enrollments
ALTER TABLE enrollments
ADD CONSTRAINT uc_enrollments_score UNIQUE (score_id);
ALTER TABLE enrollments
ADD CONSTRAINT FK_ENROLLMENTS_ON_COURSE FOREIGN KEY (course_id) REFERENCES courses (id);
ALTER TABLE enrollments
ADD CONSTRAINT FK_ENROLLMENTS_ON_STUDENT FOREIGN KEY (student_id) REFERENCES students (id);
ALTER TABLE enrollments
ADD CONSTRAINT FK_ENROLLMENTS_ON_score FOREIGN KEY (score_id) REFERENCES scores (id);
-- Add foreign key constraints for histories
ALTER TABLE histories
ADD CONSTRAINT FK_HISTORIES_ON_COURSE FOREIGN KEY (course_id) REFERENCES courses (id);
ALTER TABLE histories
ADD CONSTRAINT FK_HISTORIES_ON_STUDENT FOREIGN KEY (student_id) REFERENCES students (id);
-- Insert settings records
INSERT INTO settings (name, details) VALUES
('phonenumber', '["VN"]'),
('email', '@student.hcmus.edu.vn'),
('failinggrade', '2.0'),
('adjustmentduration', '10');
-- Seed faculties data based on the existing student data (uppercase)
INSERT INTO faculties (name) VALUES
('Faculty of Business English'),
('Faculty of Law'),
('Faculty of Japanese'),
('Faculty of French');
-- Seed programs data based on the existing student data (uppercase)
INSERT INTO programs (name) VALUES
('Business Administration'),
('Criminal Justice'),
('Japanese Literature'),
('French Studies'),
('International Business'),
('Japanese Culture'),
('Corporate Law'),
('French Language'),
('Japanese Economics'),
('Business Communication');
-- Seed statuses data based on the existing student data (uppercase)
INSERT INTO statuses (name) VALUES
('Studying'),
('Graduated'),
('Suspended'),
('Dropped');
-- Insert sample identity data
INSERT INTO identities (id, type, number, issued_by, issued_date, expiry_date, has_chip, country, notes)
VALUES
-- Chip_Card (CCCD) examples - 12 digits
('ID001', 'Chip Card', '123456789012', 'Ministry of Public Security', '2018-05-10', '2028-05-10', true, 'Vietnam', 'Citizen Identity Card with Chip'),
('ID004', 'Chip Card', '234567891023', 'Ministry of Public Security', '2021-01-05', '2031-01-05', true, 'Vietnam', NULL),
('ID006', 'Chip Card', '345678912034', 'Ministry of Public Security', '2019-07-14', '2029-07-14', true, 'Vietnam', NULL),
('ID009', 'Chip Card', '456789123045', 'Ministry of Public Security', '2021-06-17', '2031-06-17', true, 'Vietnam', NULL),
-- Identity_Card (CMND) examples - 9 digits
('ID003', 'Identity Card', '456789123', 'Police Department', '2020-03-22', '2025-03-22', false, 'Vietnam', 'Old ID card'),
('ID005', 'Identity Card', '567891234', 'Police Department', '2017-11-30', '2027-11-30', false, 'Vietnam', NULL),
('ID007', 'Identity Card', '678912345', 'Police Department', '2022-09-08', '2027-09-08', false, 'Vietnam', NULL),
-- Passport examples - 2 uppercase letters followed by 7 digits
('ID002', 'Passport', 'AB1234567', 'Immigration Department', '2019-08-15', '2029-08-15', false, 'Vietnam', 'International travel document'),
('ID008', 'Passport', 'CD2345678', 'Immigration Department', '2020-04-25', '2030-04-25', false, 'Vietnam', NULL),
('ID010', 'Passport', 'EF3456789', 'Immigration Department', '2018-12-03', '2028-12-03', false, 'Vietnam', 'Diplomatic passport');
-- Insert addresses with Ward and Province data
INSERT INTO addresses (id, street, ward, district, province, country)
VALUES
-- Permanent addresses
('PERM001', '123 Main Street', 'Thanh Cong', 'Ba Dinh', 'Hanoi', 'Vietnam'),
('PERM002', '456 Oak Avenue', 'Ben Nghe', 'District 1', 'Ho Chi Minh City', 'Vietnam'),
('PERM003', '789 Pine Road', 'Hai Chau', 'Hai Chau', 'Da Nang', 'Vietnam'),
('PERM004', '321 Maple Lane', 'Thac Gian', 'Thanh Khe', 'Da Nang', 'Vietnam'),
('PERM005', '654 Elm Street', 'Phuoc My', 'Son Tra', 'Da Nang', 'Vietnam'),
('PERM006', '987 Cedar Avenue', 'Tan Dinh', 'District 1', 'Ho Chi Minh City', 'Vietnam'),
('PERM007', '246 Birch Boulevard', 'Truc Bach', 'Ba Dinh', 'Hanoi', 'Vietnam'),
('PERM008', '135 Spruce Drive', 'Pham Ngu Lao', 'District 1', 'Ho Chi Minh City', 'Vietnam'),
('PERM009', '864 Willow Way', 'Cau Giay', 'Cau Giay', 'Hanoi', 'Vietnam'),
('PERM010', '753 Aspen Place', 'Vinh Trung', 'Thanh Khe', 'Da Nang', 'Vietnam'),
-- Temporary addresses
('TEMP001', '123 Main Street', 'Thanh Cong', 'Ba Dinh', 'Hanoi', 'Vietnam'),
('TEMP002', '456 Oak Avenue', 'Ben Nghe', 'District 1', 'Ho Chi Minh City', 'Vietnam'),
('TEMP003', '789 Pine Road', 'An Hai Bac', 'Son Tra', 'Da Nang', 'Vietnam'),
('TEMP004', '321 Maple Lane', 'Thao Dien', 'District 2', 'Ho Chi Minh City', 'Vietnam'),
('TEMP005', '654 Elm Street', 'Lang Ha', 'Dong Da', 'Hanoi', 'Vietnam'),
('TEMP006', '987 Cedar Avenue', 'Tan Dinh', 'District 1', 'Ho Chi Minh City', 'Vietnam'),
('TEMP007', '246 Birch Boulevard', 'Nguyen Thai Binh', 'District 1', 'Ho Chi Minh City', 'Vietnam'),
('TEMP008', '135 Spruce Drive', 'Pham Ngu Lao', 'District 1', 'Ho Chi Minh City', 'Vietnam'),
('TEMP009', '864 Willow Way', 'Linh Trung', 'Thu Duc', 'Ho Chi Minh City', 'Vietnam'),
('TEMP010', '753 Aspen Place', 'My An', 'Ngu Hanh Son', 'Da Nang', 'Vietnam'),
-- Mailing addresses
('MAIL001', '123 Main Street', 'Thanh Cong', 'Ba Dinh', 'Hanoi', 'Vietnam'),
('MAIL002', '456 Oak Avenue', 'Ben Nghe', 'District 1', 'Ho Chi Minh City', 'Vietnam'),
('MAIL003', '789 Pine Road', 'Hai Chau', 'Hai Chau', 'Da Nang', 'Vietnam'),
('MAIL004', '321 Maple Lane', 'Thao Dien', 'District 2', 'Ho Chi Minh City', 'Vietnam'),
('MAIL005', '654 Elm Street', 'Lang Ha', 'Dong Da', 'Hanoi', 'Vietnam'),
('MAIL006', '987 Cedar Avenue', 'Tan Dinh', 'District 1', 'Ho Chi Minh City', 'Vietnam'),
('MAIL007', '246 Birch Boulevard', 'Truc Bach', 'Ba Dinh', 'Hanoi', 'Vietnam'),
('MAIL008', '135 Spruce Drive', 'Pham Ngu Lao', 'District 1', 'Ho Chi Minh City', 'Vietnam'),
('MAIL009', '864 Willow Way', 'Cau Giay', 'Cau Giay', 'Hanoi', 'Vietnam'),
('MAIL010', '753 Aspen Place', 'My An', 'Ngu Hanh Son', 'Da Nang', 'Vietnam');
-- From 'Studying' (1) status
INSERT INTO status_transitions (from_status_id, to_status_id) VALUES
(1, 2), -- Studying -> Graduated
(1, 3), -- Studying -> Suspended
(1, 4); -- Studying -> Dropped
-- From 'Suspended' (3) status
INSERT INTO status_transitions (from_status_id, to_status_id) VALUES
(3, 1), -- Suspended -> Studying (reinstatement)
(3, 4); -- Suspended -> Dropped
INSERT INTO students (
id,
student_id,
name,
dob,
gender,
faculty_id,
school_year,
program_id,
email,
phone,
status_id,
permanent_address_id,
temporary_address_id,
mailing_address_id,
identity_id
) VALUES
-- Student 1
(
'ST001_ID',
'ST001',
'John Smith',
'2000-05-15',
'Male',
1, -- Faculty of Business English
3,
1, -- Business Administration
'john.smith@student.hcmus.edu.vn',
'+84903456789',
1, -- Studying
'PERM001',
'TEMP001',
'MAIL001',
'ID001'
),
-- Student 2
(
'ST002_ID',
'ST002',
'Emily Johnson',
'2001-08-22',
'Female',
2, -- Faculty of Law
2,
2, -- Criminal Justice
'emily.johnson@student.hcmus.edu.vn',
'+84987654321',
1, -- studying
'PERM002',
'TEMP002',
'MAIL002',
'ID002'
),
-- Student 3
(
'ST003_ID',
'ST003',
'Michael Brown',
'1999-03-10',
'Male',
3, -- Faculty of Japanese
4,
3, -- Japanese Literature
'michael.brown@student.hcmus.edu.vn',
'+84367891234',
2, -- Graduated
'PERM003',
'TEMP003',
'MAIL003',
'ID003'
),
-- Student 4
(
'ST004_ID',
'ST004',
'Sarah Davis',
'2002-01-30',
'Female',
4, -- Faculty of French
1,
4, -- French Studies
'sarah.davis@student.hcmus.edu.vn',
'+84345678912',
1, -- studying
'PERM004',
'TEMP004',
'MAIL004',
'ID004'
),
-- Student 5
(
'ST005_ID',
'ST005',
'David Wilson',
'2000-11-05',
'Male',
1, -- Faculty of Business English
3,
5, -- International Business
'david.wilson@student.hcmus.edu.vn',
'+84778912345',
3, -- Suspended
'PERM005',
'TEMP005',
'MAIL005',
'ID005'
),
-- Student 6
(
'ST006_ID',
'ST006',
'Jennifer Taylor',
'2001-07-19',
'Female',
3, -- Faculty of Japanese
2,
6, -- Japanese Culture
'jennifer.taylor@student.hcmus.edu.vn',
'+84934567891',
1, -- studying
'PERM006',
'TEMP006',
'MAIL006',
'ID006'
),
-- Student 7
(
'ST007_ID',
'ST007',
'James Anderson',
'1999-09-25',
'Male',
2, -- Faculty of Law
4,
7, -- Corporate Law
'james.anderson@student.hcmus.edu.vn',
'+84791234567',
1, -- studying
'PERM007',
'TEMP007',
'MAIL007',
'ID007'
),
-- Student 8
(
'ST008_ID',
'ST008',
'Linda Martinez',
'2002-04-12',
'Female',
4, -- Faculty of French
1,
8, -- French Language
'linda.martinez@student.hcmus.edu.vn',
'+84796789123',
4, -- Dropped
'PERM008',
'TEMP008',
'MAIL008',
'ID008'
),
-- Student 9
(
'ST009_ID',
'ST009',
'Robert Thompson',
'2000-06-28',
'Male',
3, -- Faculty of Japanese
3,
9, -- Japanese Economics
'robert.thompson@student.hcmus.edu.vn',
'+84789123456',
1, -- studying
'PERM009',
'TEMP009',
'MAIL009',
'ID009'
),
-- Student 10
(
'ST010_ID',
'ST010',
'Elizabeth Garcia',
'2001-12-07',
'Female',
1, -- Faculty of Business English
2,
10, -- Business Communication
'elizabeth.garcia@student.hcmus.edu.vn',
'+84912345678',
1, -- studying
'PERM010',
'TEMP010',
'MAIL010',
'ID010'
);
-- Insert sample subjects
INSERT INTO subjects (name, code, description, credits, faculty_id) VALUES
-- Computer Science subjects
('Introduction to Computer Science', 'CS101', 'A basic introduction to computer science principles', 3, 1),
('Data Structures and Algorithms', 'CS201', 'Study of data structures and fundamental algorithms', 4, 1),
('Database Management Systems', 'CS301', 'Design and implementation of database systems', 3, 1),
('Operating Systems', 'CS302', 'Principles of operating systems design and implementation', 3, 1),
('Software Engineering', 'CS401', 'Software development life cycle, project management, and best practices', 4, 1),
-- Mathematics subjects
('Calculus I', 'MATH101', 'Limits, derivatives, and basic integration', 3, 2),
('Calculus II', 'MATH102', 'Integration techniques, series, and parametric equations', 3, 2),
('Linear Algebra', 'MATH201', 'Vector spaces, matrices, and linear transformations', 3, 2),
('Differential Equations', 'MATH301', 'Ordinary differential equations and applications', 3, 2),
('Advanced Mathematics', 'MATH401', 'Advanced topics in mathematics including calculus and linear algebra', 4, 2),
-- Physics subjects
('Introduction to Physics', 'PHYS101', 'Basic principles of physics and mechanics', 3, 3),
('Electricity and Magnetism', 'PHYS201', 'Principles of electricity, magnetism, and electromagnetic waves', 4, 3),
('Thermodynamics', 'PHYS301', 'Laws of thermodynamics and statistical mechanics', 3, 3),
-- Business subjects
('Introduction to Business', 'BUS101', 'Basic principles of business and entrepreneurship', 3, 4),
('Marketing Principles', 'BUS201', 'Core concepts of marketing and consumer behavior', 3, 4);
-- Add prerequisites relationships
-- CS201 requires CS101
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES (2, 1);
-- CS301 requires CS101 and CS201
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES (3, 1), (3, 2);
-- CS302 requires CS101
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES (4, 1);
-- CS401 requires CS201, CS301, and CS302
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES (5, 2), (5, 3), (5, 4);
-- MATH102 requires MATH101
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES (7, 6);
-- MATH301 requires MATH102 and MATH201
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES (9, 7), (9, 8);
-- MATH401 requires MATH301
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES (10, 9);
-- PHYS201 requires PHYS101 and MATH101
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES (12, 11), (12, 6);
-- PHYS301 requires PHYS201
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES (13, 12);
-- BUS201 requires BUS101
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES (15, 14);
-- Add sample course data
INSERT INTO courses (code, year, semester, lecturer, max_student, room, schedule, start_date, program_id, subject_id) VALUES
-- Computer Science Courses
('CS101_01', 2025, 1, 'Dr. John Smith', 40, 'A101', 'T2(3-6)', '2025-04-15', 1, 1),
('CS101_02', 2025, 1, 'Dr. Sarah Johnson', 35, 'B202', 'T4(1-4)', '2025-04-15', 1, 1),
('CS201_01', 2025, 1, 'Dr. Emily Chen', 45, 'A105', 'T5(4-7)', '2025-04-17', 1, 2),
('CS301_01', 2025, 1, 'Prof. Robert Davis', 30, 'C303', 'T3(1-4)', '2025-04-16', 1, 3),
('CS302_01', 2025, 2, 'Dr. Michael Wilson', 25, 'A203', 'T6(3-6)', '2025-06-15', 1, 4),
-- Mathematics Courses
( 'MATH101_01', 2025, 1, 'Dr. Jennifer White', 50, 'D404', 'T2(8-11)', '2025-01-14', 2, 6),
( 'MATH201_01', 2025, 1, 'Prof. David Brown', 40, 'E501', 'T4(6-9)', '2025-01-16', 2, 8),
( 'MATH301_01', 2025, 2, 'Prof. David Williams', 30, 'C303', 'T3(6-9)', '2025-06-10', 2, 9),
-- Physics Courses
( 'PHYS101_01', 2025, 1, 'Prof. Michael Brown', 50, 'D404', 'T6(1-4)', '2025-01-18', 3, 11),
( 'PHYS201_01', 2025, 2, 'Dr. Elizabeth Taylor', 35, 'B205', 'T5(8-11)', '2025-06-12', 3, 12),
-- Business Courses
( 'BUS101_01', 2025, 1, 'Prof. Catherine Jones', 60, 'F601', 'T3(3-6)', '2025-01-15', 4, 14),
( 'BUS201_01', 2025, 2, 'Dr. James Anderson', 45, 'E505', 'T2(1-4)', '2025-06-14', 4, 15);
-- Insert sample enrollment data (students enrolling in courses)
INSERT INTO enrollments (student_id, course_id) VALUES
-- Student 1 (John Smith) enrolled in 3 courses
('ST001_ID', 1), -- Intro to Computer Science
('ST001_ID', 6), -- Calculus I
('ST001_ID', 11), -- Intro to Business
-- Student 2 (Emily Johnson) enrolled in 2 courses
('ST002_ID', 2), -- Another CS101 section
('ST002_ID', 9), -- Physics
-- Student 3 (Michael Brown) - graduated student
('ST003_ID', 3), -- Data Structures
('ST003_ID', 7), -- Linear Algebra
-- Student 4 (Sarah Davis)
('ST004_ID', 4), -- Database Management
('ST004_ID', 10), -- Electricity and Magnetism
-- Student 6 (Jennifer Taylor)
('ST006_ID', 5), -- Operating Systems
('ST006_ID', 8), -- Differential Equations
-- Student 7 (James Anderson)
('ST007_ID', 12), -- Marketing Principles
-- Student 9 (Robert Thompson)
('ST009_ID', 1), -- Intro to Computer Science (same as Student 1)
('ST009_ID', 3); -- Data Structures (same as Student 3)
-- Insert enrollment enrollmentHistory records (these would typically be generated automatically)
INSERT INTO histories (id, action_type, created_at, student_id, course_id) VALUES
-- Enrollment actions
('hist_001', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '10 days', 'ST001_ID', 1),
('hist_002', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '10 days', 'ST001_ID', 6),
('hist_003', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '9 days', 'ST001_ID', 11),
('hist_004', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '8 days', 'ST002_ID', 2),
('hist_005', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '8 days', 'ST002_ID', 9),
('hist_006', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '15 days', 'ST003_ID', 3),
('hist_007', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '15 days', 'ST003_ID', 7),
('hist_008', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '7 days', 'ST004_ID', 4),
('hist_009', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '7 days', 'ST004_ID', 10),
('hist_010', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '6 days', 'ST006_ID', 5),
('hist_011', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '6 days', 'ST006_ID', 8),
('hist_012', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '5 days', 'ST007_ID', 12),
('hist_013', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '5 days', 'ST009_ID', 1),
('hist_014', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '5 days', 'ST009_ID', 3),
-- Some enrollment deletions/drops
('hist_015', 'DELETED', CURRENT_TIMESTAMP - INTERVAL '2 days', 'ST001_ID', 6),
('hist_016', 'DELETED', CURRENT_TIMESTAMP - INTERVAL '3 days', 'ST002_ID', 9),
('hist_017', 'DELETED', CURRENT_TIMESTAMP - INTERVAL '1 day', 'ST004_ID', 10),
-- Re-enrollments
('hist_018', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '1 day', 'ST001_ID', 6);
-- Now delete the enrollments that correspond to the DELETED actions
DELETE FROM enrollments WHERE student_id = 'ST001_ID' AND course_id = 6;
DELETE FROM enrollments WHERE student_id = 'ST002_ID' AND course_id = 9;
DELETE FROM enrollments WHERE student_id = 'ST004_ID' AND course_id = 10;
-- And add back the one re-enrollment
INSERT INTO enrollments (student_id, course_id) VALUES
('ST001_ID', 6);
-- Insert unique scores for each enrollment
-- Student 1 (John Smith)
INSERT INTO scores (grade, gpa) VALUES ('A', 4.0); -- CS101
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST001_ID' AND course_id = 1;
INSERT INTO scores (grade, gpa) VALUES ('B+', 3.3); -- Calculus I (re-enrolled)
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST001_ID' AND course_id = 6;
INSERT INTO scores (grade, gpa) VALUES ('A-', 3.7); -- Intro to Business
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST001_ID' AND course_id = 11;
-- Student 2 (Emily Johnson)
INSERT INTO scores (grade, gpa) VALUES ('B', 3.0); -- CS101 (different section)
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST002_ID' AND course_id = 2;
-- Student 3 (Michael Brown) - graduated with good grades
INSERT INTO scores (grade, gpa) VALUES ('A+', 4.0); -- Data Structures
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST003_ID' AND course_id = 3;
INSERT INTO scores (grade, gpa) VALUES ('A', 4.0); -- Linear Algebra
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST003_ID' AND course_id = 7;
-- Student 4 (Sarah Davis)
INSERT INTO scores (grade, gpa) VALUES ('B', 3.0); -- Database Management
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST004_ID' AND course_id = 4;
-- Student 6 (Jennifer Taylor) - struggling in technical courses
INSERT INTO scores (grade, gpa) VALUES ('C-', 1.7); -- Operating Systems
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST006_ID' AND course_id = 5;
INSERT INTO scores (grade, gpa) VALUES ('D+', 1.3); -- Differential Equations
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST006_ID' AND course_id = 8;
-- Student 7 (James Anderson)
INSERT INTO scores (grade, gpa) VALUES ('B+', 3.3); -- Marketing Principles
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST007_ID' AND course_id = 12;
-- Student 9 (Robert Thompson) - mixed performance
INSERT INTO scores (grade, gpa) VALUES ('C+', 2.3); -- Intro to Computer Science
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST009_ID' AND course_id = 1;
INSERT INTO scores (grade, gpa) VALUES ('D', 1.0); -- Data Structures
UPDATE enrollments SET score_id = currval('scores_id_seq')
WHERE student_id = 'ST009_ID' AND course_id = 3;
-- Add failing grades for additional students
-- David Wilson (suspended)
INSERT INTO scores (grade, gpa) VALUES ('F', 0.0); -- Electricity & Magnetism
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST005_ID', 10, currval('scores_id_seq'));
-- Add a enrollmentHistory record for this enrollment
INSERT INTO histories (id, action_type, created_at, student_id, course_id) VALUES
('hist_019', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '20 days', 'ST005_ID', 10);
-- Linda Martinez (dropped student)
INSERT INTO scores (grade, gpa) VALUES ('F', 0.0); -- Intro to Business
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST008_ID', 11, currval('scores_id_seq'));
-- Add a enrollmentHistory record for this enrollment
INSERT INTO histories (id, action_type, created_at, student_id, course_id) VALUES
('hist_020', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '25 days', 'ST008_ID', 11);
-- ===============================
-- ADDITIONAL SUBJECTS
-- ===============================
-- More subjects for Faculty of Business English (id=1)
INSERT INTO subjects (name, code, description, credits, faculty_id) VALUES
('Business Ethics', 'BUS301', 'Ethical principles and moral issues in business decisions', 3, 1),
('International Marketing', 'MKT301', 'Marketing strategies for global markets and cross-cultural consumer behavior', 4, 1),
('Organizational Behavior', 'MGT201', 'Human behavior in organizational settings', 3, 1),
('Business Communication', 'COMM201', 'Professional communication skills for business environments', 3, 1),
('Strategic Management', 'MGT401', 'Long-term planning and strategy formulation for organizations', 4, 1);
-- More subjects for Faculty of Law (id=2)
INSERT INTO subjects (name, code, description, credits, faculty_id) VALUES
('Constitutional Law', 'LAW201', 'Fundamental principles of government structure and individual rights', 4, 2),
('Criminal Law', 'LAW301', 'Principles, theories and problems of criminal law and punishment', 4, 2),
('International Law', 'LAW401', 'Legal relationships between nations and international entities', 3, 2),
('Contract Law', 'LAW202', 'Formation and enforcement of agreements between private parties', 3, 2),
('Property Law', 'LAW302', 'Legal relationships between persons and property', 3, 2);
-- More subjects for Faculty of Japanese (id=3)
INSERT INTO subjects (name, code, description, credits, faculty_id) VALUES
('Japanese Grammar', 'JPN201', 'Advanced Japanese language structure and grammar patterns', 4, 3),
('Japanese History', 'JPN301', 'Historical development of Japan from ancient times to present', 3, 3),
('Japanese Society', 'JPN302', 'Contemporary social issues and cultural aspects of Japan', 3, 3),
('Business Japanese', 'JPN401', 'Japanese language skills for business and professional settings', 4, 3),
('Japanese Film Studies', 'JPN402', 'Analysis of Japanese cinema and its cultural context', 3, 3);
-- More subjects for Faculty of French (id=4)
INSERT INTO subjects (name, code, description, credits, faculty_id) VALUES
('French Grammar', 'FRN201', 'Advanced French language structure and grammar patterns', 4, 4),
('French Literature', 'FRN301', 'Major works and movements in French literature', 3, 4),
('French Culture', 'FRN302', 'Contemporary social issues and cultural aspects of France', 3, 4),
('Business French', 'FRN401', 'French language skills for business and professional settings', 4, 4),
('French Film Studies', 'FRN402', 'Analysis of French cinema and its cultural context', 3, 4);
-- Add additional prerequisites
-- Business Ethics requires Intro to Business
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES
((SELECT id FROM subjects WHERE code = 'BUS301'), (SELECT id FROM subjects WHERE code = 'BUS101'));
-- International Marketing requires Marketing Principles
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES
((SELECT id FROM subjects WHERE code = 'MKT301'), (SELECT id FROM subjects WHERE code = 'BUS201'));
-- Strategic Management requires Business Ethics and Organizational Behavior
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES
((SELECT id FROM subjects WHERE code = 'MGT401'), (SELECT id FROM subjects WHERE code = 'BUS301')),
((SELECT id FROM subjects WHERE code = 'MGT401'), (SELECT id FROM subjects WHERE code = 'MGT201'));
-- Criminal Law requires Constitutional Law
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES
((SELECT id FROM subjects WHERE code = 'LAW301'), (SELECT id FROM subjects WHERE code = 'LAW201'));
-- International Law requires Constitutional Law
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES
((SELECT id FROM subjects WHERE code = 'LAW401'), (SELECT id FROM subjects WHERE code = 'LAW201'));
-- Business Japanese requires Japanese Grammar
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES
((SELECT id FROM subjects WHERE code = 'JPN401'), (SELECT id FROM subjects WHERE code = 'JPN201'));
-- Japanese Film Studies requires Japanese Society
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES
((SELECT id FROM subjects WHERE code = 'JPN402'), (SELECT id FROM subjects WHERE code = 'JPN302'));
-- Business French requires French Grammar
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES
((SELECT id FROM subjects WHERE code = 'FRN401'), (SELECT id FROM subjects WHERE code = 'FRN201'));
-- French Film Studies requires French Culture
INSERT INTO subject_prerequisites (subject_id, prerequisite_id) VALUES
((SELECT id FROM subjects WHERE code = 'FRN402'), (SELECT id FROM subjects WHERE code = 'FRN302'));
-- ===============================
-- ADDITIONAL COURSES
-- ===============================
-- More courses for existing subjects (additional sections)
INSERT INTO courses (code, year, semester, lecturer, max_student, room, schedule, start_date, program_id, subject_id) VALUES
-- Additional Computer Science course sections
('CS101_03', 2025, 2, 'Dr. Alice Cooper', 35, 'B204', 'T3(7-10)', '2025-09-10', 1, 1),
('CS201_02', 2025, 2, 'Prof. Mark Johnson', 40, 'A102', 'T4(7-10)', '2025-09-12', 1, 2),
-- Additional Mathematics course sections
('MATH101_02', 2025, 2, 'Dr. Thomas Lee', 45, 'C101', 'T5(1-4)', '2025-09-15', 2, 6),
('MATH201_02', 2025, 2, 'Prof. Susan Kim', 35, 'D303', 'T2(4-7)', '2025-09-11', 2, 8);
-- New courses for Business subjects
INSERT INTO courses (code, year, semester, lecturer, max_student, room, schedule, start_date, program_id, subject_id) VALUES
('BUS301_01', 2025, 1, 'Dr. Patricia Adams', 50, 'E201', 'T3(4-7)', '2025-04-16', 1, (SELECT id FROM subjects WHERE code = 'BUS301')),
('BUS301_02', 2025, 2, 'Prof. Richard Scott', 45, 'F302', 'T6(7-10)', '2025-09-14', 5, (SELECT id FROM subjects WHERE code = 'BUS301')),
('MKT301_01', 2025, 1, 'Dr. William Chen', 40, 'E202', 'T4(4-7)', '2025-04-17', 5, (SELECT id FROM subjects WHERE code = 'MKT301')),
('MGT201_01', 2025, 1, 'Prof. Lisa Wang', 55, 'F101', 'T5(1-4)', '2025-04-18', 10, (SELECT id FROM subjects WHERE code = 'MGT201')),
('COMM201_01', 2025, 2, 'Dr. Kevin Rodriguez', 50, 'E101', 'T2(7-10)', '2025-09-16', 10, (SELECT id FROM subjects WHERE code = 'COMM201')),
('MGT401_01', 2025, 2, 'Prof. Emma Wilson', 35, 'F303', 'T3(1-4)', '2025-09-17', 1, (SELECT id FROM subjects WHERE code = 'MGT401'));
-- New courses for Law subjects
INSERT INTO courses (code, year, semester, lecturer, max_student, room, schedule, start_date, program_id, subject_id) VALUES
('LAW201_01', 2025, 1, 'Prof. George Martinez', 60, 'G201', 'T2(4-7)', '2025-04-15', 2, (SELECT id FROM subjects WHERE code = 'LAW201')),
('LAW301_01', 2025, 1, 'Dr. Victoria Taylor', 50, 'G301', 'T4(1-4)', '2025-04-17', 2, (SELECT id FROM subjects WHERE code = 'LAW301')),
('LAW401_01', 2025, 2, 'Prof. Charles Wright', 40, 'G401', 'T6(4-7)', '2025-09-13', 7, (SELECT id FROM subjects WHERE code = 'LAW401')),
('LAW202_01', 2025, 2, 'Dr. Olivia Davis', 55, 'G202', 'T5(7-10)', '2025-09-18', 7, (SELECT id FROM subjects WHERE code = 'LAW202')),
('LAW302_01', 2025, 2, 'Prof. James Lee', 45, 'G302', 'T3(4-7)', '2025-09-19', 2, (SELECT id FROM subjects WHERE code = 'LAW302'));
-- New courses for Japanese subjects
INSERT INTO courses (code, year, semester, lecturer, max_student, room, schedule, start_date, program_id, subject_id) VALUES
('JPN201_01', 2025, 1, 'Prof. Hiroshi Tanaka', 40, 'H201', 'T3(1-4)', '2025-04-16', 3, (SELECT id FROM subjects WHERE code = 'JPN201')),
('JPN301_01', 2025, 1, 'Dr. Akiko Sato', 35, 'H301', 'T5(4-7)', '2025-04-18', 3, (SELECT id FROM subjects WHERE code = 'JPN301')),
('JPN302_01', 2025, 2, 'Prof. Takashi Yamamoto', 45, 'H302', 'T2(1-4)', '2025-09-15', 6, (SELECT id FROM subjects WHERE code = 'JPN302')),
('JPN401_01', 2025, 2, 'Dr. Yuki Nakamura', 30, 'H401', 'T4(4-7)', '2025-09-17', 9, (SELECT id FROM subjects WHERE code = 'JPN401')),
('JPN402_01', 2025, 2, 'Prof. Keiko Suzuki', 25, 'H402', 'T6(1-4)', '2025-09-19', 3, (SELECT id FROM subjects WHERE code = 'JPN402'));
-- New courses for French subjects
INSERT INTO courses (code, year, semester, lecturer, max_student, room, schedule, start_date, program_id, subject_id) VALUES
('FRN201_01', 2025, 1, 'Prof. Pierre Dubois', 40, 'J201', 'T4(4-7)', '2025-04-17', 4, (SELECT id FROM subjects WHERE code = 'FRN201')),
('FRN301_01', 2025, 1, 'Dr. Sophie Martin', 35, 'J301', 'T6(7-10)', '2025-04-19', 4, (SELECT id FROM subjects WHERE code = 'FRN301')),
('FRN302_01', 2025, 2, 'Prof. Jean Lefebvre', 45, 'J302', 'T3(7-10)', '2025-09-16', 8, (SELECT id FROM subjects WHERE code = 'FRN302')),
('FRN401_01', 2025, 2, 'Dr. Marie Roux', 30, 'J401', 'T5(4-7)', '2025-09-18', 4, (SELECT id FROM subjects WHERE code = 'FRN401')),
('FRN402_01', 2025, 2, 'Prof. Claude Moreau', 25, 'J402', 'T2(7-10)', '2025-09-20', 8, (SELECT id FROM subjects WHERE code = 'FRN402'));
-- ===============================
-- ADDITIONAL ENROLLMENTS AND SCORES
-- ===============================
-- Student 1 (John Smith - Business English) - additional enrollments
INSERT INTO scores (grade, gpa) VALUES ('A-', 3.7); -- Business Ethics
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST001_ID', (SELECT id FROM courses WHERE code = 'BUS301_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('B+', 3.3); -- Organizational Behavior
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST001_ID', (SELECT id FROM courses WHERE code = 'MGT201_01'), currval('scores_id_seq'));
-- Student 2 (Emily Johnson - Law) - additional enrollments
INSERT INTO scores (grade, gpa) VALUES ('A', 4.0); -- Constitutional Law
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST002_ID', (SELECT id FROM courses WHERE code = 'LAW201_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('B+', 3.3); -- Criminal Law
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST002_ID', (SELECT id FROM courses WHERE code = 'LAW301_01'), currval('scores_id_seq'));
-- Student 3 (Michael Brown - Japanese) - additional enrollments (graduated)
INSERT INTO scores (grade, gpa) VALUES ('A', 4.0); -- Japanese Grammar
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST003_ID', (SELECT id FROM courses WHERE code = 'JPN201_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('A-', 3.7); -- Japanese History
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST003_ID', (SELECT id FROM courses WHERE code = 'JPN301_01'), currval('scores_id_seq'));
-- Student 4 (Sarah Davis - French) - additional enrollments
INSERT INTO scores (grade, gpa) VALUES ('B+', 3.3); -- French Grammar
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST004_ID', (SELECT id FROM courses WHERE code = 'FRN201_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('A-', 3.7); -- French Literature
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST004_ID', (SELECT id FROM courses WHERE code = 'FRN301_01'), currval('scores_id_seq'));
-- Student 5 (David Wilson - Business English, Suspended) - additional enrollments
INSERT INTO scores (grade, gpa) VALUES ('D', 1.0); -- International Marketing
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST005_ID', (SELECT id FROM courses WHERE code = 'MKT301_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('F', 0.0); -- Business Ethics
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST005_ID', (SELECT id FROM courses WHERE code = 'BUS301_01'), currval('scores_id_seq'));
-- Student 6 (Jennifer Taylor - Japanese) - additional enrollments
INSERT INTO scores (grade, gpa) VALUES ('C', 2.0); -- Japanese Grammar
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST006_ID', (SELECT id FROM courses WHERE code = 'JPN201_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('C+', 2.3); -- Japanese Society
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST006_ID', (SELECT id FROM courses WHERE code = 'JPN302_01'), currval('scores_id_seq'));
-- Student 7 (James Anderson - Law) - additional enrollments
INSERT INTO scores (grade, gpa) VALUES ('B', 3.0); -- Constitutional Law
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST007_ID', (SELECT id FROM courses WHERE code = 'LAW201_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('B-', 2.7); -- Property Law
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST007_ID', (SELECT id FROM courses WHERE code = 'LAW302_01'), currval('scores_id_seq'));
-- Student 8 (Linda Martinez - French, Dropped) - additional enrollments
INSERT INTO scores (grade, gpa) VALUES ('F', 0.0); -- French Grammar
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST008_ID', (SELECT id FROM courses WHERE code = 'FRN201_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('D-', 0.7); -- French Culture
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST008_ID', (SELECT id FROM courses WHERE code = 'FRN302_01'), currval('scores_id_seq'));
-- Student 9 (Robert Thompson - Japanese) - additional enrollments
INSERT INTO scores (grade, gpa) VALUES ('C', 2.0); -- Japanese History
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST009_ID', (SELECT id FROM courses WHERE code = 'JPN301_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('B-', 2.7); -- Japanese Society
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST009_ID', (SELECT id FROM courses WHERE code = 'JPN302_01'), currval('scores_id_seq'));
-- Student 10 (Elizabeth Garcia - Business English) - additional enrollments
INSERT INTO scores (grade, gpa) VALUES ('A', 4.0); -- Business Ethics
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST010_ID', (SELECT id FROM courses WHERE code = 'BUS301_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('A-', 3.7); -- International Marketing
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST010_ID', (SELECT id FROM courses WHERE code = 'MKT301_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('B+', 3.3); -- Organizational Behavior
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST010_ID', (SELECT id FROM courses WHERE code = 'MGT201_01'), currval('scores_id_seq'));
-- ===============================
-- HISTORY RECORDS FOR NEW ENROLLMENTS
-- ===============================
-- Add enrollmentHistory records for all new enrollments
INSERT INTO histories (id, action_type, created_at, student_id, course_id) VALUES
-- Student 1 new enrollments enrollmentHistory
('hist_021', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '12 days', 'ST001_ID', (SELECT id FROM courses WHERE code = 'BUS301_01')),
('hist_022', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '12 days', 'ST001_ID', (SELECT id FROM courses WHERE code = 'MGT201_01')),
-- Student 2 new enrollments enrollmentHistory
('hist_023', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '11 days', 'ST002_ID', (SELECT id FROM courses WHERE code = 'LAW201_01')),
('hist_024', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '11 days', 'ST002_ID', (SELECT id FROM courses WHERE code = 'LAW301_01')),
-- Student 3 new enrollments enrollmentHistory
('hist_025', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '14 days', 'ST003_ID', (SELECT id FROM courses WHERE code = 'JPN201_01')),
('hist_026', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '14 days', 'ST003_ID', (SELECT id FROM courses WHERE code = 'JPN301_01')),
-- Student 4 new enrollments enrollmentHistory
('hist_027', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '10 days', 'ST004_ID', (SELECT id FROM courses WHERE code = 'FRN201_01')),
('hist_028', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '10 days', 'ST004_ID', (SELECT id FROM courses WHERE code = 'FRN301_01')),
-- Student 5 new enrollments enrollmentHistory
('hist_029', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '18 days', 'ST005_ID', (SELECT id FROM courses WHERE code = 'MKT301_01')),
('hist_030', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '18 days', 'ST005_ID', (SELECT id FROM courses WHERE code = 'BUS301_01')),
-- Student 6 new enrollments enrollmentHistory
('hist_031', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '9 days', 'ST006_ID', (SELECT id FROM courses WHERE code = 'JPN201_01')),
('hist_032', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '9 days', 'ST006_ID', (SELECT id FROM courses WHERE code = 'JPN302_01')),
-- Student 7 new enrollments enrollmentHistory
('hist_033', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '10 days', 'ST007_ID', (SELECT id FROM courses WHERE code = 'LAW201_01')),
('hist_034', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '10 days', 'ST007_ID', (SELECT id FROM courses WHERE code = 'LAW302_01')),
-- Student 8 new enrollments enrollmentHistory
('hist_035', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '22 days', 'ST008_ID', (SELECT id FROM courses WHERE code = 'FRN201_01')),
('hist_036', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '22 days', 'ST008_ID', (SELECT id FROM courses WHERE code = 'FRN302_01')),
-- Student 9 new enrollments enrollmentHistory
('hist_037', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '8 days', 'ST009_ID', (SELECT id FROM courses WHERE code = 'JPN301_01')),
('hist_038', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '8 days', 'ST009_ID', (SELECT id FROM courses WHERE code = 'JPN302_01')),
-- Student 10 new enrollments enrollmentHistory
('hist_039', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '7 days', 'ST010_ID', (SELECT id FROM courses WHERE code = 'BUS301_01')),
('hist_040', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '7 days', 'ST010_ID', (SELECT id FROM courses WHERE code = 'MKT301_01')),
('hist_041', 'ENROLLED', CURRENT_TIMESTAMP - INTERVAL '7 days', 'ST010_ID', (SELECT id FROM courses WHERE code = 'MGT201_01'));
-- ===============================
-- ADDITIONAL ENROLLMENTS AND SCORES FOR EXISTING STUDENTS
-- ===============================
-- More enrollments for second semester courses
-- Student 1 (John Smith - Business English)
INSERT INTO scores (grade, gpa) VALUES ('A', 4.0); -- Strategic Management
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST001_ID', (SELECT id FROM courses WHERE code = 'MGT401_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('B+', 3.3); -- Business Communication
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST001_ID', (SELECT id FROM courses WHERE code = 'COMM201_01'), currval('scores_id_seq'));
INSERT INTO scores (grade, gpa) VALUES ('A-', 3.7); -- CS201 (second section)
INSERT INTO enrollments (student_id, course_id, score_id) VALUES
('ST001_ID', (SELECT id FROM courses WHERE code = 'CS201_02'), currval('scores_id_seq'));
-- Student 2 (Emily Johnson - Law)