Skip to content

docs: keep the existing database file when migrating to drift - #3862

Closed
onur-kesim wants to merge 1 commit into
simolus3:developfrom
onur-kesim:docs/drift-flutter-keep-db-path
Closed

onur-kesim wants to merge 1 commit into
simolus3:developfrom
onur-kesim:docs/drift-flutter-keep-db-path

Conversation

@onur-kesim

Copy link
Copy Markdown
Contributor

Refs #3367.

In "Opening a drift database", the guide says the drift snippets open the same database as the code above them, but the previous code opens demo.db while both drift snippets opened db.sqlite. Following the guide literally opens a new, empty database instead of the existing one. Both are now demo.db.

The second part is what #3367 asks for: driftDatabase() stores <name>.sqlite under getApplicationDocumentsDirectory() by default, so someone switching to drift_flutter silently ends up on a different file. The new snippet passes databasePath to keep the existing one, and the text notes that databasePath and databaseDirectory are mutually exclusive.

Documentation only. The two Dart snippets analyze cleanly against the docs package (drift, drift_flutter, path, path_provider). The drift_sqflite snippet only changed its file name; drift_sqflite is not a dependency of the docs package, so it cannot be analyzed there.

On placement: in #3367 you wrote that you were not sure where to put this. The migration guide seemed like the natural home because it already maps old setups to drift, but I am happy to move it into the setup guide instead.

Fix two examples in the "Opening a drift database" section that claimed
to open "the same database" as the code above them, but used a
different file name ('db.sqlite' instead of 'demo.db').

Add a short paragraph and code sample for readers using drift_flutter
instead of a bare NativeDatabase: driftDatabase() names its database
file '$name.sqlite' under getApplicationDocumentsDirectory() by
default (drift_flutter/lib/src/native.dart), which is not the file
opened by the examples above it. Use DriftNativeOptions.databasePath
to point at the existing file instead (databasePath and
databaseDirectory are mutually exclusive, see
drift_flutter/lib/src/connect.dart).

Refs simolus3#3367

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@simolus3

Copy link
Copy Markdown
Owner

Thanks for the contribution! I have merged this in d9f88e5, the changes will be visible with the next drift release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants