Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions schemas/ispyb/lookups.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 */;
Expand Down Expand Up @@ -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 */;
Expand Down
61 changes: 51 additions & 10 deletions schemas/ispyb/routines.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 */ ;
Expand Down
29 changes: 25 additions & 4 deletions schemas/ispyb/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 */;
Expand Down Expand Up @@ -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`;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`;
Expand Down Expand Up @@ -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 */;
Expand Down
5 changes: 5 additions & 0 deletions schemas/ispyb/updates/2025_05_12_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 ('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';