DbUpdate 8 - geography update stuff

This commit is contained in:
Rick Falkvinge
2014-12-21 20:53:00 +01:00
parent 38b6c3a971
commit 764ffeda5f
2 changed files with 82 additions and 0 deletions
+1
View File
@@ -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]
+81
View File
@@ -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
#