powersync.dart icon indicating copy to clipboard operation
powersync.dart copied to clipboard

Id included in data column in ps_data__<table>

Open js2702 opened this issue 5 months ago • 2 comments

While inspecting the ps_data__ table we noticed that the JSON data column includes the PowerSync id as a field in the json. But when the device is offline and an UPDATE is made, the id field is not included in the json.

Should the id be in the json in the first place? Because you already have an id column?

In any case the state of the table seems inconsistent.

This is in PowerSync client 1.4.0.

js2702 avatar Jul 07 '25 17:07 js2702

Should the id be in the json in the first place? Because you already have an id column?

We store the data as it's received from the PowerSync service, and there the id column is indeed included (which also looks a bit odd to me since we're also extracting the id value as a special column to identify the row, but it also makes sense that data is a complete representation of the source row).

In any case the state of the table seems inconsistent.

On the other hand, could you share a query where this is relevant? It looks like we're pretty much ignoring the id key in data on the client because the views all reference the dedicated id column.

But when the device is offline and an UPDATE is made, the id field is not included in the json.

Right, because here the value comes from a powersync_diff comparison involving only the actual column names. Still, I think the best approach is to always use the id field on CRUD entries instead of looking it up in data.

simolus3 avatar Jul 08 '25 07:07 simolus3

I thing going forward it might be best to remove the id field from the data json blob completely (in powersync-service). As far as I know we're not actively using it anywhere, and it does add significant overhead when you sync many small rows. We'll have to confirm that it's not breaking backwards-compatibility anywhere though.

rkistner avatar Jul 08 '25 07:07 rkistner