Comments (3)
Hello @zaplitny,
It looks like this could work, yes. But since grdb_migrations
is an internal table, not even mentioned in the documentation, I would not recommend messing with it directly. Future GRDB versions may modify the grdb_migrations
schema, and your code would stop working.
Instead, you can rely of the fact that GRDB never modifies user_version
by itself. So if it is not zero, you know that the app opens a database that was previously handled by FMDB.
You can thus register one GRDB migration per FMDB migration:
var migrator = ...
migrator.registerMigration("fmdb-1") { db in
guard try db.userVersion() < 1 else {
// Migration already applied by FMDB
return
}
// apply script 1
}
migrator.registerMigration("fmdb-2") { db in
guard try db.userVersion() < 2 else {
// Migration already applied by FMDB
return
}
// apply script 2
}
...
migrator.registerMigration("first-post-fmdb-migration") { db in
...
}
Also possible: just register one GRDB migration for all FMDB migrations:
var migrator = ...
migrator.registerMigration("fmdb") { db in
let version = try db.userVersion()
if version < 1 {
// apply script 1
}
if version < 2 {
// apply script 2
}
...
}
migrator.registerMigration("first-post-fmdb-migration") { db in
...
}
Both sample codes use this little Database
extension:
extension Database {
func userVersion() -> Int {
// Force-unwrap is ok: user_version is always returned.
try Int.fetchOne(db, sql: "PRAGMA user_version")!
}
}
from grdb.swift.
Thanks a lot, @groue . It's much better solution
from grdb.swift.
Cool! Happy GRDB :-)
from grdb.swift.
Related Issues (20)
- Missing column crash after migration is performed HOT 12
- Issue with aggregate HOT 24
- can upsertAndFetch support list record? now only support one record HOT 9
- Async bug? (reads not seeing writes in sequential async code) HOT 10
- Custom sqllite version HOT 5
- `databaseDateEncodingStrategy` not work when implement `func encode(to container: inout PersistenceContainer)` HOT 3
- raw SQL can support insert array? HOT 1
- primarykey(_:) does not allow specifying a schema name HOT 5
- dumpContent dumps undesired information from FTS5 virtual tables HOT 1
- Catch a `recordNotFound` error when using `MutablePersistableRecord.save(db)` to update or insert. HOT 4
- GRDB called a `Not implemented` function while inserting. HOT 2
- Issue with having in fetch query HOT 5
- `databaseDateEncodingStrategy` not wok when update a existing record HOT 1
- Throwing subscript Row value HOT 4
- Linker error when building for watchOS with Address Sanitizer enabled HOT 7
- Conflicting Database.logError ? HOT 3
- “database disk image is malformed” when deleting some datas HOT 1
- Setting a default value for a date time column HOT 3
- Pool.get got "priority inversions" warnings in concurrent visit. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grdb.swift.