Merged
Conversation
- automatically update the latest sent db_version value after sending payloads depending on the status returned by the cloudsync http service - the cloudsync_network_send_changes functions now returns the status data in the json format - the cloudsync_network_has_unsent_changes now call the status endpoints before comparing with the latest local db_version - only consider the db_version value in the WHERE clause of cloudsync_payload_get, don't filter at seq level
The three public sync functions was leaking internal server JSON or returning raw integers. We want them to return coherent, user-facing JSON with a computed status field and relevant version/row info.
New responses:
- cloudsync_network_send_changes — formats JSON: {"status":"...", "localVersion":N, "serverVersion":N}
- cloudsync_network_check_changes — formats JSON: {"rowsReceived":N}
- cloudsync_network_sync — combines send + check results into: {"status":"...", "localVersion":N, "serverVersion":N, "rowsReceived":N}
The status helper computes "synced", "syncing", "retry", or "error" from the apply/status response fields.
…teCloud projects using RLS rules
…nd/receive keys
Change the flat JSON return format of network functions to a nested
structure with "send" and "receive" top-level keys, rename
"rowsReceived" to "rows" for conciseness, and add a "tables" array
field to the receive section listing affected table names.
Before: {"status":"synced","localVersion":5,"serverVersion":5,"rowsReceived":3}
After: {"send":{"status":"synced","localVersion":5,"serverVersion":5},"receive":{"rows":3,"tables":["tasks"]}}
Update integration tests to use SQLite's ->> operator for JSON field
extraction, and add db_expect_str helper for string assertions.
…ayload AND db_version == 0.
1. Added early return for empty-db case (lines 959–966): When there's no payload (blob == NULL || blob_size == 0) AND db_version == 0, skip the network call entirely and return { server_version: 0, local_version: 0, status: "synced" }. This avoids the 404 from the status endpoint when the server doesn't know the device yet.
2. Fixed condition from || to && (line 969): Changed blob != NULL || blob_size > 0 to blob != NULL && blob_size > 0 — both conditions must be true to confirm there's actual data to upload.
andinux
added a commit
that referenced
this pull request
Mar 13, 2026
* fix(network): cloudsync_network_check_changes must not return the nrows value in case of error `SELECT cloudysnc_network_check_changes();` was returning "Runtime error: 0" in case of error response from the cloudsync microservice instead of the real error message * feat(rls): add complete support for RLS with batch merge in cloudsync_payload_apply * Feat/add support for status endpoint (#10) * feat(network): add support for new status endpoint * refactor(network): structured JSON responses for sync functions. Example: {"send":{"status":"synced","localVersion":5,"serverVersion":5},"receive":{"rows":3,"tables":["tasks"]}} * Feat/network support for multi org cloudsync (#11) * Disable notnull prikey constraints (#12) * The cloudsync extension now enforces NULL primary key rejection at runtime (any write with a NULL PK returns an error), so the explicit NOT NULL constraint on primary key columns is no longer a schema requirement * test: add null primary key rejection tests for SQLite and PostgreSQL * docs: remove NOT NULL requirement from primary key definitions The extension now enforces NULL primary key rejection at runtime, so the explicit NOT NULL constraint on PK columns is no longer a schema requirement. Replace the "must be NOT NULL" guidance with a note about runtime enforcement. * docs: add first draft of PERFORMANCE.md and CHANGELOG.md * fix(postgresql): resolve commit_alter crash and BYTEA handling in column_text Guard savepoint commit/rollback against missing subtransactions to prevent segfault in autocommit mode. Add BYTEA support to database_column_text so encoded PKs are readable during refill_metatable after ALTER TABLE. Enable alter table sync test (31). * test: new alter table test for postgres * feat: update endpoints to use databaseMangedId for /v2/cloudsync api * feat(network)!: replace URL connection string with a UUID (managedDatabaseId) BREAKING CHANGE: cloudsync_network_init now accepts a UUID string instead of the previous URL string. URL connection strings are no longer accepted. The managed database identifier returned by the CloudSync service when a new database is registered for sync. For SQLiteCloud projects, this value can be obtained from the project's OffSync page on the dashboard. * docs: update docs for the new managedDatabaseId arg for cloudsync_network_init * docs(examples): update example for the new managedDatabaseId arg for cloudsync_network_init
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.