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
|
self.network = networkType
|
||||||
}
|
}
|
||||||
|
|
||||||
func performMigration(ufvks: [UnifiedFullViewingKey]) throws {
|
func performMigration() throws {
|
||||||
try migrateCacheDb()
|
try migrateCacheDb()
|
||||||
try migratePendingDb()
|
try migratePendingDb()
|
||||||
}
|
}
|
||||||
|
@ -84,60 +84,62 @@ private extension MigrationManager {
|
||||||
createdTable.column(PendingTransactionSQLDAO.TableColumns.memo)
|
createdTable.column(PendingTransactionSQLDAO.TableColumns.memo)
|
||||||
}
|
}
|
||||||
|
|
||||||
try pendingDb.connection().transaction {
|
try pendingDb.connection().transaction(.immediate) {
|
||||||
try pendingDb.connection().run(statement);
|
try pendingDb.connection().execute(statement);
|
||||||
try self.pendingDb.connection().setUserVersion(PendingDbMigration.v1.rawValue);
|
try pendingDb.connection().setUserVersion(PendingDbMigration.v1.rawValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func migratePendingDbV2() throws {
|
func migratePendingDbV2() throws {
|
||||||
let statement =
|
try pendingDb.connection().transaction(.immediate) {
|
||||||
"""
|
let statement =
|
||||||
ALTER TABLE pending_transactions RENAME TO pending_transactions_old;
|
"""
|
||||||
|
ALTER TABLE pending_transactions RENAME TO pending_transactions_old;
|
||||||
|
|
||||||
CREATE TABLE pending_transactions(
|
CREATE TABLE pending_transactions(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
to_address TEXT,
|
to_address TEXT,
|
||||||
to_internal INTEGER,
|
to_internal INTEGER,
|
||||||
account_index INTEGER NOT NULL,
|
account_index INTEGER NOT NULL,
|
||||||
mined_height INTEGER,
|
mined_height INTEGER,
|
||||||
expiry_height INTEGER,
|
expiry_height INTEGER,
|
||||||
cancelled INTEGER,
|
cancelled INTEGER,
|
||||||
encode_attempts INTEGER DEFAULT (0),
|
encode_attempts INTEGER DEFAULT (0),
|
||||||
error_message TEXT,
|
error_message TEXT,
|
||||||
error_code INTEGER,
|
error_code INTEGER,
|
||||||
submit_attempts INTEGER DEFAULT (0),
|
submit_attempts INTEGER DEFAULT (0),
|
||||||
create_time REAL,
|
create_time REAL,
|
||||||
txid BLOB,
|
txid BLOB,
|
||||||
value INTEGER NOT NULL,
|
value INTEGER NOT NULL,
|
||||||
raw BLOB,
|
raw BLOB,
|
||||||
memo BLOB
|
memo BLOB
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO pending_transactions
|
INSERT INTO pending_transactions
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
to_address,
|
to_address,
|
||||||
NULL,
|
NULL,
|
||||||
account_index,
|
account_index,
|
||||||
mined_height,
|
mined_height,
|
||||||
expiry_height,
|
expiry_height,
|
||||||
cancelled,
|
cancelled,
|
||||||
encode_attempts,
|
encode_attempts,
|
||||||
error_message,
|
error_message,
|
||||||
error_code,
|
error_code,
|
||||||
submit_attempts,
|
submit_attempts,
|
||||||
create_time,
|
create_time,
|
||||||
txid,
|
txid,
|
||||||
value,
|
value,
|
||||||
raw,
|
raw,
|
||||||
memo
|
memo
|
||||||
FROM pending_transactions_old;
|
FROM pending_transactions_old;
|
||||||
"""
|
|
||||||
|
|
||||||
try pendingDb.connection().transaction {
|
DROP TABLE pending_transactions_old
|
||||||
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 {
|
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
|
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
|
return .success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class PendingTransactionRepositoryTests: XCTestCase {
|
||||||
let pendingDbProvider = SimpleConnectionProvider(path: try! TestDbBuilder.pendingTransactionsDbURL().absoluteString)
|
let pendingDbProvider = SimpleConnectionProvider(path: try! TestDbBuilder.pendingTransactionsDbURL().absoluteString)
|
||||||
let dao = PendingTransactionSQLDAO(dbProvider: pendingDbProvider)
|
let dao = PendingTransactionSQLDAO(dbProvider: pendingDbProvider)
|
||||||
let migrations = try! MigrationManager(cacheDbConnection: InMemoryDbProvider(), pendingDbConnection: pendingDbProvider, networkType: .testnet)
|
let migrations = try! MigrationManager(cacheDbConnection: InMemoryDbProvider(), pendingDbConnection: pendingDbProvider, networkType: .testnet)
|
||||||
try! migrations.performMigration(ufvks: [])
|
try! migrations.performMigration()
|
||||||
pendingRepository = dao
|
pendingRepository = dao
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue