jamsocket / y-sweet

A standalone yjs server with persistence to S3 or filesystem.
https://docs.y-sweet.dev
Other
404 stars 27 forks source link

How to migrate data #222

Open gempir opened 4 months ago

gempir commented 4 months ago

I followed the example tldraw App https://github.com/drifting-in-space/y-sweet/blob/main/examples/nextjs/src/app/tldraw/useYjsStore.ts#L24

The issue is tldraw changed their document structure a bit https://github.com/tldraw/tldraw/issues/3463

loadSnapshot should take care of this issue.

But loadSnapshot is only called to initialize the empty document it looks like.

I don't quite follow how y-sweet loads everything that is already on the server and needs to be initially loaded.

How would I achieve a migration on this data?

paulgb commented 4 months ago

Hi, this is something we have been thinking about but don't yet have a good answer on to be honest. It's part of a broader issue of data migration with CRDTs.

Do you have ideas on how you would like to see it work? One idea I've had is to allow you to provide a script to the server that runs every time the data is loaded from storage, which would give you a place to do any migration tasks, which would then be synchronized down to clients when they connect.

gempir commented 4 months ago

I think generally that idea is good.

The responsibility of removing the script from the sever when migration is no longer required then lies on the user.