Preserve Upload Requests and Tag States
The following steps will migrate upload requests and tag states, or just tag states if that's all that's needed. Elevate 3.2 is required, so install it now if it hasn't been, but don't trigger a model read until instructed to do so by these steps.
- Empty out the EFMigrationHistory table and rename the conflicting entities by running the following SQL statements against the sqldb-tagcontroller database:
DELETE FROM [dbo].[__EFMigrationsHistory]
GO
EXEC sp_rename 'dbo.TagMap', 'TagMapOld';
EXEC sp_rename 'dbo.UploadContent', 'UploadContentOld';
GO
EXEC sp_rename N'dbo.TagMapOld.PK_TagMap', N'PK_TagMapOld', N'INDEX';
EXEC sp_rename N'dbo.UploadContentOld.PK_UploadContent', N'PK_UploadContentOld', N'INDEX';
EXEC sp_rename N'dbo.FK_UploadContent_TagMap_TagMapId', N'FK_UploadContentOld_TagMapOld_TagMapId';
GO
- Wait for func-tagcontroller to create the new tables (i.e., the function app starts successfully and is running). Refreshing or restarting func-tagcontroller may help speed this along.
- Trigger a model read and wait for it to complete: run
ModelReader.exe -r <instance> - If desired, migrate requests by running the following SQL:
INSERT INTO dbo.Requests (EndTime, Publisher, StartTime, [State], SubmitTimeStamp, RequestType, Discriminator)
SELECT EndTime, Publisher, StartTime, [State], SubmitTimeStamp, RequestType, 1
FROM dbo.HistoryUploadRequest
GO
INSERT INTO dbo.Requests (EndTime, Publisher, StartTime, [State], SubmitTimeStamp, RequestType, ServerName, [Database], Template, Discriminator)
SELECT EndTime, Publisher, StartTime, [State], SubmitTimeStamp, RequestType, ServerName, [Database], Template, 2
FROM dbo.EventRequest
GO
- Migrate tag states by running the following SQL:
UPDATE dbo.TagMap
SET Scanning = 1, New = 0
FROM dbo.TagMap TM
INNER JOIN dbo.TagMapOld TMO ON TM.TSID = TMO.Device
WHERE TMO.State = 'Scanning'
GO
UPDATE dbo.TagMap
SET Uploading = 1, New = 0
FROM dbo.TagMap TM
INNER JOIN dbo.TagMapOld TMO ON TM.TSID = TMO.Device
WHERE TMO.State = 'Uploading'
GO
Note
Note that the above commands do not do anything with tags in state Deprecated or Processing. Ideally, no tags would be in Processing when running this command.
- If desired, connect tags to requests with the following SQL:
INSERT INTO dbo.UploadContent (HistoryUploadRequestId, TagMapId)
SELECT R.Id, TM.Id
FROM dbo.UploadContentOld UCO
INNER JOIN dbo.HistoryUploadRequest HUR ON UCO.HistoryUploadRequestId = HUR.Id
INNER JOIN dbo.Requests R ON HUR.SubmitTimeStamp = R.SubmitTimeStamp
INNER JOIN dbo.TagMapOld TMO ON UCO.TagMapId = TMO.Id
INNER JOIN dbo.TagMap TM ON TMO.Device = TM.TSID
GO
- Clear out the old tables with the following SQL:
DROP TABLE UploadContentOld
DROP TABLE TagMapOld
DROP TABLE HistoryUploadRequest
DROP TABLE EventRequest
GO