Skip to content

Fix drift migrations #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 2024-11-06

### Changes

---

Packages with breaking changes:

- There are no breaking changes in this release.

Packages with other changes:

- [`drift_sqlite_async` - `v0.2.0`](#drift_sqlite_async---v020)

---

#### `drift_sqlite_async` - `v0.2.0`

- Automatically run Drift migrations


## 2024-11-06

### Changes
Expand Down
4 changes: 4 additions & 0 deletions packages/drift_sqlite_async/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.0

- Automatically run Drift migrations

## 0.2.0-alpha.4

- Update a dependency to the latest release.
Expand Down
1 change: 1 addition & 0 deletions packages/drift_sqlite_async/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Supported functionality:
2. Transactions and nested transactions.
3. Table updates are propagated between sqlite_async and Drift - watching queries works using either API.
4. Select queries can run concurrently with writes and other select statements.
5. Drift migrations are supported (optional).

## Usage

Expand Down
131 changes: 131 additions & 0 deletions packages/drift_sqlite_async/example/main.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions packages/drift_sqlite_async/example/with_migrations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,18 @@ class AppDatabase extends _$AppDatabase {

@override
MigrationStrategy get migration {
return MigrationStrategy(
onCreate: (m) async {
// In this example, the schema is managed by Drift
await m.createAll();
},
);
return MigrationStrategy(onCreate: (m) async {
// In this example, the schema is managed by Drift.
// For more options, see:
// https://drift.simonbinder.eu/migrations/#usage
await m.createAll();
});
}
}

Future<void> main() async {
final db = SqliteDatabase(path: 'with_migrations.db');

await db.execute(
'CREATE TABLE IF NOT EXISTS todos(id integer primary key, description text)');

final appdb = AppDatabase(db);

// Watch a query on the Drift database
Expand Down
131 changes: 131 additions & 0 deletions packages/drift_sqlite_async/example/with_migrations.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion packages/drift_sqlite_async/lib/src/executor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class _SqliteAsyncDelegate extends _SqliteAsyncQueryDelegate
implements DatabaseDelegate {
final SqliteConnection db;
bool _closed = false;
bool _calledOpen = false;

_SqliteAsyncDelegate(this.db) : super(db, db.writeLock);

Expand All @@ -30,12 +31,15 @@ class _SqliteAsyncDelegate extends _SqliteAsyncQueryDelegate
_SqliteAsyncTransactionDelegate(db);

@override
bool get isOpen => !db.closed && !_closed;
bool get isOpen => !db.closed && !_closed && _calledOpen;

@override
Future<void> open(QueryExecutorUser user) async {
// Workaround - this ensures the db is open
await db.get('SELECT 1');
// We need to delay this until open() has been called, otherwise
// migrations don't run.
_calledOpen = true;
}

@override
Expand Down
Loading
Loading