Database 0071: Applicants

This commit is contained in:
Rick Falkvinge
2018-03-07 11:04:18 +01:00
parent 85e207aa29
commit e2e9a050e1
6 changed files with 133 additions and 8 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ namespace Swarmops.Database
/// <summary>
/// This is the IN-CODE revision of the database. The version we expect to be running against.
/// </summary>
public static int DbVersionExpected => 70;
public static int DbVersionExpected => 71;
// This class is in horrible need of serious refactoring. For its simplicity in task, it's a horrible bowl of spaghetti.
+2 -1
View File
@@ -67,4 +67,5 @@
0067 - Bugfix for 0066 [RF]
0068 - Added SetSalaryOpen [RF]
0069 - Added table, procs for ExpenseClaimGroups [RF]
0070 - Added first Applications tables, procs [RF]
0070 - Added first Applications tables, procs [RF]
0071 - Renamed Application to Applicant, to avoid a marsh and misery of name collisions [RF]
+86
View File
@@ -0,0 +1,86 @@
DROP TABLE `Applications`
#
CREATE TABLE `Applicants` (
`ApplicantId` INT NOT NULL AUTO_INCREMENT,
`PersonId` INT NOT NULL,
`OrganizationId` INT NOT NULL,
`CreatedDateTime` DATETIME NOT NULL,
`GrantedDateTime` DATETIME NOT NULL DEFAULT '1800-01-01',
`GrantedByPersonId` INT NOT NULL DEFAULT 0,
`Open` TINYINT NOT NULL DEFAULT 1,
`Score1` BIGINT NOT NULL DEFAULT 0,
`Score2` BIGINT NOT NULL DEFAULT 0,
`Score3` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`ApplicantId`),
INDEX `Ix_Person` (`PersonId` ASC),
INDEX `Ix_Organization` (`OrganizationId` ASC),
INDEX `Ix_Scores` (`Score1` ASC, `Score2` ASC, `Score3` ASC),
INDEX `Ix_Open` (`Open` ASC),
INDEX `Ix_Created` (`CreatedDateTime` ASC))
#
DROP PROCEDURE IF EXISTS `CreateApplication`
#
DROP PROCEDURE IF EXISTS `UpdateApplicationScore`
#
DROP PROCEDURE IF EXISTS `CreateApplicant`
#
DROP PROCEDURE IF EXISTS `UpdateApplicantScore`
#
CREATE PROCEDURE `CreateApplicant`(
IN personId INT,
IN organizationId INT,
IN dateTimeNow DATETIME
)
BEGIN
INSERT INTO Applicants (PersonId, OrganizationId, CreatedDateTime)
VALUES (personId, organizationId, dateTimeNow);
SELECT LAST_INSERT_ID() AS Identity;
END
#
CREATE PROCEDURE `UpdateApplicantScore`(
IN applicantId INT,
IN deltaScore1 BIGINT,
IN deltaScore2 BIGINT,
IN deltaScore3 BIGINT
)
BEGIN
UPDATE Applicants
SET Applicants.Score1 = Applicants.Score1 + deltaScore1,
Applicants.Score2 = Applicants.Score2 + deltaScore2,
Applicants.Score3 = Applicants.Score3 + deltaScore3
WHERE Applicants.ApplicantId = applicantId;
END