Skip to content

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

Draft
wants to merge 6 commits into
base: raw-tables
Choose a base branch
from

Conversation

davidmartos96
Copy link
Contributor

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 ready db.markSchemaAsReady()

When using this manual mode, the developer is responsible for calling db.updateSchema(schema). Alternatively we could call automatically the updateSchema function in the markSchemaAsReady() 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 calling connect for example.

A working example with this is the branch example-raw-tables in https://github.com/davidmartos96/powersync.dart

Pending changes here are:

  • Docs
  • Pass the schema down to syncIteration() in the web worker implementation. We are not familiar with the communication protocol it uses.
  • Tests

@davidmartos96 davidmartos96 marked this pull request as draft June 10, 2025 10:01
@@ -110,10 +114,36 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
statusStream = statusStreamController.stream;
updates = powerSyncUpdateNotifications(database.updates);

_manualSchemaManagementCompleted = false;
Copy link
Contributor

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.

Copy link
Contributor Author

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

@davidmartos96
Copy link
Contributor Author

One thing we noticed while doing this PR is the logger param in PowerSyncDatabase.withDatabase actually says loggers. Technically it's a breaking change, but maybe you guys want to fix it in a separate commit

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.

3 participants