From 764ffeda5f19f5cd01caf45aa2344358e913c6e2 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sun, 21 Dec 2014 20:53:00 +0100 Subject: [PATCH] DbUpdate 8 - geography update stuff --- Database/Schemata/revisions.txt | 1 + Database/Schemata/upgrade-0008.sql | 81 ++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 Database/Schemata/upgrade-0008.sql diff --git a/Database/Schemata/revisions.txt b/Database/Schemata/revisions.txt index 2aaf9886..b0a3ef81 100644 --- a/Database/Schemata/revisions.txt +++ b/Database/Schemata/revisions.txt @@ -5,3 +5,4 @@ 0005 - Changed PostalCodeLength for NO DK to 4; for GH to zero; added Country.Currency. [Rick Falkvinge] 0006 - Added Memberships.LocalNumber and .FamilyNumber; added CurrencyExchangeRate tables/procs. [Rick Falkvinge] 0007 - NL update; added Lat/Long to PostalCodes and to People, indexed [RF] +0008 - GeographyUpdate updates ahead of deploying: added country, Guid [RF] diff --git a/Database/Schemata/upgrade-0008.sql b/Database/Schemata/upgrade-0008.sql new file mode 100644 index 00000000..53ef0dda --- /dev/null +++ b/Database/Schemata/upgrade-0008.sql @@ -0,0 +1,81 @@ +ALTER TABLE `GeographyUpdates` +ADD COLUMN `GeographyUpdateSourceId` INT(11) NOT NULL AFTER `GeographyUpdateTypeId`, +ADD COLUMN `CountryCode` VARCHAR(8) NOT NULL AFTER `EffectiveDateTime`, +ADD COLUMN `Guid` VARCHAR(40) NOT NULL AFTER `GeographyUpdateSourceId`, +ADD INDEX `indexGuid` (`Guid` ASC) + + +# + + +CREATE TABLE `GeographyUpdateSources` ( + `GeographyUpdateSourceId` INT NOT NULL AUTO_INCREMENT, + `Name` VARCHAR(128) NOT NULL, + PRIMARY KEY (`GeographyUpdateSourceId`), + INDEX `indexName` (`Name` ASC)) + + +# + + +ALTER TABLE `GeographyUpdateTypes` +ADD INDEX `indexName` (`Name` ASC) + + +# + + +ALTER TABLE `Countries` +ADD COLUMN `PostalCodeFormat` VARCHAR(32) NOT NULL DEFAULT '' AFTER `PostalCodeLength` + + +# + + +DROP PROCEDURE `CreateGeographyUpdate` + + +# + + +CREATE PROCEDURE `CreateGeographyUpdate`( + geographyUpdateType VARCHAR(128), + geographyUpdateSource VARCHAR(128), + guid VARCHAR(40), + countryCode VARCHAR(8), + changeDataXml TEXT, + createdDateTime DATETIME, + effectiveDateTime DATETIME +) +BEGIN + + DECLARE geographyUpdateTypeId INTEGER; + DECLARE geographyUpdateSourceId INTEGER; + + IF ((SELECT COUNT(*) FROM GeographyUpdateTypes WHERE GeographyUpdateTypes.Name=geographyUpdateType) = 0) + THEN + INSERT INTO GeographyUpdateTypes (Name) VALUES (geographyUpdateType); + SELECT LAST_INSERT_ID() INTO geographyUpdateTypeId; + ELSE + SELECT GeographyUpdateTypes.GeographyUpdateTypeId INTO geographyUpdateTypeId FROM GeographyUpdateTypes + WHERE GeographyUpdateTypes.Name=geographyUpdateType; + END IF; + + IF ((SELECT COUNT(*) FROM GeographyUpdateSources WHERE GeographyUpdateSources.Name=geographyUpdateSource) = 0) + THEN + INSERT INTO GeographyUpdateSources (Name) VALUES (geographyUpdateSource); + SELECT LAST_INSERT_ID() INTO geographyUpdateSourceId; + ELSE + SELECT GeographyUpdateSources.GeographyUpdateSourceId INTO geographyUpdateSourceId FROM GeographyUpdateSources + WHERE GeographyUpdateSources.Name=geographyUpdateSource; + END IF; + + INSERT INTO GeographyUpdates (GeographyUpdateTypeId,GeographyUpdateSourceId,Guid,CreatedDateTime,EffectiveDateTime,CountryCode,ChangeDataXml,Processed) + VALUES (geographyUpdateTypeId,geographyUpdateSourceId,guid,createdDateTime,effectiveDateTime,countryCode,changeDataXml,0); + + SELECT LAST_INSERT_ID() As Identity; + +END + + +# \ No newline at end of file