-
Notifications
You must be signed in to change notification settings - Fork 11
Added refreshSchema()
#57
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
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3d34040
Added refreshSchema() to SqliteConnection interface.
Chriztiaan d278237
Simplifying refreshSchema implementation by introducing exlusiveLock …
Chriztiaan f90b7eb
Cleanup of function comment.
Chriztiaan 03bca29
Updated changelog.
Chriztiaan 7bb71be
Removed exclusiveLock, simplified implementation of refreshSchema.
Chriztiaan 4fb4228
squashed
Chriztiaan 31c6989
chore(release): publish packages
Chriztiaan 204d5e8
Increased pana score threshold temporarily.
Chriztiaan 05101e8
Added comment to pana threshold alteration.
Chriztiaan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
@TestOn('!browser') | ||
import 'dart:async'; | ||
|
||
import 'package:sqlite_async/sqlite_async.dart'; | ||
import 'package:sqlite_async/src/utils/shared_utils.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../utils/test_utils_impl.dart'; | ||
|
||
final testUtils = TestUtils(); | ||
|
||
void main() { | ||
group('Schema Tests', () { | ||
late String path; | ||
|
||
setUp(() async { | ||
path = testUtils.dbPath(); | ||
await testUtils.cleanDb(path: path); | ||
}); | ||
|
||
tearDown(() async { | ||
await testUtils.cleanDb(path: path); | ||
}); | ||
|
||
createTables(SqliteDatabase db) async { | ||
await db.writeTransaction((tx) async { | ||
await tx.execute( | ||
'CREATE TABLE _customers(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)'); | ||
await tx.execute( | ||
'CREATE TABLE _local_customers(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)'); | ||
await tx | ||
.execute('CREATE VIEW customers AS SELECT * FROM _local_customers'); | ||
}); | ||
} | ||
|
||
updateTables(SqliteDatabase db) async { | ||
await db.writeTransaction((tx) async { | ||
await tx.execute('DROP VIEW IF EXISTS customers'); | ||
await tx.execute('CREATE VIEW customers AS SELECT * FROM _customers'); | ||
}); | ||
} | ||
|
||
test('should refresh schema views', () async { | ||
final db = await testUtils.setupDatabase(path: path); | ||
await createTables(db); | ||
|
||
final customerTables = | ||
await getSourceTables(db, "select * from customers"); | ||
expect(customerTables.contains('_local_customers'), true); | ||
await updateTables(db); | ||
|
||
// without this, source tables are outdated | ||
await db.refreshSchema(); | ||
|
||
final updatedCustomerTables = | ||
await getSourceTables(db, "select * from customers"); | ||
expect(updatedCustomerTables.contains('_customers'), true); | ||
}); | ||
|
||
test('should complete refresh schema after transaction', () async { | ||
var completer1 = Completer<void>(); | ||
var transactionCompleted = false; | ||
|
||
final db = await testUtils.setupDatabase(path: path); | ||
await createTables(db); | ||
|
||
// Start a read transaction | ||
db.readTransaction((tx) async { | ||
completer1.complete(); | ||
await tx.get('select test_sleep(2000)'); | ||
|
||
transactionCompleted = true; | ||
}); | ||
|
||
// Wait for the transaction to start | ||
await completer1.future; | ||
|
||
var refreshSchemaFuture = db.refreshSchema(); | ||
|
||
// Setup check that refreshSchema completes after the transaction has completed | ||
var refreshAfterTransaction = false; | ||
refreshSchemaFuture.then((_) { | ||
if (transactionCompleted) { | ||
refreshAfterTransaction = true; | ||
} | ||
}); | ||
|
||
await refreshSchemaFuture; | ||
|
||
expect(refreshAfterTransaction, isTrue, | ||
reason: 'refreshSchema completed before transaction finished'); | ||
|
||
// Sanity check | ||
expect(transactionCompleted, isTrue, | ||
reason: 'Transaction did not complete as expected'); | ||
}); | ||
}); | ||
} | ||
|
||
// For some reason, future.ignore() doesn't actually ignore errors in these tests. | ||
void ignore(Future future) { | ||
future.then((_) {}, onError: (_) {}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.