diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 63e0e0897..37ae1e361 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -461,22 +461,6 @@ public final class Database { assertValidQueue() columnInfosCache = [:] } - - /// When false, the schema cache is disabled. - private var schemaCacheIsEnabled: Bool - - func withDisabledSchemaCache(@noescape block:() throws -> ()) rethrows { - assertValidQueue() - - var schemaCacheWasEnabled = schemaCacheIsEnabled - defer { - schemaCacheIsEnabled = schemaCacheWasEnabled - } - - schemaCacheIsEnabled = false - clearSchemaCache() - try block() - } /// The last error message var lastErrorMessage: String? { return String.fromCString(sqlite3_errmsg(sqliteConnection)) } @@ -599,15 +583,13 @@ public final class Database { // Cache for columnInfosForTable(named:) private var columnInfosCache: [String: [ColumnInfo]] = [:] private func columnInfosForTable(named tableName: String) -> [ColumnInfo] { - if let columnInfos = columnInfosCache[tableName] where schemaCacheIsEnabled { + if let columnInfos = columnInfosCache[tableName] { return columnInfos } else { // This pragma is case-insensitive: PRAGMA table_info("PERSONS") and // PRAGMA table_info("persons") yield the same results. let columnInfos = ColumnInfo.fetchAll(self, "PRAGMA table_info(\(tableName.quotedDatabaseIdentifier))") - if schemaCacheIsEnabled { - columnInfosCache[tableName] = columnInfos - } + columnInfosCache[tableName] = columnInfos return columnInfos } } @@ -637,7 +619,6 @@ public final class Database { init(path: String, configuration: Configuration) throws { self.configuration = configuration - self.schemaCacheIsEnabled = true // See https://www.sqlite.org/c3ref/open.html var sqliteConnection = SQLiteConnection() diff --git a/GRDB/Migrations/DatabaseMigrator.swift b/GRDB/Migrations/DatabaseMigrator.swift index 73324986a..a4f9fb980 100644 --- a/GRDB/Migrations/DatabaseMigrator.swift +++ b/GRDB/Migrations/DatabaseMigrator.swift @@ -85,10 +85,8 @@ public struct DatabaseMigrator { /// - throws: An eventual error thrown by the registered migration blocks. public func migrate(dbQueue: DatabaseQueue) throws { try dbQueue.inDatabase { db in - try db.withDisabledSchemaCache { - try self.setupMigrations(db) - try self.runMigrations(db) - } + try self.setupMigrations(db) + try self.runMigrations(db) } } @@ -112,6 +110,9 @@ public struct DatabaseMigrator { let appliedMigrationIdentifiers = String.fetchAll(db, "SELECT identifier FROM grdb_migrations") try migrations .filter { !appliedMigrationIdentifiers.contains($0.identifier) } - .forEach { try $0.run(db) } + .forEach { + try $0.run(db) + db.clearSchemaCache() + } } } \ No newline at end of file