-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
1,300 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
admin/data/sql/migrations/159.do.create-pupil-status-table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
create table [mtc_admin].[pupilStatus] ( | ||
id int IDENTITY (1,1) NOT NULL, | ||
createdAt datetimeoffset(3) NOT NULL DEFAULT GETUTCDATE(), | ||
updatedAt datetimeoffset(3) NOT NULL DEFAULT GETUTCDATE(), | ||
version rowversion, | ||
description nvarchar(150) NOT NULL, | ||
code nvarchar(12) NOT NULL | ||
CONSTRAINT [PK_pupilStatus] PRIMARY KEY CLUSTERED ([id] ASC) | ||
WITH ( | ||
PAD_INDEX = OFF, | ||
STATISTICS_NORECOMPUTE = OFF, | ||
IGNORE_DUP_KEY = OFF, | ||
ALLOW_ROW_LOCKS = ON, | ||
ALLOW_PAGE_LOCKS = ON | ||
), | ||
CONSTRAINT [pupilStatus_code_uindex] UNIQUE([code]) | ||
); | ||
|
||
-- missing triggers like a lot of newer tables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
alter table [mtc_admin].[pupilStatus] drop constraint [pupilStatus_code_uindex]; | ||
drop table [mtc_admin].[pupilStatus]; |
8 changes: 8 additions & 0 deletions
8
admin/data/sql/migrations/160.do.populate-pupil-status-table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
insert into [mtc_admin].[pupilStatus] (code, description) | ||
values | ||
('UNALLOC', 'The pupil has not been allocated a check'), | ||
('ALLOC', 'The pupil has been allocated a check'), | ||
('LOGGED_IN', 'The pupil has logged in and collected the check'), | ||
('STARTED', 'The pupil clicked the "Start Now" button and started taking the real, live check'), | ||
('COMPLETED', 'The pupil has completed the live check'), | ||
('NOT_TAKING', 'The pupil has been marked as not taking the check for some reason'); |
1 change: 1 addition & 0 deletions
1
admin/data/sql/migrations/160.undo.populate-pupil-status-table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
truncate table [mtc_admin].[pupilStatus]; |
1 change: 1 addition & 0 deletions
1
admin/data/sql/migrations/161.do.drop-pupilStatusCode-table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
drop table [mtc_admin].[pupilStatusCode]; |
18 changes: 18 additions & 0 deletions
18
admin/data/sql/migrations/161.undo.drop-pupilStatusCode-table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CREATE TABLE [mtc_admin].[pupilStatusCode] ( | ||
id int IDENTITY (1,1) NOT NULL, | ||
createdAt datetimeoffset(3) NOT NULL DEFAULT GETUTCDATE(), | ||
updatedAt datetimeoffset(3) NOT NULL DEFAULT GETUTCDATE(), | ||
version rowversion, | ||
description nvarchar(50) NOT NULL, | ||
code char(3) NOT NULL, | ||
CONSTRAINT [PK_pupilStatusCode] PRIMARY KEY CLUSTERED ([id] ASC) | ||
WITH ( | ||
PAD_INDEX = OFF, | ||
STATISTICS_NORECOMPUTE = OFF, | ||
IGNORE_DUP_KEY = OFF, | ||
ALLOW_ROW_LOCKS = ON, | ||
ALLOW_PAGE_LOCKS = ON | ||
), | ||
CONSTRAINT [pupilStatusCode_code_uindex] UNIQUE([code]) | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
alter table [mtc_admin].[pupil] add pupilStatus_id int | ||
constraint [FK_pupil_pupilStatus_id_pupilStatus_id] foreign key (pupilStatus_id) | ||
references [mtc_admin].[pupilStatus] (id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
alter table [mtc_admin].[pupil] drop constraint [FK_pupil_pupilStatus_id_pupilStatus_id]; | ||
alter table [mtc_admin].[pupil] drop column pupilStatus_id; |
84 changes: 84 additions & 0 deletions
84
admin/data/sql/migrations/163.do.backfill-pupil-status.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
declare @statusId int; | ||
|
||
-- Set pupil status for those pupils who have never been allocated any checks | ||
set @statusId = (select id from [mtc_admin].[pupilStatus] where code = 'UNALLOC'); | ||
|
||
UPDATE [mtc_admin].[pupil] | ||
SET pupilStatus_id = @statusId | ||
FROM [mtc_admin].[pupil] p | ||
LEFT JOIN [mtc_admin].[check] chk ON (p.id = chk.pupil_id) | ||
WHERE chk.id IS NULL; | ||
|
||
|
||
|
||
-- Set the pupil status for those pupils who have been allocated a check but have never logged in | ||
set @statusId = (select id from [mtc_admin].[pupilStatus] where code = 'ALLOC'); | ||
|
||
UPDATE [mtc_admin].[pupil] | ||
SET pupilStatus_id = @statusId | ||
FROM [mtc_admin].[pupil] p | ||
LEFT JOIN [mtc_admin].[check] chk ON (p.id = chk.pupil_id) | ||
WHERE chk.isLiveCheck = 1 | ||
AND chk.id IS NULL; | ||
|
||
|
||
|
||
-- Set pupil status for those pupils who have have logged in to their check | ||
set @statusId = (select id from [mtc_admin].[pupilStatus] where code = 'LOGGED_IN'); | ||
|
||
UPDATE [mtc_admin].[pupil] | ||
SET pupilStatus_id = @statusId | ||
FROM [mtc_admin].[pupil] p | ||
INNER JOIN [mtc_admin].[check] chk ON (p.id = chk.pupil_id) | ||
INNER JOIN [mtc_admin].[checkStatus] chkStatus ON (chk.checkStatus_id = chkStatus.id) | ||
WHERE chkStatus.code = 'COL' | ||
AND chk.isLiveCheck = 1; | ||
|
||
|
||
|
||
-- Set pupil status for those who have have started a check | ||
set @statusId = (select id from [mtc_admin].[pupilStatus] where code = 'STARTED'); | ||
|
||
UPDATE [mtc_admin].[pupil] | ||
SET pupilStatus_id = @statusId | ||
FROM [mtc_admin].[pupil] p | ||
INNER JOIN [mtc_admin].[check] chk ON (p.id = chk.pupil_id) | ||
INNER JOIN [mtc_admin].[checkStatus] chkStatus ON (chk.checkStatus_id = chkStatus.id) | ||
WHERE chkStatus.code = 'STD' | ||
AND chk.isLiveCheck = 1; | ||
|
||
|
||
|
||
-- Update the pupil status for pupils who have completed a check | ||
set @statusId = (select id from [mtc_admin].[pupilStatus] where code = 'COMPLETED'); | ||
|
||
UPDATE [mtc_admin].[pupil] | ||
SET pupilStatus_id = @statusId | ||
FROM [mtc_admin].[pupil] p | ||
INNER JOIN [mtc_admin].[check] chk ON (p.id = chk.pupil_id) | ||
INNER JOIN [mtc_admin].[checkStatus] chkStatus ON (chk.checkStatus_id = chkStatus.id) | ||
WHERE chkStatus.code = 'CMP' | ||
AND chk.isLiveCheck = 1; | ||
|
||
|
||
-- Set pupil status for those not taking the check | ||
set @statusId = (select id from [mtc_admin].[pupilStatus] where code = 'NOT_TAKING'); | ||
|
||
UPDATE [mtc_admin].[pupil] | ||
SET pupilStatus_id = @statusId | ||
FROM [mtc_admin].[pupil] p | ||
INNER JOIN [mtc_admin].[pupilAttendance] pa ON (p.id = pa.pupil_id) | ||
WHERE pa.isDeleted = 0; | ||
|
||
|
||
-- Set any pupils with an unconsumed restart to UNALLOC, so they can be allocated a new check | ||
set @statusId = (select id from [mtc_admin].[pupilStatus] where code = 'UNALLOC'); | ||
|
||
UPDATE [mtc_admin].[pupil] | ||
SET pupilStatus_id = @statusId | ||
FROM [mtc_admin].[pupil] p | ||
INNER JOIN [mtc_admin].[pupilRestart] pr ON (p.id = pr.pupil_id) | ||
WHERE | ||
pr.check_id IS NULL | ||
AND pr.isDeleted = 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
update [mtc_admin].[pupil] set pupilStatus_id = NULL; |
14 changes: 14 additions & 0 deletions
14
admin/data/sql/migrations/164.do.create-pupil-status-view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- helper view for DBAs / developers | ||
|
||
CREATE VIEW [mtc_admin].[vewPupilStatus] AS ( | ||
SELECT | ||
p.id as pupil_id, | ||
p.foreName, | ||
p.lastName, | ||
p.middleNames, | ||
p.dateOfBirth, | ||
p.gender, | ||
ps.code | ||
FROM [mtc_admin].[pupil] p | ||
LEFT JOIN [mtc_admin].[pupilStatus] ps ON (p.pupilStatus_id = ps.id) | ||
); |
1 change: 1 addition & 0 deletions
1
admin/data/sql/migrations/164.undo.create-pupil-status-view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP VIEW [mtc_admin].[vewPupilStatus]; |
5 changes: 5 additions & 0 deletions
5
admin/data/sql/migrations/165.do.make-pupil-status-not-null.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
alter table [mtc_admin].[pupil] | ||
alter column pupilStatus_id int not null; | ||
|
||
alter table [mtc_admin].[pupil] | ||
add constraint [DF_pupil_pupilStatus_id] DEFAULT 1 FOR [pupilStatus_id]; |
5 changes: 5 additions & 0 deletions
5
admin/data/sql/migrations/165.undo.make-pupil-status-not-null.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
alter table [mtc_admin].[pupil] | ||
alter column pupilStatus_id int; | ||
|
||
alter table [mtc_admin].[pupil] | ||
drop constraint [DF_pupil_pupilStatus_id]; |
45 changes: 45 additions & 0 deletions
45
admin/data/sql/migrations/166.do.create-view-pupils-eligible-for-familiarisation-pin.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
-- | ||
-- Find pupils eligible to generate a Familiarisation PIN | ||
-- | ||
|
||
CREATE VIEW [mtc_admin].[vewPupilsEligibleForFamiliarisationPinGeneration] AS ( | ||
SELECT | ||
p.id, | ||
p.foreName, | ||
p.middleNames, | ||
p.lastName, | ||
p.dateOfBirth, | ||
p.school_id, | ||
p.urlSlug | ||
FROM | ||
[mtc_admin].[pupil] p | ||
LEFT JOIN [mtc_admin].[pupilAttendance] pa ON (p.id = pa.pupil_id) | ||
LEFT JOIN [mtc_admin].[attendanceCode] ac ON (pa.attendanceCode_id = ac.id) | ||
INNER JOIN [mtc_admin].[pupilStatus] ps ON (p.pupilStatus_id = ps.id) | ||
WHERE | ||
-- include all pupils except those who are marked as not taking check because they left school | ||
(ac.id IS NULL OR ac.code <> 'LEFTT') | ||
AND ps.code IN ('UNALLOC', | ||
'ALLOC', | ||
'LOGGED_IN', | ||
'NOT_TAKING_CHECK') | ||
|
||
|
||
EXCEPT | ||
|
||
-- Exclude pupils who already have an active familiarisation check | ||
SELECT | ||
p.id, | ||
p.foreName, | ||
p.middleNames, | ||
p.lastName, | ||
p.dateOfBirth, | ||
p.school_id, | ||
p.urlSlug | ||
FROM | ||
[mtc_admin].[pupil] p | ||
LEFT JOIN [mtc_admin].[check] AS chk ON (p.id = chk.pupil_id) | ||
LEFT JOIN [mtc_admin].[checkStatus] AS chkStatus ON (chk.checkStatus_id = chkStatus.id) | ||
WHERE chk.isLiveCheck = 0 | ||
AND chkStatus.code = 'NEW' | ||
); |
1 change: 1 addition & 0 deletions
1
admin/data/sql/migrations/166.undo.create-view-pupils-eligible-for-familiarisation-pin.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP VIEW [mtc_admin].[vewPupilsEligibleForFamiliarisationPinGeneration]; |
1 change: 1 addition & 0 deletions
1
admin/data/sql/migrations/167.do.drop-view-pupils-eligible-for-pin-generation.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
drop view [mtc_admin].[vewPupilsEligibleForPinGeneration]; |
Oops, something went wrong.