Skip to content

Commit

Permalink
Merge pull request #14 from DiamondLightSource/sp_prog_msg
Browse files Browse the repository at this point in the history
New version with stored procedure to upsert processing program messages
  • Loading branch information
KarlLevik authored Dec 2, 2019
2 parents a3f2de9 + 59141e3 commit 4320c9b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 21 deletions.
1 change: 1 addition & 0 deletions docs/list_of_procs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"**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"
"**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"
"**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"
"**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."
"**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."
"**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."
"**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"
Expand Down
1 change: 1 addition & 0 deletions grants/ispyb_processing.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ GRANT EXECUTE ON PROCEDURE `update_reprocessing_status` TO 'ispyb_processing';
GRANT EXECUTE ON PROCEDURE `upsert_processing_program` TO 'ispyb_processing';
GRANT EXECUTE ON PROCEDURE `upsert_processing_program_attachment` TO 'ispyb_processing';
GRANT EXECUTE ON PROCEDURE upsert_processing_program_attachment_v2 TO 'ispyb_processing';
GRANT EXECUTE ON PROCEDURE upsert_processing_program_message TO 'ispyb_processing';
GRANT EXECUTE ON PROCEDURE `upsert_processing` TO 'ispyb_processing';
GRANT EXECUTE ON PROCEDURE `insert_processing_scaling` TO 'ispyb_processing';
GRANT EXECUTE ON PROCEDURE `upsert_processing_integration` TO 'ispyb_processing';
Expand Down
10 changes: 5 additions & 5 deletions schema/lookups.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- MariaDB dump 10.17 Distrib 10.4.8-MariaDB, for Linux (x86_64)
-- MariaDB dump 10.17 Distrib 10.4.10-MariaDB, for Linux (x86_64)
--
-- Host: localhost Database: ispyb_build
-- ------------------------------------------------------
-- Server version 10.4.8-MariaDB
-- Server version 10.4.10-MariaDB

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
Expand All @@ -19,15 +19,15 @@
--

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

--
-- Dumping data for table `SchemaStatus`
--

/*!40000 ALTER TABLE `SchemaStatus` DISABLE KEYS */;
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');
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');
/*!40000 ALTER TABLE `SchemaStatus` ENABLE KEYS */;

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

-- Dump completed on 2019-11-26 15:00:53
-- Dump completed on 2019-12-02 11:29:18
48 changes: 45 additions & 3 deletions schema/routines.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- MariaDB dump 10.17 Distrib 10.4.8-MariaDB, for Linux (x86_64)
-- MariaDB dump 10.17 Distrib 10.4.10-MariaDB, for Linux (x86_64)
--
-- Host: localhost Database: ispyb_build
-- ------------------------------------------------------
-- Server version 10.4.8-MariaDB
-- Server version 10.4.10-MariaDB

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
Expand Down Expand Up @@ -6876,6 +6876,48 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `upsert_processing_program_message` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE PROCEDURE `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
)
MODIFIES SQL DATA
COMMENT 'Inserts or updates existing row in AutoProcProgramMessage.'
BEGIN
IF p_id IS NULL AND NOT (p_programId IS NULL) THEN
INSERT INTO AutoProcProgramMessage (autoProcProgramMessageId, autoProcProgramId, severity, message, description)
VALUES (p_id, p_programId, p_severity, p_message, p_description);
SET p_id = LAST_INSERT_ID();
ELSEIF NOT (p_id IS NULL) THEN
UPDATE AutoProcProgramMessage
SET
autoProcProgramId = IFNULL(p_programId, autoProcProgramId),
severity = IFNULL(p_severity, severity),
message = IFNULL(p_message, message),
description = IFNULL(p_description, description)
WHERE
autoProcProgramMessageId = p_id;
ELSE
SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Both arguments p_id and p_programId cannot be NULL';
END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `upsert_proposal` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
Expand Down Expand Up @@ -7575,4 +7617,4 @@ DELIMITER ;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2019-11-08 16:10:10
-- Dump completed on 2019-12-02 11:24:31
28 changes: 15 additions & 13 deletions schema/stored_programs/sp_upsert_processing_program_message.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
-- Example call:
-- SET @id=NULL;
-- CALL upsert_processing_program_message(@id, 56986673,'ERROR','Hello','Something odd is happening');

DELIMITER ;;

CREATE DEFINER=`ispyb_root`@`%` PROCEDURE `upsert_processing_program_message`(
CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `upsert_processing_program_message`(
INOUT p_id int(10) unsigned,
p_programId int(10) unsigned,
p_severity varchar(255),
Expand All @@ -13,20 +14,21 @@ CREATE DEFINER=`ispyb_root`@`%` PROCEDURE `upsert_processing_program_message`(
MODIFIES SQL DATA
COMMENT 'Inserts or updates existing row in AutoProcProgramMessage.'
BEGIN
IF NOT (p_programId IS NULL) THEN
IF p_id IS NULL AND NOT (p_programId IS NULL) THEN
INSERT INTO AutoProcProgramMessage (autoProcProgramMessageId, autoProcProgramId, severity, message, description)
VALUES (p_id, p_programId, p_severity, p_message, p_description)
ON DUPLICATE KEY UPDATE
autoProcProgramId = IFNULL(p_programId, autoProcProgramId),
severity = IFNULL(p_severity, severity),
message = IFNULL(p_message, message),
description = IFNULL(p_description, description);

IF p_id IS NULL THEN
SET p_id = LAST_INSERT_ID();
END IF;
VALUES (p_id, p_programId, p_severity, p_message, p_description);
SET p_id = LAST_INSERT_ID();
ELSEIF NOT (p_id IS NULL) THEN
UPDATE AutoProcProgramMessage
SET
autoProcProgramId = IFNULL(p_programId, autoProcProgramId),
severity = IFNULL(p_severity, severity),
message = IFNULL(p_message, message),
description = IFNULL(p_description, description)
WHERE
autoProcProgramMessageId = p_id;
ELSE
SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory argument p_programId is NULL';
SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Both arguments p_id and p_programId cannot be NULL';
END IF;
END;;

Expand Down
5 changes: 5 additions & 0 deletions schema/updates/2019_12_02_AdminVar_bump_version.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
INSERT IGNORE INTO SchemaStatus (scriptName, schemaStatus) VALUES ('2019_12_02_AdminVar_bump_version.sql', 'ONGOING');

UPDATE AdminVar SET `value` = '1.9.0' WHERE `name` = 'schemaVersion';

UPDATE SchemaStatus SET schemaStatus = 'DONE' WHERE scriptName = '2019_12_02_AdminVar_bump_version.sql';

0 comments on commit 4320c9b

Please sign in to comment.