Explorar el Código

Add missing Migration parameter update and a fix for boxes where the migration has already taken place without the update.

Brett Credo hace 8 años
padre
commit
594eb7f36b
Se han modificado 1 ficheros con 13 adiciones y 4 borrados
  1. 13 4
      BulkPrinting/BulkPrinting/Migrations.cs

+ 13 - 4
BulkPrinting/BulkPrinting/Migrations.cs

132
                 db,
132
                 db,
133
                 "ALTER TABLE Orders ADD COLUMN InternalReference VARCHAR(32)",
133
                 "ALTER TABLE Orders ADD COLUMN InternalReference VARCHAR(32)",
134
                 "ALTER TABLE Batch ADD COLUMN InternalReference VARCHAR(32)",
134
                 "ALTER TABLE Batch ADD COLUMN InternalReference VARCHAR(32)",
135
+
136
+                // IMPORTANT
135
                 "INSERT INTO Parameters (Key, Value) VALUES ('Migration','1')"
137
                 "INSERT INTO Parameters (Key, Value) VALUES ('Migration','1')"
136
             );
138
             );
137
         }
139
         }
150
                 "CREATE UNIQUE INDEX Parameters_Key ON Parameters(Key)",
152
                 "CREATE UNIQUE INDEX Parameters_Key ON Parameters(Key)",
151
                 "CREATE INDEX Orders_OrderDate ON Orders(OrderDate)",
153
                 "CREATE INDEX Orders_OrderDate ON Orders(OrderDate)",
152
                 "CREATE INDEX OrderedItems_OrderId ON OrderedItems(OrderId)",
154
                 "CREATE INDEX OrderedItems_OrderId ON OrderedItems(OrderId)",
153
-                "UPDATE Parameters SET Value='2' WHERE Key='Migration'",
154
                 "UPDATE Batch SET Downloaded=(ReadyForDownload=1 AND DeliveredQuantity<=COALESCE((SELECT COUNT(*) FROM Voucher WHERE Voucher.BatchId=Batch.Id), 0))",
155
                 "UPDATE Batch SET Downloaded=(ReadyForDownload=1 AND DeliveredQuantity<=COALESCE((SELECT COUNT(*) FROM Voucher WHERE Voucher.BatchId=Batch.Id), 0))",
155
                 "INSERT INTO Parameters (Key, Value) VALUES ('LastSyncedBatchId', '0')",
156
                 "INSERT INTO Parameters (Key, Value) VALUES ('LastSyncedBatchId', '0')",
156
                 "INSERT INTO Parameters (Key, Value) VALUES ('SyncBackwardsFromLogId', '0')",
157
                 "INSERT INTO Parameters (Key, Value) VALUES ('SyncBackwardsFromLogId', '0')",
165
                 "INSERT INTO Logs_New (Id, UserId, VoucherId, EventDate, EventType, Retry) " +
166
                 "INSERT INTO Logs_New (Id, UserId, VoucherId, EventDate, EventType, Retry) " +
166
                     "SELECT Id, UserId, VoucherId, EventDate, EventType, Retry FROM Logs",
167
                     "SELECT Id, UserId, VoucherId, EventDate, EventType, Retry FROM Logs",
167
                 "DROP TABLE Logs",
168
                 "DROP TABLE Logs",
168
-                "ALTER TABLE Logs_New RENAME TO Logs"
169
+                "ALTER TABLE Logs_New RENAME TO Logs",
170
+
171
+                // IMPORTANT
172
+                "UPDATE Parameters SET Value='2' WHERE Key='Migration'"
169
             );
173
             );
170
         }
174
         }
171
 
175
 
173
         {
177
         {
174
             return ApplyMigrationQueries(
178
             return ApplyMigrationQueries(
175
                 db,
179
                 db,
176
-                "CREATE INDEX Logs_VoucherId_EventType_Id ON Logs(VoucherId, EventType, Id)"
177
-            );
180
+
181
+                // Forgot to update the migration value initially, hence the 'NOT EXISTS'
182
+                "CREATE INDEX IF NOT EXISTS Logs_VoucherId_EventType_Id ON Logs(VoucherId, EventType, Id)",
183
+
184
+                // IMPORTANT
185
+                "UPDATE Parameters SET Value='3' WHERE Key='Migration'"
186
+           );
178
         }
187
         }
179
     }
188
     }
180
 }
189
 }