Skip to content

Commit 4e183f3

Browse files
authored
Merge pull request #78 from powersync-ja/fix-drift-migrations
Fix drift migrations
2 parents 1e64f5d + efe6fa3 commit 4e183f3

12 files changed

+486
-13
lines changed

CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## 2024-11-06
7+
8+
### Changes
9+
10+
---
11+
12+
Packages with breaking changes:
13+
14+
- There are no breaking changes in this release.
15+
16+
Packages with other changes:
17+
18+
- [`drift_sqlite_async` - `v0.2.0`](#drift_sqlite_async---v020)
19+
20+
---
21+
22+
#### `drift_sqlite_async` - `v0.2.0`
23+
24+
- Automatically run Drift migrations
25+
26+
627
## 2024-11-06
728

829
### Changes

packages/drift_sqlite_async/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.0
2+
3+
- Automatically run Drift migrations
4+
15
## 0.2.0-alpha.4
26

37
- Update a dependency to the latest release.

packages/drift_sqlite_async/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Supported functionality:
88
2. Transactions and nested transactions.
99
3. Table updates are propagated between sqlite_async and Drift - watching queries works using either API.
1010
4. Select queries can run concurrently with writes and other select statements.
11+
5. Drift migrations are supported (optional).
1112

1213
## Usage
1314

packages/drift_sqlite_async/example/main.g.dart

+131
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/drift_sqlite_async/example/with_migrations.dart

+6-9
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,18 @@ class AppDatabase extends _$AppDatabase {
2121

2222
@override
2323
MigrationStrategy get migration {
24-
return MigrationStrategy(
25-
onCreate: (m) async {
26-
// In this example, the schema is managed by Drift
27-
await m.createAll();
28-
},
29-
);
24+
return MigrationStrategy(onCreate: (m) async {
25+
// In this example, the schema is managed by Drift.
26+
// For more options, see:
27+
// https://drift.simonbinder.eu/migrations/#usage
28+
await m.createAll();
29+
});
3030
}
3131
}
3232

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

36-
await db.execute(
37-
'CREATE TABLE IF NOT EXISTS todos(id integer primary key, description text)');
38-
3936
final appdb = AppDatabase(db);
4037

4138
// Watch a query on the Drift database

packages/drift_sqlite_async/example/with_migrations.g.dart

+131
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/drift_sqlite_async/lib/src/executor.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class _SqliteAsyncDelegate extends _SqliteAsyncQueryDelegate
1515
implements DatabaseDelegate {
1616
final SqliteConnection db;
1717
bool _closed = false;
18+
bool _calledOpen = false;
1819

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

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

3233
@override
33-
bool get isOpen => !db.closed && !_closed;
34+
bool get isOpen => !db.closed && !_closed && _calledOpen;
3435

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

4145
@override

0 commit comments

Comments
 (0)