From 19126878fbac5c3eb1fc038a635137450cadca26 Mon Sep 17 00:00:00 2001 From: KarlLevik Date: Mon, 16 Jan 2023 18:13:49 +0000 Subject: [PATCH] New SP update_dc_append_comments + refresh schema and history files --- HISTORY.rst | 1 + grants/ispyb_acquisition.sql | 2 ++ schemas/ispyb/lookups.sql | 3 +- schemas/ispyb/routines.sql | 33 +++++++++++++++++++ .../sp_update_dc_append_comments.sql | 20 +++++++++++ schemas/ispyb/tables.sql | 12 ++++++- 6 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 schemas/ispyb/stored_programs/sp_update_dc_append_comments.sql diff --git a/HISTORY.rst b/HISTORY.rst index 0863fe2d..23d054b6 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -12,6 +12,7 @@ Table/column changes: Stored procedures: * New procedure ``update_container_dispose`` to mark a container as disposed +* New procedure ``update_dc_append_comments`` to append text to the comments column in a data collection Grants & roles: diff --git a/grants/ispyb_acquisition.sql b/grants/ispyb_acquisition.sql index dfea54b9..6169aa83 100644 --- a/grants/ispyb_acquisition.sql +++ b/grants/ispyb_acquisition.sql @@ -34,6 +34,8 @@ GRANT EXECUTE ON PROCEDURE update_dc_machine TO 'ispyb_acquisition'; GRANT EXECUTE ON PROCEDURE upsert_sample_image_analysis TO 'ispyb_acquisition'; GRANT EXECUTE ON PROCEDURE upsert_dcg_grid TO 'ispyb_acquisition'; GRANT EXECUTE ON PROCEDURE upsert_dc_grid TO 'ispyb_acquisition'; + +GRANT EXECUTE ON PROCEDURE update_dc_append_comments TO 'ispyb_acquisition'; GRANT EXECUTE ON PROCEDURE update_dc_position TO 'ispyb_acquisition'; GRANT EXECUTE ON PROCEDURE `update_dc_experiment_v2` TO 'ispyb_acquisition'; diff --git a/schemas/ispyb/lookups.sql b/schemas/ispyb/lookups.sql index f5fac279..f4cb2d0f 100644 --- a/schemas/ispyb/lookups.sql +++ b/schemas/ispyb/lookups.sql @@ -207,7 +207,8 @@ INSERT INTO `SchemaStatus` (`schemaStatusId`, `scriptName`, `schemaStatus`, `rec (232,'2022_09_28_ContainerType_update.sql','DONE','2022-09-28 10:04:59'), (233,'2022_10_17_BLSession_drop_constraint.sql','DONE','2022-10-17 11:25:35'), (234,'2022_10_21_Shipping_extra.sql','DONE','2022-11-02 17:04:27'), -(235,'2022_11_02_AdminVar_bump_version.sql','DONE','2022-11-02 17:04:27'); +(235,'2022_11_02_AdminVar_bump_version.sql','DONE','2022-11-02 17:04:27'), +(236,'2023_01_16_Tomogram_new_cols.sql','DONE','2023-01-16 18:09:03'); /*!40000 ALTER TABLE `SchemaStatus` ENABLE KEYS */; /*!40000 ALTER TABLE `ComponentType` DISABLE KEYS */; diff --git a/schemas/ispyb/routines.sql b/schemas/ispyb/routines.sql index fee5e46d..ce52768c 100644 --- a/schemas/ispyb/routines.sql +++ b/schemas/ispyb/routines.sql @@ -7794,6 +7794,39 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!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' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `update_dc_append_comments` */; +/*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +DELIMITER ;; +CREATE PROCEDURE `update_dc_append_comments`( + p_id int(11) unsigned, + p_comments varchar(1024), + p_separator varchar(5) +) + MODIFIES SQL DATA + COMMENT 'Appends text to DataCollection.comments for dataCollectionId=p_id. ' +BEGIN + IF NOT (p_id IS NULL) AND NOT (p_comments IS NULL) THEN + + UPDATE DataCollection + SET comments = concat_ws(p_separator, comments, p_comments) + WHERE dataCollectionId = p_id; + + ELSE + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory arguments p_id and/or p_comments are 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 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'STRICT_TRANS_TABLES' */ ; /*!50003 DROP PROCEDURE IF EXISTS `update_dc_experiment` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; diff --git a/schemas/ispyb/stored_programs/sp_update_dc_append_comments.sql b/schemas/ispyb/stored_programs/sp_update_dc_append_comments.sql new file mode 100644 index 00000000..b55dc9b0 --- /dev/null +++ b/schemas/ispyb/stored_programs/sp_update_dc_append_comments.sql @@ -0,0 +1,20 @@ +DELIMITER ;; +CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `update_dc_append_comments`( + p_id int(11) unsigned, + p_comments varchar(1024), + p_separator varchar(5) +) +MODIFIES SQL DATA +COMMENT 'Appends text to DataCollection.comments for dataCollectionId=p_id. ' +BEGIN + IF NOT (p_id IS NULL) AND NOT (p_comments IS NULL) THEN + + UPDATE DataCollection + SET comments = concat_ws(p_separator, comments, p_comments) + WHERE dataCollectionId = p_id; + + ELSE + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory arguments p_id and/or p_comments are NULL'; + END IF; +END;; +DELIMITER ; diff --git a/schemas/ispyb/tables.sql b/schemas/ispyb/tables.sql index ab88af1b..ebb7c00f 100644 --- a/schemas/ispyb/tables.sql +++ b/schemas/ispyb/tables.sql @@ -4043,11 +4043,21 @@ CREATE TABLE `Tomogram` ( `xAxisCorrection` float DEFAULT NULL COMMENT 'X axis angle (etomo), unit: degrees', `tiltAngleOffset` float DEFAULT NULL COMMENT 'tilt Axis offset (etomo), unit: degrees', `zShift` float DEFAULT NULL COMMENT 'shift to center volumen in Z (etomo)', + `fileDirectory` varchar(255) DEFAULT NULL COMMENT 'Directory path for files referenced by this table', + `centralSliceImage` varchar(255) DEFAULT NULL COMMENT 'Tomogram central slice file', + `tomogramMovie` varchar(255) DEFAULT NULL COMMENT 'Movie traversing the tomogram across an axis', + `xyShiftPlot` varchar(255) DEFAULT NULL COMMENT 'XY shift plot file', + `projXY` varchar(255) DEFAULT NULL COMMENT 'XY projection file', + `projXZ` varchar(255) DEFAULT NULL COMMENT 'XZ projection file', + `processingJobId` int(11) unsigned DEFAULT NULL, + `recordTimeStamp` datetime DEFAULT current_timestamp() COMMENT 'Creation or last update date/time', PRIMARY KEY (`tomogramId`), KEY `Tomogram_fk_dataCollectionId` (`dataCollectionId`), KEY `Tomogram_fk_autoProcProgramId` (`autoProcProgramId`), + KEY `Tomogram_fk_processingJobId` (`processingJobId`), CONSTRAINT `Tomogram_fk_autoProcProgramId` FOREIGN KEY (`autoProcProgramId`) REFERENCES `AutoProcProgram` (`autoProcProgramId`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `Tomogram_fk_dataCollectionId` FOREIGN KEY (`dataCollectionId`) REFERENCES `DataCollection` (`dataCollectionId`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `Tomogram_fk_dataCollectionId` FOREIGN KEY (`dataCollectionId`) REFERENCES `DataCollection` (`dataCollectionId`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `Tomogram_fk_processingJobId` FOREIGN KEY (`processingJobId`) REFERENCES `ProcessingJob` (`processingJobId`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='For storing per-sample, per-position data analysis results (reconstruction)'; /*!40101 SET character_set_client = @saved_cs_client */; DROP TABLE IF EXISTS `UserGroup`;