Skip to content

Commit 87ea17d

Browse files
committed
Bootstrap the bodies cache into .cacheDir
Also compare the version and dump different caches.
1 parent 5b817d0 commit 87ea17d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Sources/Bodies/BodiesApp.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,23 @@ struct BodiesApp: App {
77
// "overwrite" can be used during development to get a clean database on
88
// each run.
99
#if DEBUG
10-
let database = try! BodiesDB.bootstrap(overwrite: true)
10+
let database =
11+
try! BodiesDB.bootstrap(into: .cachesDirectory, overwrite: true)
1112
#else
12-
let database = try! BodiesDB.bootstrap()
13+
let database = try! BodiesDB.bootstrap(into: .cachesDirectory)
1314
#endif
15+
16+
init() {
17+
// Check whether a migration is necessary.
18+
let schemaVersion =
19+
try! database.get(pragma: "user_version", as: Int.self)
20+
if schemaVersion != BodiesDB.userVersion {
21+
try! database.fetch("UPDATE") { _, _ in }
22+
23+
print("Dumping cache, the version is outdated.")
24+
_ = try! BodiesDB.bootstrap(overwrite: true)
25+
}
26+
}
1427

1528
var body: some Scene {
1629
WindowGroup {

0 commit comments

Comments
 (0)