
INSERT INTO dbo.StoredBlobs (Id, StateCode, Size, CreatedUtc, LastAccessUtc, ReferenceCount, Details)
	SELECT Id, 'R' AS StateCode, 1 AS Size, StartDateUtc AS CreatedUtc, StartDateUtc AS LastAccessUtc, 1 AS ReferenceCount, Details
	FROM (
		SELECT XmlFileId AS Id, 'Migrated Xml Data' AS Details, StartDateUtc
		FROM dbo.SignatureProcesses
		UNION
		SELECT DataToSignFileId AS Id, 'Migrated Signature Data' AS Details, StartDateUtc
		FROM dbo.SignatureProcesses
		UNION
		SELECT PadesTransferDataFileId AS Id, 'Migrated PAdES Data' AS Details, StartDateUtc
		FROM dbo.SignatureProcesses
		UNION
		SELECT CadesCmsToCoSignFileId AS Id, 'Migrated CAdES Data' AS Details, StartDateUtc
		FROM dbo.SignatureProcesses
	) AS U
	WHERE U.Id IS NOT NULL

UPDATE dbo.SignatureProcesses SET XmlBlobId=XmlFileId,
						DataToSignBlobId=DataToSignFileId,
						PadesTransferDataBlobId=PadesTransferDataFileId,
						CadesCmsToCoSignBlobId=CadesCmsToCoSignFileId
