Skip to content

Commit 4320c9b

Browse files
authored
Merge pull request #14 from DiamondLightSource/sp_prog_msg
New version with stored procedure to upsert processing program messages
2 parents a3f2de9 + 59141e3 commit 4320c9b

File tree

6 files changed

+72
-21
lines changed

6 files changed

+72
-21
lines changed

docs/list_of_procs.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"**upsert_processing_program**","INOUT p_id int(11) unsigned, p_commandLine varchar(255), p_programs varchar(255), p_status int(11), p_updateMessage varchar(80), p_startTimestamp datetime, p_updateTimestamp datetime, p_environment varchar(255), p_processingJobId int(11) unsigned, p_recordTimestamp datetime","If p_id is not provided, inserts new row. Otherwise updates exis"
128128
"**upsert_processing_program_attachment**","INOUT p_id int(10) unsigned, p_parentid int(10) unsigned, p_name varchar(255), p_path varchar(255), p_type enum('Log','Result','Graph')","Inserts or updates existing row in AutoProcProgramAttachment. Pa"
129129
"**upsert_processing_program_attachment_v2**","INOUT p_id int(10) unsigned, p_parentid int(10) unsigned, p_name varchar(255), p_path varchar(255), p_type enum('Log','Result','Graph', 'Debug'), p_importanceRank tinyint unsigned","Inserts or updates existing row in AutoProcProgramAttachment. Pa"
130+
"**upsert_processing_program_message**","INOUT p_id int(10) unsigned, p_programId int(10) unsigned, p_severity varchar(255), p_message varchar(255), p_description text","Inserts or updates existing row in AutoProcProgramMessage."
130131
"**upsert_proposal**","INOUT p_id int(11) unsigned, p_personId int(11) unsigned, p_title varchar(200), p_proposalCode varchar(45), p_proposalNumber int(11) unsigned, p_proposalType varchar(2), p_externalPkUUID varchar(32)","Inserts or updates info about a proposal (p_id).Mandatory columns:For insert: p_personId AND p_proposalCode AND p_proposalNumberFor update: p_id Returns: Record ID in p_id."
131132
"**upsert_proposal_has_person**","INOUT p_id int(10) unsigned, p_proposalId int(10) unsigned, p_personId int(10) unsigned, p_role varchar(100)","Inserts or updates info about a proposal - person association (p_id).Mandatory columns:For insert: p_proposalId, p_personIdFor update: p_idReturns: Record ID in p_id."
132133
"**upsert_quality_indicators**","OUT p_id int(11) unsigned, p_dataCollectionId int(11) unsigned, p_autoProcProgramId int(10) unsigned, p_imageNumber mediumint(8) unsigned, p_spotTotal int(10), p_inResTotal int(10), p_goodBraggCandidates int(10), p_iceRings int(10), p_method1Res float, p_method2Res float, p_maxUnitCell float, p_pctSaturationTop50Peaks float, p_inResolutionOvrlSpots int(10), p_binPopCutOffMethod2Res float, p_totalIntegratedSignal double, p_dozorScore double, p_driftFactor float","Inserts into or updates a row in the image quality indicators table"

grants/ispyb_processing.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ GRANT EXECUTE ON PROCEDURE `update_reprocessing_status` TO 'ispyb_processing';
5353
GRANT EXECUTE ON PROCEDURE `upsert_processing_program` TO 'ispyb_processing';
5454
GRANT EXECUTE ON PROCEDURE `upsert_processing_program_attachment` TO 'ispyb_processing';
5555
GRANT EXECUTE ON PROCEDURE upsert_processing_program_attachment_v2 TO 'ispyb_processing';
56+
GRANT EXECUTE ON PROCEDURE upsert_processing_program_message TO 'ispyb_processing';
5657
GRANT EXECUTE ON PROCEDURE `upsert_processing` TO 'ispyb_processing';
5758
GRANT EXECUTE ON PROCEDURE `insert_processing_scaling` TO 'ispyb_processing';
5859
GRANT EXECUTE ON PROCEDURE `upsert_processing_integration` TO 'ispyb_processing';

schema/lookups.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
-- MariaDB dump 10.17 Distrib 10.4.8-MariaDB, for Linux (x86_64)
1+
-- MariaDB dump 10.17 Distrib 10.4.10-MariaDB, for Linux (x86_64)
22
--
33
-- Host: localhost Database: ispyb_build
44
-- ------------------------------------------------------
5-
-- Server version 10.4.8-MariaDB
5+
-- Server version 10.4.10-MariaDB
66

77
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
88
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
@@ -19,15 +19,15 @@
1919
--
2020

2121
/*!40000 ALTER TABLE `AdminVar` DISABLE KEYS */;
22-
INSERT INTO `AdminVar` (`varId`, `name`, `value`) VALUES (4,'schemaVersion','1.8.0');
22+
INSERT INTO `AdminVar` (`varId`, `name`, `value`) VALUES (4,'schemaVersion','1.9.0');
2323
/*!40000 ALTER TABLE `AdminVar` ENABLE KEYS */;
2424

2525
--
2626
-- Dumping data for table `SchemaStatus`
2727
--
2828

2929
/*!40000 ALTER TABLE `SchemaStatus` DISABLE KEYS */;
30-
INSERT INTO `SchemaStatus` (`schemaStatusId`, `scriptName`, `schemaStatus`, `recordTimeStamp`) VALUES (6,'20180213_BLSample_subLocation.sql','DONE','2018-02-13 13:27:19'),(12,'20180213_DataCollectionFileAttachment_fileType.sql','DONE','2018-02-13 15:12:54'),(16,'20180303_v_run_to_table.sql','DONE','2018-07-25 15:11:18'),(19,'20180328_ImageQualityIndicators_alter_table.sql','DONE','2018-07-25 15:11:18'),(22,'20180410_BeamLineSetup_alter.sql','DONE','2018-07-25 15:11:18'),(25,'20180413_BeamLineSetup_and_Detector_alter.sql','DONE','2018-07-25 15:11:18'),(28,'20180501_DataCollectionGroup_experimentType_enum.sql','DONE','2018-07-25 15:11:18'),(31,'20180531_ScreeningOutput_alignmentSuccess.sql','DONE','2018-07-25 15:11:18'),(34,'20180629_DataCollection_imageContainerSubPath.sql','DONE','2018-07-25 15:11:18'),(35,'20180913_BeamCalendar.sql','DONE','2018-09-19 09:52:45'),(36,'2018_09_19_DataCollection_imageDirectory_comment.sql','DONE','2018-09-19 12:38:01'),(37,'2018_09_27_increase_schema_version.sql','DONE','2018-09-27 13:17:15'),(38,'2018_11_01_XrayCenteringResult.sql','DONE','2018-11-01 13:36:53'),(39,'2018_11_01_AutoProcProgram_dataCollectionId.sql','DONE','2018-11-01 15:10:38'),(40,'2018_11_01_AutoProcProgramMessage.sql','DONE','2018-11-01 15:28:17'),(44,'2018_11_01_DiffractionPlan_centeringMethod.sql','DONE','2018-11-01 22:51:36'),(45,'2018_11_02_DataCollectionGroup_experimentType_enum.sql','DONE','2018-11-02 11:54:15'),(47,'2018_11_05_spelling_of_centring.sql','DONE','2018-11-05 15:31:38'),(48,'2018_11_09_AutoProcProgram_update_processing_program.sql','DONE','2018-11-09 16:38:34'),(49,'2018_11_14_AutoProcProgramMessage_autoinc.sql','DONE','2018-11-14 10:15:27'),(50,'2018_11_22_AutoProcProgram_processingStatus_update.sql','DONE','2018-11-22 16:11:15'),(51,'2018_12_04_EnergyScan_and_XFEFluorescenceSpectrum_add_axisPosition.sql','DONE','2018-12-04 14:13:23'),(52,'2018_12_20_DataCollectionGroup_scanParameters.sql','DONE','2018-12-20 17:30:04'),(53,'2019_01_14_Proposal_state.sql','DONE','2019-01-14 12:13:31'),(54,'2019_01_14_ProcessingJobParameter_parameterValue.sql','DONE','2019-01-14 14:00:02'),(57,'2019_01_15_Detector_localName.sql','DONE','2019-01-15 23:01:15'),(58,'2019_02_04_BLSession_unique_index.sql','DONE','2019-02-04 13:52:19'),(59,'2019_03_29_BLSession_archived.sql','DONE','2019-04-03 14:43:08'),(60,'2019_04_03_UserGroup_and_Permission.sql','DONE','2019-04-03 14:51:04'),(61,'2019_04_07_AdminVar_bump_version.sql','DONE','2019-04-07 11:35:06'),(62,'2019_04_08_AdminVar_bump_version.sql','DONE','2019-04-08 15:38:01'),(63,'2019_04_23_AdminVar_bump_version.sql','DONE','2019-04-23 11:13:27'),(64,'2019_04_23_drop_v_run_view.sql','DONE','2019-04-23 11:13:35'),(67,'2019_04_23_v_run_additional_runs.sql','DONE','2019-04-23 12:39:47'),(68,'2019_05_28_AdminVar_bump_version.sql','DONE','2019-05-28 13:29:27'),(72,'2019_07_17_BLSample_crystalId_default.sql','DONE','2019-07-17 15:21:59'),(73,'2019_08_15_Sleeve.sql','DONE','2019-08-15 08:34:34'),(74,'2019_08_15_AdminVar_bump_version.sql','DONE','2019-08-15 08:57:37'),(75,'2019_08_28_AdminVar_bump_version.sql','DONE','2019-08-28 13:30:13'),(76,'2019_08_30_AdminVar_bump_version.sql','DONE','2019-08-30 11:58:16'),(77,'2019_10_06_BLSampleImage_fk3.sql','DONE','2019-10-06 16:55:44'),(78,'2019_10_08_DiffractionPlan_experimentKind.sql','DONE','2019-10-08 12:47:10'),(79,'2019_11_07_AutoProcProgramAttachment_importanceRank.sql','DONE','2019-11-07 16:35:25'),(80,'2019_11_07_AdminVar_bump_version.sql','DONE','2019-11-07 16:45:44'),(81,'2019_11_08_AdminVar_bump_version.sql','DONE','2019-11-08 16:09:52'),(82,'2019_11_26_v_run_idx1.sql','DONE','2019-11-26 15:00:21');
30+
INSERT INTO `SchemaStatus` (`schemaStatusId`, `scriptName`, `schemaStatus`, `recordTimeStamp`) VALUES (6,'20180213_BLSample_subLocation.sql','DONE','2018-02-13 13:27:19'),(12,'20180213_DataCollectionFileAttachment_fileType.sql','DONE','2018-02-13 15:12:54'),(16,'20180303_v_run_to_table.sql','DONE','2018-07-25 15:11:18'),(19,'20180328_ImageQualityIndicators_alter_table.sql','DONE','2018-07-25 15:11:18'),(22,'20180410_BeamLineSetup_alter.sql','DONE','2018-07-25 15:11:18'),(25,'20180413_BeamLineSetup_and_Detector_alter.sql','DONE','2018-07-25 15:11:18'),(28,'20180501_DataCollectionGroup_experimentType_enum.sql','DONE','2018-07-25 15:11:18'),(31,'20180531_ScreeningOutput_alignmentSuccess.sql','DONE','2018-07-25 15:11:18'),(34,'20180629_DataCollection_imageContainerSubPath.sql','DONE','2018-07-25 15:11:18'),(35,'20180913_BeamCalendar.sql','DONE','2018-09-19 09:52:45'),(36,'2018_09_19_DataCollection_imageDirectory_comment.sql','DONE','2018-09-19 12:38:01'),(37,'2018_09_27_increase_schema_version.sql','DONE','2018-09-27 13:17:15'),(38,'2018_11_01_XrayCenteringResult.sql','DONE','2018-11-01 13:36:53'),(39,'2018_11_01_AutoProcProgram_dataCollectionId.sql','DONE','2018-11-01 15:10:38'),(40,'2018_11_01_AutoProcProgramMessage.sql','DONE','2018-11-01 15:28:17'),(44,'2018_11_01_DiffractionPlan_centeringMethod.sql','DONE','2018-11-01 22:51:36'),(45,'2018_11_02_DataCollectionGroup_experimentType_enum.sql','DONE','2018-11-02 11:54:15'),(47,'2018_11_05_spelling_of_centring.sql','DONE','2018-11-05 15:31:38'),(48,'2018_11_09_AutoProcProgram_update_processing_program.sql','DONE','2018-11-09 16:38:34'),(49,'2018_11_14_AutoProcProgramMessage_autoinc.sql','DONE','2018-11-14 10:15:27'),(50,'2018_11_22_AutoProcProgram_processingStatus_update.sql','DONE','2018-11-22 16:11:15'),(51,'2018_12_04_EnergyScan_and_XFEFluorescenceSpectrum_add_axisPosition.sql','DONE','2018-12-04 14:13:23'),(52,'2018_12_20_DataCollectionGroup_scanParameters.sql','DONE','2018-12-20 17:30:04'),(53,'2019_01_14_Proposal_state.sql','DONE','2019-01-14 12:13:31'),(54,'2019_01_14_ProcessingJobParameter_parameterValue.sql','DONE','2019-01-14 14:00:02'),(57,'2019_01_15_Detector_localName.sql','DONE','2019-01-15 23:01:15'),(58,'2019_02_04_BLSession_unique_index.sql','DONE','2019-02-04 13:52:19'),(59,'2019_03_29_BLSession_archived.sql','DONE','2019-04-03 14:43:08'),(60,'2019_04_03_UserGroup_and_Permission.sql','DONE','2019-04-03 14:51:04'),(61,'2019_04_07_AdminVar_bump_version.sql','DONE','2019-04-07 11:35:06'),(62,'2019_04_08_AdminVar_bump_version.sql','DONE','2019-04-08 15:38:01'),(63,'2019_04_23_AdminVar_bump_version.sql','DONE','2019-04-23 11:13:27'),(64,'2019_04_23_drop_v_run_view.sql','DONE','2019-04-23 11:13:35'),(67,'2019_04_23_v_run_additional_runs.sql','DONE','2019-04-23 12:39:47'),(68,'2019_05_28_AdminVar_bump_version.sql','DONE','2019-05-28 13:29:27'),(72,'2019_07_17_BLSample_crystalId_default.sql','DONE','2019-07-17 15:21:59'),(73,'2019_08_15_Sleeve.sql','DONE','2019-08-15 08:34:34'),(74,'2019_08_15_AdminVar_bump_version.sql','DONE','2019-08-15 08:57:37'),(75,'2019_08_28_AdminVar_bump_version.sql','DONE','2019-08-28 13:30:13'),(76,'2019_08_30_AdminVar_bump_version.sql','DONE','2019-08-30 11:58:16'),(77,'2019_10_06_BLSampleImage_fk3.sql','DONE','2019-10-06 16:55:44'),(78,'2019_10_08_DiffractionPlan_experimentKind.sql','DONE','2019-10-08 12:47:10'),(79,'2019_11_07_AutoProcProgramAttachment_importanceRank.sql','DONE','2019-11-07 16:35:25'),(80,'2019_11_07_AdminVar_bump_version.sql','DONE','2019-11-07 16:45:44'),(81,'2019_11_08_AdminVar_bump_version.sql','DONE','2019-11-08 16:09:52'),(82,'2019_11_26_v_run_idx1.sql','DONE','2019-11-26 15:00:21'),(83,'2019_12_02_AdminVar_bump_version.sql','DONE','2019-12-02 11:29:05');
3131
/*!40000 ALTER TABLE `SchemaStatus` ENABLE KEYS */;
3232

3333
--
@@ -159,4 +159,4 @@ INSERT INTO `Permission` (`permissionId`, `type`, `description`) VALUES (1,'mx_a
159159
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
160160
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
161161

162-
-- Dump completed on 2019-11-26 15:00:53
162+
-- Dump completed on 2019-12-02 11:29:18

schema/routines.sql

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
-- MariaDB dump 10.17 Distrib 10.4.8-MariaDB, for Linux (x86_64)
1+
-- MariaDB dump 10.17 Distrib 10.4.10-MariaDB, for Linux (x86_64)
22
--
33
-- Host: localhost Database: ispyb_build
44
-- ------------------------------------------------------
5-
-- Server version 10.4.8-MariaDB
5+
-- Server version 10.4.10-MariaDB
66

77
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
88
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
@@ -6876,6 +6876,48 @@ DELIMITER ;
68766876
/*!50003 SET character_set_client = @saved_cs_client */ ;
68776877
/*!50003 SET character_set_results = @saved_cs_results */ ;
68786878
/*!50003 SET collation_connection = @saved_col_connection */ ;
6879+
/*!50003 DROP PROCEDURE IF EXISTS `upsert_processing_program_message` */;
6880+
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
6881+
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
6882+
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
6883+
/*!50003 SET character_set_client = utf8 */ ;
6884+
/*!50003 SET character_set_results = utf8 */ ;
6885+
/*!50003 SET collation_connection = utf8_general_ci */ ;
6886+
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
6887+
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
6888+
DELIMITER ;;
6889+
CREATE PROCEDURE `upsert_processing_program_message`(
6890+
INOUT p_id int(10) unsigned,
6891+
p_programId int(10) unsigned,
6892+
p_severity varchar(255),
6893+
p_message varchar(255),
6894+
p_description text
6895+
)
6896+
MODIFIES SQL DATA
6897+
COMMENT 'Inserts or updates existing row in AutoProcProgramMessage.'
6898+
BEGIN
6899+
IF p_id IS NULL AND NOT (p_programId IS NULL) THEN
6900+
INSERT INTO AutoProcProgramMessage (autoProcProgramMessageId, autoProcProgramId, severity, message, description)
6901+
VALUES (p_id, p_programId, p_severity, p_message, p_description);
6902+
SET p_id = LAST_INSERT_ID();
6903+
ELSEIF NOT (p_id IS NULL) THEN
6904+
UPDATE AutoProcProgramMessage
6905+
SET
6906+
autoProcProgramId = IFNULL(p_programId, autoProcProgramId),
6907+
severity = IFNULL(p_severity, severity),
6908+
message = IFNULL(p_message, message),
6909+
description = IFNULL(p_description, description)
6910+
WHERE
6911+
autoProcProgramMessageId = p_id;
6912+
ELSE
6913+
SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Both arguments p_id and p_programId cannot be NULL';
6914+
END IF;
6915+
END ;;
6916+
DELIMITER ;
6917+
/*!50003 SET sql_mode = @saved_sql_mode */ ;
6918+
/*!50003 SET character_set_client = @saved_cs_client */ ;
6919+
/*!50003 SET character_set_results = @saved_cs_results */ ;
6920+
/*!50003 SET collation_connection = @saved_col_connection */ ;
68796921
/*!50003 DROP PROCEDURE IF EXISTS `upsert_proposal` */;
68806922
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
68816923
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -7575,4 +7617,4 @@ DELIMITER ;
75757617
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
75767618
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
75777619

7578-
-- Dump completed on 2019-11-08 16:10:10
7620+
-- Dump completed on 2019-12-02 11:24:31

schema/stored_programs/sp_upsert_processing_program_message.sql

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
-- Example call:
2+
-- SET @id=NULL;
23
-- CALL upsert_processing_program_message(@id, 56986673,'ERROR','Hello','Something odd is happening');
34

45
DELIMITER ;;
56

6-
CREATE DEFINER=`ispyb_root`@`%` PROCEDURE `upsert_processing_program_message`(
7+
CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `upsert_processing_program_message`(
78
INOUT p_id int(10) unsigned,
89
p_programId int(10) unsigned,
910
p_severity varchar(255),
@@ -13,20 +14,21 @@ CREATE DEFINER=`ispyb_root`@`%` PROCEDURE `upsert_processing_program_message`(
1314
MODIFIES SQL DATA
1415
COMMENT 'Inserts or updates existing row in AutoProcProgramMessage.'
1516
BEGIN
16-
IF NOT (p_programId IS NULL) THEN
17+
IF p_id IS NULL AND NOT (p_programId IS NULL) THEN
1718
INSERT INTO AutoProcProgramMessage (autoProcProgramMessageId, autoProcProgramId, severity, message, description)
18-
VALUES (p_id, p_programId, p_severity, p_message, p_description)
19-
ON DUPLICATE KEY UPDATE
20-
autoProcProgramId = IFNULL(p_programId, autoProcProgramId),
21-
severity = IFNULL(p_severity, severity),
22-
message = IFNULL(p_message, message),
23-
description = IFNULL(p_description, description);
24-
25-
IF p_id IS NULL THEN
26-
SET p_id = LAST_INSERT_ID();
27-
END IF;
19+
VALUES (p_id, p_programId, p_severity, p_message, p_description);
20+
SET p_id = LAST_INSERT_ID();
21+
ELSEIF NOT (p_id IS NULL) THEN
22+
UPDATE AutoProcProgramMessage
23+
SET
24+
autoProcProgramId = IFNULL(p_programId, autoProcProgramId),
25+
severity = IFNULL(p_severity, severity),
26+
message = IFNULL(p_message, message),
27+
description = IFNULL(p_description, description)
28+
WHERE
29+
autoProcProgramMessageId = p_id;
2830
ELSE
29-
SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory argument p_programId is NULL';
31+
SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Both arguments p_id and p_programId cannot be NULL';
3032
END IF;
3133
END;;
3234

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
INSERT IGNORE INTO SchemaStatus (scriptName, schemaStatus) VALUES ('2019_12_02_AdminVar_bump_version.sql', 'ONGOING');
2+
3+
UPDATE AdminVar SET `value` = '1.9.0' WHERE `name` = 'schemaVersion';
4+
5+
UPDATE SchemaStatus SET schemaStatus = 'DONE' WHERE scriptName = '2019_12_02_AdminVar_bump_version.sql';

0 commit comments

Comments
 (0)