From e64c67421a46cf2be8e5b06241f3fc3b735fcbe8 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Thu, 30 Nov 2017 12:19:16 +0100 Subject: [PATCH] Db0065 --- Database/Configuration.cs | 2 +- Database/Schemata/revisions.txt | 1 + Database/Schemata/upgrade-0065.sql | 47 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Database/Schemata/upgrade-0065.sql diff --git a/Database/Configuration.cs b/Database/Configuration.cs index d6a3431c..ddfd1b07 100644 --- a/Database/Configuration.cs +++ b/Database/Configuration.cs @@ -12,7 +12,7 @@ namespace Swarmops.Database /// /// This is the IN-CODE revision of the database. The version we expect to be running against. /// - public static int DbVersionExpected => 64; + public static int DbVersionExpected => 65; // This class is in horrible need of serious refactoring. For its simplicity in task, it's a horrible bowl of spaghetti. diff --git a/Database/Schemata/revisions.txt b/Database/Schemata/revisions.txt index 59c37a78..1dde232b 100644 --- a/Database/Schemata/revisions.txt +++ b/Database/Schemata/revisions.txt @@ -62,3 +62,4 @@ 0062 - Added OrganizationSequenceId to OutboundInvoices (like 0041 but outbound) [RF] 0063 - Added DeriveUnique to HotBitcoinAddresses for ability to create unique HBAs [RF] 0064 - Quick fix for OutboundInvoices (how did this error happen?) [RF] +0065 - Dumb fix for 0062 (or rather, the error was dumb) [RF] diff --git a/Database/Schemata/upgrade-0065.sql b/Database/Schemata/upgrade-0065.sql new file mode 100644 index 00000000..0c8ddd5c --- /dev/null +++ b/Database/Schemata/upgrade-0065.sql @@ -0,0 +1,47 @@ +DROP PROCEDURE IF EXISTS `CreateOutboundInvoice` + +# + +CREATE PROCEDURE `CreateOutboundInvoice`( + organizationId INTEGER, + createdDateTime DATETIME, + createdByPersonId INTEGER, + dueDate DATETIME, + budgetId INTEGER, + customerName VARCHAR(128), + invoiceAddressPaper VARCHAR(256), + invoiceAddressMail VARCHAR(128), + currencyId INTEGER, + reference VARCHAR(64), + domestic TINYINT(1), + securityCode VARCHAR(16), + theirReference VARCHAR(64) +) +BEGIN + + DECLARE newIdentity INTEGER; + DECLARE sequenceNumber INTEGER; + + INSERT INTO OutboundInvoices + (CustomerName,InvoiceAddressPaper,InvoiceAddressMail,CurrencyId, + BudgetId,OrganizationId,CreatedDateTime,CreatedByPersonId, + DueDate,ReminderCount,Reference,Open,Domestic,Sent,SecurityCode,TheirReference) + VALUES + (customerName,invoiceAddressPaper,invoiceAddressMail,currencyId, + budgetId,organizationId,createdDateTime,createdByPersonId, + dueDate,0,reference,1,domestic,0,securityCode,theirReference); + + SELECT LAST_INSERT_ID() INTO newIdentity; + + SELECT COUNT(*) FROM OutboundInvoices WHERE + OutboundInvoices.OrganizationId = organizationId AND + OutboundInvoices.OutboundInvoiceId <= newIdentity INTO sequenceNumber; + + UPDATE OutboundInvoices + SET OutboundInvoices.OrganizationSequenceId = sequenceNumber + WHERE OutboundInvoices.OutboundInvoiceId = newIdentity; + + SELECT newIdentity AS Identity; + +END +