-
Notifications
You must be signed in to change notification settings - Fork 28
WIP: Manual schema management API #290
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
base: raw-tables
Are you sure you want to change the base?
WIP: Manual schema management API #290
Conversation
packages/powersync_core/lib/src/database/powersync_db_mixin.dart
Outdated
Show resolved
Hide resolved
@@ -110,10 +114,36 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection { | |||
statusStream = statusStreamController.stream; | |||
updates = powerSyncUpdateNotifications(database.updates); | |||
|
|||
_manualSchemaManagementCompleted = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super happy with this design, but I don't see a better option either.
One thing that looks cleaner might be to have users open their own databases (from sqlite_async
), initialize the schema there and then pass the database to PowerSyncDatabase.withDatabase
. But that would make the database tricky to use with wrappers like drift because we can't swap out the earlier database with the other one later.
So this might be the best option we have here, but I'll ping @rkistner for API design advice as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One issue I can see with that is that the developer wouldn't be able to call powersyncDB.updateSchema()
because they can only use the sqlite_async API at that point
One thing we noticed while doing this PR is the |
Here is a proposed API for the manual schema management in the raw tables feature.
A new flag is added to the PowerSyncDatabase factories
manualManagement
, and a new function to mark the schema as readydb.markSchemaAsReady()
When using this manual mode, the developer is responsible for calling
db.updateSchema(schema)
. Alternatively we could call automatically the updateSchema function in themarkSchemaAsReady()
function, but we believe it makes sense to be all manual and not mix.While the schema is not ready, the public functions that are not related to executing SQL are guarded by
_assertSchemaIsReady()
, to prevent callingconnect
for example.A working example with this is the branch
example-raw-tables
in https://github.com/davidmartos96/powersync.dartPending changes here are:
syncIteration()
in the web worker implementation. We are not familiar with the communication protocol it uses.