Replace `db.run` with `db.execute` to fix migration issues
This commit is contained in:
parent
0fbf90dc82
commit
30a9c066ad
|
@ -36,7 +36,7 @@ class MigrationManager {
|
|||
self.network = networkType
|
||||
}
|
||||
|
||||
func performMigration(ufvks: [UnifiedFullViewingKey]) throws {
|
||||
func performMigration() throws {
|
||||
try migrateCacheDb()
|
||||
try migratePendingDb()
|
||||
}
|
||||
|
@ -84,13 +84,14 @@ private extension MigrationManager {
|
|||
createdTable.column(PendingTransactionSQLDAO.TableColumns.memo)
|
||||
}
|
||||
|
||||
try pendingDb.connection().transaction {
|
||||
try pendingDb.connection().run(statement);
|
||||
try self.pendingDb.connection().setUserVersion(PendingDbMigration.v1.rawValue);
|
||||
try pendingDb.connection().transaction(.immediate) {
|
||||
try pendingDb.connection().execute(statement);
|
||||
try pendingDb.connection().setUserVersion(PendingDbMigration.v1.rawValue);
|
||||
}
|
||||
}
|
||||
|
||||
func migratePendingDbV2() throws {
|
||||
try pendingDb.connection().transaction(.immediate) {
|
||||
let statement =
|
||||
"""
|
||||
ALTER TABLE pending_transactions RENAME TO pending_transactions_old;
|
||||
|
@ -133,11 +134,12 @@ private extension MigrationManager {
|
|||
raw,
|
||||
memo
|
||||
FROM pending_transactions_old;
|
||||
|
||||
DROP TABLE pending_transactions_old
|
||||
"""
|
||||
|
||||
try pendingDb.connection().transaction {
|
||||
try pendingDb.connection().run(statement);
|
||||
try self.pendingDb.connection().setUserVersion(PendingDbMigration.v2.rawValue);
|
||||
try pendingDb.connection().execute(statement);
|
||||
try pendingDb.connection().setUserVersion(PendingDbMigration.v2.rawValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,6 +169,6 @@ extension Connection {
|
|||
}
|
||||
|
||||
func setUserVersion(_ version: Int32) throws {
|
||||
try run("PRAGMA user_version = \(version)")
|
||||
try execute("PRAGMA user_version = \(version)")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -245,6 +245,14 @@ public class Initializer {
|
|||
throw rustBackend.lastError() ?? InitializerError.accountInitFailed
|
||||
}
|
||||
|
||||
let migrationManager = MigrationManager(
|
||||
cacheDbConnection: SimpleConnectionProvider(path: cacheDbURL.path),
|
||||
pendingDbConnection: SimpleConnectionProvider(path: pendingDbURL.path),
|
||||
networkType: self.network.networkType
|
||||
)
|
||||
|
||||
try migrationManager.performMigration()
|
||||
|
||||
return .success
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class PendingTransactionRepositoryTests: XCTestCase {
|
|||
let pendingDbProvider = SimpleConnectionProvider(path: try! TestDbBuilder.pendingTransactionsDbURL().absoluteString)
|
||||
let dao = PendingTransactionSQLDAO(dbProvider: pendingDbProvider)
|
||||
let migrations = try! MigrationManager(cacheDbConnection: InMemoryDbProvider(), pendingDbConnection: pendingDbProvider, networkType: .testnet)
|
||||
try! migrations.performMigration(ufvks: [])
|
||||
try! migrations.performMigration()
|
||||
pendingRepository = dao
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue