cloudflare / cloudflare-docs

Cloudflare’s documentation
https://developers.cloudflare.com
Creative Commons Attribution 4.0 International
2.92k stars 3.35k forks source link

How to share state of D1 and other products locally (workers and pages project)) #16572

Open cloudcreatr opened 2 weeks ago

cloudcreatr commented 2 weeks ago

Proposed changes

https://developers.cloudflare.com/workers/wrangler/api/#parameters-1 https://developers.cloudflare.com/d1/build-with-d1/local-development/#persist-data

Subject Matter

How to share D1 and other projects locally between different projects

Content Location

I have a mono repo setup and I had spend a quite some time to figure out how to share cloudflare D1 between different projects locally. Cloudflare D1 states, are unique to each project locally. It would be good if there's specific documentation saying how to do that. For example if you want to link pages project and workers projects locally with one D1 you have to use get platform proxy function in pages and use its persist option with directory path and also do the same with workers but difference use the same directory with command option in Wrangler to persist. But how should one mange migrations now for common shared D1 locally

https://developers.cloudflare.com/d1/reference/migrations/#wrangler-customizations Here it's mentioned that we can change the migration directory, but in this part https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases, it's not mentioned only that there's option to rename the migration folder. This inconsistent behaviour cab lead to a lot of delay.. I am using turbo repo, i have created a internal package that uses different migration folder for each D1 and persist the files to common directory, both workers and pages depends on it. Please make the changes. Thanks

Additional information

No response

inerte commented 2 weeks ago

@cloudcreatr Maybe --persist-to works for you? As seen here https://github.com/cloudflare/workers-sdk/issues/4755

cloudcreatr commented 2 weeks ago

@cloudcreatr Maybe --persist-to works for you? As seen here cloudflare/workers-sdk#4755

As it does, but not for pages, where vite is used in local development. It would be good if they document that you have to use GetplatformProxy function to persist in development mode