Skip to content

Commit fe7c042

Browse files
authored
New stored procedure upsert_dc_grid_v2 using params p_micronsPerPixelX,Y (#198)
* New sproc upsert_dc_grid_v2 using params p_micronsPerPixelX,Y * Add grant to execute new sproc upsert_dc_grid_v2 * Refresh schema files with new sproc upsert_dc_grid_v2 * Update history with new stored procedure * Bump up version to 2.1.0
1 parent c124be2 commit fe7c042

File tree

6 files changed

+122
-5
lines changed

6 files changed

+122
-5
lines changed

HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ History
55
Unreleased / master
66
-------------------
77

8+
2.1.0 (2023-06-05)
9+
-------------------
10+
11+
* New stored procedure ``upsert_dc_grid_v2`` and ``EXECUTE`` permission on it for the relevant role
12+
813
2.0.0 (2023-05-15)
914
-------------------
1015

grants/ispyb_acquisition.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ GRANT EXECUTE ON PROCEDURE update_dc_machine TO 'ispyb_acquisition';
3434
GRANT EXECUTE ON PROCEDURE upsert_sample_image_analysis TO 'ispyb_acquisition';
3535
GRANT EXECUTE ON PROCEDURE upsert_dcg_grid TO 'ispyb_acquisition';
3636
GRANT EXECUTE ON PROCEDURE upsert_dc_grid TO 'ispyb_acquisition';
37+
GRANT EXECUTE ON PROCEDURE upsert_dc_grid_v2 TO 'ispyb_acquisition';
3738

3839
GRANT EXECUTE ON PROCEDURE update_dc_append_comments TO 'ispyb_acquisition';
3940
GRANT EXECUTE ON PROCEDURE update_dc_position TO 'ispyb_acquisition';

schemas/ispyb/lookups.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
1111

1212
/*!40000 ALTER TABLE `AdminVar` DISABLE KEYS */;
13-
INSERT INTO `AdminVar` (`varId`, `name`, `value`) VALUES (4,'schemaVersion','2.0.0');
13+
INSERT INTO `AdminVar` (`varId`, `name`, `value`) VALUES (4,'schemaVersion','2.1.0');
1414
/*!40000 ALTER TABLE `AdminVar` ENABLE KEYS */;
1515

1616
/*!40000 ALTER TABLE `SchemaStatus` DISABLE KEYS */;
@@ -227,7 +227,8 @@ INSERT INTO `SchemaStatus` (`schemaStatusId`, `scriptName`, `schemaStatus`, `rec
227227
(252,'2023_05_05_ParticleClassificationGroup_selected.sql','DONE','2023-05-05 14:25:42'),
228228
(253,'2023_05_09_Dewar_modify_comments.sql','DONE','2023-05-11 15:32:52'),
229229
(254,'2023_05_11_ParticleClassification_selected.sql','DONE','2023-05-11 15:32:52'),
230-
(255,'2023_05_15_AdminVar_bump_version.sql','DONE','2023-05-15 09:59:49');
230+
(255,'2023_05_15_AdminVar_bump_version.sql','DONE','2023-05-15 09:59:49'),
231+
(256,'2023_06_05_AdminVar_bump_version.sql','DONE','2023-06-05 15:13:35');
231232
/*!40000 ALTER TABLE `SchemaStatus` ENABLE KEYS */;
232233

233234
/*!40000 ALTER TABLE `ComponentType` DISABLE KEYS */;

schemas/ispyb/routines.sql

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ DELIMITER ;
130130
/*!50003 SET character_set_results = utf8mb3 */ ;
131131
/*!50003 SET collation_connection = utf8mb3_general_ci */ ;
132132
DELIMITER ;;
133-
CREATE FUNCTION `retrieve_proposal_title`(p_proposal_code varchar(5), p_proposal_number int) RETURNS varchar(255) CHARSET latin1 COLLATE latin1_swedish_ci
133+
CREATE FUNCTION `retrieve_proposal_title`(p_proposal_code varchar(5), p_proposal_number int) RETURNS varchar(255) CHARSET latin1
134134
READS SQL DATA
135135
BEGIN
136136
DECLARE ret_title varchar(255);
@@ -155,7 +155,7 @@ DELIMITER ;
155155
/*!50003 SET character_set_results = utf8mb3 */ ;
156156
/*!50003 SET collation_connection = utf8mb3_general_ci */ ;
157157
DELIMITER ;;
158-
CREATE FUNCTION `retrieve_proposal_title_v2`(p_proposalCode varchar(5), p_proposalNumber int) RETURNS varchar(255) CHARSET latin1 COLLATE latin1_swedish_ci
158+
CREATE FUNCTION `retrieve_proposal_title_v2`(p_proposalCode varchar(5), p_proposalNumber int) RETURNS varchar(255) CHARSET latin1
159159
READS SQL DATA
160160
COMMENT 'Retrieve the title for a given proposal code and number.'
161161
BEGIN
@@ -206,7 +206,7 @@ DELIMITER ;
206206
/*!50003 SET character_set_results = utf8mb3 */ ;
207207
/*!50003 SET collation_connection = utf8mb3_general_ci */ ;
208208
DELIMITER ;;
209-
CREATE FUNCTION `root_replace`(p_str varchar(255), p_oldroot varchar(255), p_newroot varchar(255)) RETURNS varchar(255) CHARSET latin1 COLLATE latin1_swedish_ci
209+
CREATE FUNCTION `root_replace`(p_str varchar(255), p_oldroot varchar(255), p_newroot varchar(255)) RETURNS varchar(255) CHARSET latin1
210210
COMMENT 'Returns a varchar where the old root p_oldroot (the leftmost part) of p_str has been replaced with a new root p_newroot'
211211
BEGIN
212212
DECLARE path_len smallint unsigned DEFAULT LENGTH(p_oldroot);
@@ -9009,6 +9009,63 @@ DELIMITER ;
90099009
/*!50003 SET character_set_results = @saved_cs_results */ ;
90109010
/*!50003 SET collation_connection = @saved_col_connection */ ;
90119011
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
9012+
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
9013+
/*!50003 DROP PROCEDURE IF EXISTS `upsert_dc_grid_v2` */;
9014+
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
9015+
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
9016+
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
9017+
/*!50003 SET character_set_client = utf8mb3 */ ;
9018+
/*!50003 SET character_set_results = utf8mb3 */ ;
9019+
/*!50003 SET collation_connection = utf8mb3_general_ci */ ;
9020+
DELIMITER ;;
9021+
CREATE PROCEDURE `upsert_dc_grid_v2`(
9022+
INOUT p_id int(11) unsigned,
9023+
p_dcId int(11) unsigned,
9024+
p_dxInMm double,
9025+
p_dyInMm double,
9026+
p_stepsX double,
9027+
p_stepsY double,
9028+
p_meshAngle double,
9029+
p_micronsPerPixelX float,
9030+
p_micronsPerPixelY float,
9031+
p_snapshotOffsetXPixel float,
9032+
p_snapshotOffsetYPixel float,
9033+
p_orientation enum('vertical','horizontal'),
9034+
p_snaked boolean
9035+
)
9036+
MODIFIES SQL DATA
9037+
BEGIN
9038+
IF p_dcId IS NOT NULL THEN
9039+
INSERT INTO GridInfo (gridInfoId, dataCollectionId, dx_mm, dy_mm, steps_x, steps_y, meshAngle,
9040+
micronsPerPixelX, micronsPerPixelY, snapshot_offsetXPixel, snapshot_offsetYPixel,
9041+
orientation, snaked)
9042+
VALUES (p_id, p_dcId, p_dxInMm, p_dyInMm, p_stepsX, p_stepsY, p_meshAngle,
9043+
p_micronsPerPixelX, p_micronsPerPixelY, p_snapshotOffsetXPixel, p_snapshotOffsetYPixel,
9044+
p_orientation, p_snaked)
9045+
ON DUPLICATE KEY UPDATE
9046+
dataCollectionId = IFNULL(p_dcId, dataCollectionId),
9047+
dx_mm = IFNULL(p_dxInMm, dx_mm),
9048+
dy_mm = IFNULL(p_dyInMm, dy_mm),
9049+
steps_x = IFNULL(p_stepsX, steps_x),
9050+
steps_y = IFNULL(p_stepsY, steps_y),
9051+
meshAngle = IFNULL(p_meshAngle, meshAngle),
9052+
micronsPerPixelX = IFNULL(p_micronsPerPixelX, micronsPerPixelX),
9053+
micronsPerPixelY = IFNULL(p_micronsPerPixelY, micronsPerPixelY),
9054+
snapshot_offsetXPixel = IFNULL(p_snapshotOffsetXPixel, snapshot_offsetXPixel),
9055+
snapshot_offsetYPixel = IFNULL(p_snapshotOffsetYPixel, snapshot_offsetYPixel),
9056+
orientation = IFNULL(p_orientation, orientation),
9057+
snaked = IFNULL(p_snaked, snaked);
9058+
IF LAST_INSERT_ID() <> 0 THEN
9059+
SET p_id = LAST_INSERT_ID();
9060+
END IF;
9061+
END IF;
9062+
END ;;
9063+
DELIMITER ;
9064+
/*!50003 SET sql_mode = @saved_sql_mode */ ;
9065+
/*!50003 SET character_set_client = @saved_cs_client */ ;
9066+
/*!50003 SET character_set_results = @saved_cs_results */ ;
9067+
/*!50003 SET collation_connection = @saved_col_connection */ ;
9068+
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
90129069
/*!50003 SET sql_mode = '' */ ;
90139070
/*!50003 DROP PROCEDURE IF EXISTS `upsert_dc_group` */;
90149071
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-- Example call:
2+
-- SET @id := NULL;
3+
-- CALL upsert_dc_grid_v2(@id, 993677, 1.0, 2.0, 3, 4, 90, 10, 20, 30, 40, 'vertical', TRUE);
4+
5+
DELIMITER ;;
6+
CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `upsert_dc_grid_v2`(
7+
INOUT p_id int(11) unsigned,
8+
p_dcId int(11) unsigned,
9+
p_dxInMm double,
10+
p_dyInMm double,
11+
p_stepsX double,
12+
p_stepsY double,
13+
p_meshAngle double,
14+
p_micronsPerPixelX float,
15+
p_micronsPerPixelY float,
16+
p_snapshotOffsetXPixel float,
17+
p_snapshotOffsetYPixel float,
18+
p_orientation enum('vertical','horizontal'),
19+
p_snaked boolean
20+
)
21+
MODIFIES SQL DATA
22+
BEGIN
23+
IF p_dcId IS NOT NULL THEN
24+
INSERT INTO GridInfo (gridInfoId, dataCollectionId, dx_mm, dy_mm, steps_x, steps_y, meshAngle,
25+
micronsPerPixelX, micronsPerPixelY, snapshot_offsetXPixel, snapshot_offsetYPixel,
26+
orientation, snaked)
27+
VALUES (p_id, p_dcId, p_dxInMm, p_dyInMm, p_stepsX, p_stepsY, p_meshAngle,
28+
p_micronsPerPixelX, p_micronsPerPixelY, p_snapshotOffsetXPixel, p_snapshotOffsetYPixel,
29+
p_orientation, p_snaked)
30+
ON DUPLICATE KEY UPDATE
31+
dataCollectionId = IFNULL(p_dcId, dataCollectionId),
32+
dx_mm = IFNULL(p_dxInMm, dx_mm),
33+
dy_mm = IFNULL(p_dyInMm, dy_mm),
34+
steps_x = IFNULL(p_stepsX, steps_x),
35+
steps_y = IFNULL(p_stepsY, steps_y),
36+
meshAngle = IFNULL(p_meshAngle, meshAngle),
37+
micronsPerPixelX = IFNULL(p_micronsPerPixelX, micronsPerPixelX),
38+
micronsPerPixelY = IFNULL(p_micronsPerPixelY, micronsPerPixelY),
39+
snapshot_offsetXPixel = IFNULL(p_snapshotOffsetXPixel, snapshot_offsetXPixel),
40+
snapshot_offsetYPixel = IFNULL(p_snapshotOffsetYPixel, snapshot_offsetYPixel),
41+
orientation = IFNULL(p_orientation, orientation),
42+
snaked = IFNULL(p_snaked, snaked);
43+
IF LAST_INSERT_ID() <> 0 THEN
44+
SET p_id = LAST_INSERT_ID();
45+
END IF;
46+
END IF;
47+
END ;;
48+
DELIMITER ;
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 ('2023_06_05_AdminVar_bump_version.sql', 'ONGOING');
2+
3+
UPDATE AdminVar SET `value` = '2.1.0' WHERE `name` = 'schemaVersion';
4+
5+
UPDATE SchemaStatus SET schemaStatus = 'DONE' WHERE scriptName = '2023_06_05_AdminVar_bump_version.sql';

0 commit comments

Comments
 (0)