diff --git a/Database/Configuration.cs b/Database/Configuration.cs index 07cb2b66..051e5272 100644 --- a/Database/Configuration.cs +++ b/Database/Configuration.cs @@ -14,7 +14,7 @@ namespace Swarmops.Database /// public static int DbVersionExpected { - get { return 30; } + get { return 31; } } diff --git a/Database/Schemata/revisions.txt b/Database/Schemata/revisions.txt index f870be28..e1fb7777 100644 --- a/Database/Schemata/revisions.txt +++ b/Database/Schemata/revisions.txt @@ -28,3 +28,4 @@ 0028 - Bugfix for 0027 [RF] 0029 - Added unspent satoshis to hotaddress on create unspent [RF] 0030 - Added flexibility for Resolver classes for OutboundComms [RF] +0031 - Added foreign ID tables, procs for transactions, to track blockchain [RF] \ No newline at end of file diff --git a/Database/Schemata/upgrade-0031.sql b/Database/Schemata/upgrade-0031.sql new file mode 100644 index 00000000..27a1723b --- /dev/null +++ b/Database/Schemata/upgrade-0031.sql @@ -0,0 +1,49 @@ +CREATE TABLE `FinancialTransactionForeignIds` ( + `FinancialTransactionForeignIdId` INT NOT NULL AUTO_INCREMENT, + `FinancialTransactionId` INT NOT NULL, + `ForeignIdType` INT NOT NULL, + `ForeignId` VARCHAR(256) NOT NULL, + PRIMARY KEY (`FinancialTransactionForeignIdId`), + INDEX `Ix_TxId` (`FinancialTransactionId` ASC), + INDEX `Ix_IdType` (`ForeignIdType` ASC), + INDEX `Ix_Identifier` (`ForeignId` ASC) +) + + +# + + +DROP procedure IF EXISTS `SetFinancialTransactionForeignIdentity` + + +# + + +CREATE PROCEDURE `SetFinancialTransactionForeignIdentity`( + IN financialTransactionId INT, + IN foreignIdType INT, + IN foreignId VARCHAR(256) +) +BEGIN + + IF ((SELECT COUNT(*) FROM FinancialTransactionForeignIds + WHERE FinancialTransactionForeignIds.FinancialTransactionId=financialTransactionId + AND FinancialTransactionForeignIds.ForeignIdType=foreignIdType) = 0) + THEN + + INSERT INTO FinancialTransactionForeignIds (FinancialTransactionId,ForeignIdType,ForeignId) + VALUES (financialTransactionId,foreignIdType,foreignId); + SELECT LAST_INSERT_ID() AS Identity; + + ELSE + + UPDATE FinancialTransactionForeignIds + SET FinancialTransactionForeignId.ForeignId=foreignId + WHERE FinancialTransactionForeignIds.FinancialTransactionId=financialTransactionId + AND FinancialTransactionForeignIds.ForeignIdType=foreignIdType; + + SELECT 0 AS Identity; + + END IF; + +END