diff --git a/schemas/ispyb/lookups.sql b/schemas/ispyb/lookups.sql index c4ed6af..ab7080f 100644 --- a/schemas/ispyb/lookups.sql +++ b/schemas/ispyb/lookups.sql @@ -11,7 +11,7 @@ /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; /*!40000 ALTER TABLE `AdminVar` DISABLE KEYS */; -INSERT INTO `AdminVar` (`varId`, `name`, `value`) VALUES (4,'schemaVersion','4.6.0'); +INSERT INTO `AdminVar` (`varId`, `name`, `value`) VALUES (4,'schemaVersion','4.7.0'); /*!40000 ALTER TABLE `AdminVar` ENABLE KEYS */; /*!40000 ALTER TABLE `SchemaStatus` DISABLE KEYS */; @@ -278,7 +278,16 @@ INSERT INTO `SchemaStatus` (`schemaStatusId`, `scriptName`, `schemaStatus`, `rec (306,'2025_02_25_AdminVar_bump_version.sql','DONE','2025-02-25 15:51:30'), (307,'2025_02_27_ExperimentType_atlas.sql','DONE','2025-03-06 11:58:07'), (308,'2025_03_05_Dewar_dewarRegistryId.sql','DONE','2025-03-06 11:58:07'), -(309,'2025_03_06_AdminVar_bump_version.sql','DONE','2025-03-06 11:58:07'); +(309,'2025_03_06_AdminVar_bump_version.sql','DONE','2025-03-06 11:58:07'), +(310,'2025_03_20_ParticleClassification_angularEfficiency_suggestedTilt.sql','DONE','2025-05-09 15:21:06'), +(311,'2025_04_11_Position_blSampleId_positionType.sql','DONE','2025-05-09 15:21:06'), +(312,'2025_04_16_labContacts_fk_on_delete_set_null.sql','DONE','2025-05-09 15:21:06'), +(313,'2025_04_29_DewarRegistry_fk_labContactId_on_delete_set_null.sql','DONE','2025-05-09 15:21:06'), +(314,'2025_04_30_Shipping_fk_personId_on_delete_set_null.sql','DONE','2025-05-09 15:21:06'), +(315,'2025_05_01_BLSamplePosition.sql','DONE','2025-05-09 15:21:06'), +(316,'2025_05_01_XrayCentringResult_fk_blSampleId.sql','DONE','2025-05-09 15:21:06'), +(317,'2025_05_02_BLSamplePosition_rename_column.sql','DONE','2025-05-09 15:21:06'), +(318,'2025_05_12_AdminVar_bump_version.sql','DONE','2025-05-09 15:21:06'); /*!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 7949622..335dede 100644 --- a/schemas/ispyb/routines.sql +++ b/schemas/ispyb/routines.sql @@ -7456,30 +7456,61 @@ BEGIN DECLARE row_beamlineLocation varchar(20) DEFAULT NULL; DECLARE row_sampleChangerLocation varchar(20) DEFAULT NULL; DECLARE row_proposalId int(10) unsigned DEFAULT NULL; + DECLARE row_proposalCode varchar(45) DEFAULT NULL; + DECLARE row_proposalNumber varchar(45) DEFAULT NULL; DECLARE row_queuedCount int(11) unsigned DEFAULT NULL; + DECLARE row_samples varchar(255) DEFAULT NULL; + + IF p_beamline IS NULL THEN + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory argument p_beamline is NULL'; + END IF; IF NOT (p_registry_barcode IS NULL) THEN START TRANSACTION; - SELECT c.containerId, c.containerStatus, c.dewarId, c.beamlineLocation, c.sampleChangerLocation, s.proposalId, count(cq.containerQueueId) - INTO row_containerId, row_containerStatus, row_dewarId, row_beamlineLocation, row_sampleChangerLocation, row_proposalId, row_queuedCount + SELECT c.containerId, + c.containerStatus, + c.dewarId, + c.beamlineLocation, + c.sampleChangerLocation, + p.proposalId, + p.proposalCode, + p.proposalNumber, + count(cq.containerQueueId) + INTO row_containerId, + row_containerStatus, + row_dewarId, + row_beamlineLocation, + row_sampleChangerLocation, + row_proposalId, + row_proposalCode, + row_proposalNumber, + row_queuedCount FROM Container c INNER JOIN ContainerRegistry cr ON c.containerRegistryId = cr.containerRegistryId INNER JOIN Dewar d ON d.dewarId = c.dewarId INNER JOIN Shipping s ON s.shippingId = d.shippingId + INNER JOIN Proposal p ON p.proposalId = s.proposalId LEFT OUTER JOIN ContainerQueue cq ON cq.containerId = c.containerId WHERE cr.barcode = p_registry_barcode - GROUP BY c.containerId, c.containerStatus, c.dewarId, c.beamlineLocation, c.sampleChangerLocation, s.proposalId + GROUP BY c.containerId, + c.containerStatus, + c.dewarId, + c.beamlineLocation, + c.sampleChangerLocation, + p.proposalId, + p.proposalCode, + p.proposalNumber ORDER BY c.containerId DESC LIMIT 1; SELECT row_containerStatus INTO currentContainerStatus; - + IF NOT row_containerId IS NULL THEN IF (NOT row_containerStatus <=> 'processing') OR (row_beamlineLocation = p_beamline AND row_sampleChangerLocation = p_position) THEN - + UPDATE Container c INNER JOIN Dewar d ON d.dewarId = c.dewarId INNER JOIN Shipping s ON s.shippingId = d.shippingId @@ -7496,8 +7527,8 @@ BEGIN SELECT IF(row_containerStatus<=>'processing', 'at facility', 'processing') INTO currentContainerStatus; IF NOT row_containerStatus <=> 'processing' THEN - - + + UPDATE Container c INNER JOIN Dewar d ON d.dewarId = c.dewarId INNER JOIN Shipping s ON s.shippingId = d.shippingId @@ -7506,12 +7537,12 @@ BEGIN WHERE s.proposalId = row_proposalId AND c.beamlineLocation = p_beamline AND c.sampleChangerLocation = p_position AND c.containerId <> row_containerId; - + INSERT INTO DewarTransportHistory (dewarId, dewarStatus, storageLocation, arrivalDate) VALUES (row_dewarId, 'processing', p_beamline, NOW()); END IF; - + INSERT INTO ContainerHistory (containerId, location, status, beamlineName, currentDewarId) SELECT row_containerId, p_position, IF(row_containerStatus<=>'processing', 'at facility', 'processing'), p_beamline, currentDewarId FROM Container @@ -7525,9 +7556,19 @@ BEGIN ELSE SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory argument p_registry_barcode is NULL'; END IF; + + SELECT group_concat(location ORDER BY cast(location AS integer) SEPARATOR ',') + INTO row_samples + FROM BLSample + WHERE containerId = row_containerId + GROUP BY containerId; + SELECT row_containerId as "containerId", currentContainerStatus as "containerStatus", - row_queuedCount as "queuedCount"; + row_proposalCode as "proposalCode", + row_proposalNumber as "proposalNumber", + row_queuedCount as "queuedCount", + row_samples as "samples"; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; diff --git a/schemas/ispyb/tables.sql b/schemas/ispyb/tables.sql index e3d5244..0b8b6ff 100644 --- a/schemas/ispyb/tables.sql +++ b/schemas/ispyb/tables.sql @@ -605,6 +605,22 @@ CREATE TABLE `BLSampleImage_has_Positioner` ( CONSTRAINT `BLSampleImageHasPositioner_ibfk2` FOREIGN KEY (`positionerId`) REFERENCES `Positioner` (`positionerId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Allows a BLSampleImage to store motor positions along with the image'; /*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS `BLSamplePosition`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `BLSamplePosition` ( + `blSamplePositionId` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key (auto-incremented)', + `blSampleId` int(11) unsigned NOT NULL COMMENT 'FK, references parent sample', + `posX` double DEFAULT NULL, + `posY` double DEFAULT NULL, + `posZ` double DEFAULT NULL, + `recordTimeStamp` datetime DEFAULT NULL COMMENT 'Creation or last update date/time', + `positionType` enum('dispensing') DEFAULT NULL COMMENT 'Type of marked position (e.g.: dispensing location)', + PRIMARY KEY (`blSamplePositionId`), + KEY `BLSamplePosition_fk_blSampleId` (`blSampleId`), + CONSTRAINT `BLSamplePosition_fk_blSampleId` FOREIGN KEY (`blSampleId`) REFERENCES `BLSample` (`blSampleId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; DROP TABLE IF EXISTS `BLSampleType`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8mb4 */; @@ -1687,7 +1703,7 @@ CREATE TABLE `DewarRegistry_has_Proposal` ( CONSTRAINT `DewarRegistry_has_Proposal_ibfk1` FOREIGN KEY (`dewarRegistryId`) REFERENCES `DewarRegistry` (`dewarRegistryId`), CONSTRAINT `DewarRegistry_has_Proposal_ibfk2` FOREIGN KEY (`proposalId`) REFERENCES `Proposal` (`proposalId`), CONSTRAINT `DewarRegistry_has_Proposal_ibfk3` FOREIGN KEY (`personId`) REFERENCES `Person` (`personId`), - CONSTRAINT `DewarRegistry_has_Proposal_ibfk4` FOREIGN KEY (`labContactId`) REFERENCES `LabContact` (`labContactId`) ON DELETE NO ACTION ON UPDATE CASCADE + CONSTRAINT `DewarRegistry_has_Proposal_ibfk4` FOREIGN KEY (`labContactId`) REFERENCES `LabContact` (`labContactId`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; DROP TABLE IF EXISTS `DewarReport`; @@ -2396,6 +2412,8 @@ CREATE TABLE `ParticleClassification` ( `bFactorFitIntercept` float DEFAULT NULL COMMENT 'Intercept of quadratic fit to refinement resolution against the logarithm of the number of particles', `bFactorFitLinear` float DEFAULT NULL COMMENT 'Linear coefficient of quadratic fit to refinement resolution against the logarithm of the number of particles, equal to half of the B factor', `bFactorFitQuadratic` float DEFAULT NULL COMMENT 'Quadratic coefficient of quadratic fit to refinement resolution against the logarithm of the number of particles', + `angularEfficiency` double DEFAULT NULL COMMENT 'Variation in resolution across different angles, 1-2sig/mean', + `suggestedTilt` double DEFAULT NULL COMMENT 'Suggested stage tilt angle to improve angular efficiency. Unit: degrees', PRIMARY KEY (`particleClassificationId`), KEY `ParticleClassification_fk_particleClassificationGroupId` (`particleClassificationGroupId`), CONSTRAINT `ParticleClassification_fk_particleClassificationGroupId` FOREIGN KEY (`particleClassificationGroupId`) REFERENCES `ParticleClassificationGroup` (`particleClassificationGroupId`) ON DELETE CASCADE ON UPDATE CASCADE @@ -3456,9 +3474,9 @@ CREATE TABLE `Shipping` ( KEY `Shipping_FKIndexStatus` (`shippingStatus`), KEY `Shipping_ibfk_4` (`deliveryAgent_flightCodePersonId`), CONSTRAINT `Shipping_ibfk_1` FOREIGN KEY (`proposalId`) REFERENCES `Proposal` (`proposalId`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `Shipping_ibfk_2` FOREIGN KEY (`sendingLabContactId`) REFERENCES `LabContact` (`labContactId`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `Shipping_ibfk_3` FOREIGN KEY (`returnLabContactId`) REFERENCES `LabContact` (`labContactId`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `Shipping_ibfk_4` FOREIGN KEY (`deliveryAgent_flightCodePersonId`) REFERENCES `Person` (`personId`) + CONSTRAINT `Shipping_ibfk_2` FOREIGN KEY (`sendingLabContactId`) REFERENCES `LabContact` (`labContactId`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `Shipping_ibfk_3` FOREIGN KEY (`returnLabContactId`) REFERENCES `LabContact` (`labContactId`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `Shipping_ibfk_4` FOREIGN KEY (`deliveryAgent_flightCodePersonId`) REFERENCES `Person` (`personId`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; DROP TABLE IF EXISTS `ShippingHasSession`; @@ -3762,8 +3780,11 @@ CREATE TABLE `XrayCentringResult` ( `boundingBoxMaxZ` float DEFAULT NULL COMMENT 'Maximum z-coordinate of the bounding box containing the crystal (in voxels)', `status` enum('success','failure','pending') DEFAULT NULL COMMENT 'to be removed', `gridInfoId` int(11) unsigned DEFAULT NULL COMMENT 'to be removed', + `blSampleId` int(11) unsigned DEFAULT NULL COMMENT 'The BLSample attributed for this x-ray centring result, i.e. the actual sample even for multi-pins', PRIMARY KEY (`xrayCentringResultId`), KEY `xrayCentringId` (`xrayCentringId`), + KEY `XrayCentringResult_fk_blSampleId` (`blSampleId`), + CONSTRAINT `XrayCentringResult_fk_blSampleId` FOREIGN KEY (`blSampleId`) REFERENCES `BLSample` (`blSampleId`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `XrayCentringResult_ibfk_1` FOREIGN KEY (`xrayCentringId`) REFERENCES `XrayCentring` (`xrayCentringId`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Xray Centring result.'; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/schemas/ispyb/updates/2025_05_12_AdminVar_bump_version.sql b/schemas/ispyb/updates/2025_05_12_AdminVar_bump_version.sql new file mode 100644 index 0000000..bd1302d --- /dev/null +++ b/schemas/ispyb/updates/2025_05_12_AdminVar_bump_version.sql @@ -0,0 +1,5 @@ +INSERT IGNORE INTO SchemaStatus (scriptName, schemaStatus) VALUES ('2025_05_12_AdminVar_bump_version.sql', 'ONGOING'); + +UPDATE AdminVar SET `value` = '4.7.0' WHERE `name` = 'schemaVersion'; + +UPDATE SchemaStatus SET schemaStatus = 'DONE' WHERE scriptName = '2025_05_12_AdminVar_bump_version.sql';