#Local File Persistence for PayloadCMS with Static Site Generation

6 messages · Page 1 of 1 (latest)

ornate nest
#

Hi everyone! 👋

I’m working on a project using PayloadCMS, and I’m exploring the possibility of persisting content to local files instead of a database. Here’s the context:

My frontend uses Static Site Generation (SSG), meaning no server hosting is expected after the site is built.
To update content, I’d clone the repository, start the CMS locally to make changes, then rebuild the site and deploy the updated static files.
Persisting content in files would allow me to:
Use git diff for PR reviews.
Reproduce datasets easily across environments via git cloning.
While I’m considering building a custom dbAdapter to achieve this, I wanted to ask:

Has anyone already created a plugin or adapter for PayloadCMS to store content as local files (e.g., JSON, Markdown, etc.)?
I looked into using SQLite as a local file-based option, but it’s hard to review diffs during PRs, which makes it less ideal for my workflow.
Would love to hear if there are existing solutions or any pointers before I dive into custom code. Thanks for your help! 😊

idle flameBOT
ornate nest
#

Local File Persistence for PayloadCMS with Static Site Generation

chrome seal
#

I would probably just write custom query inside payload. Inside write all needed queries to get data, do all the file printings to files. Call that query with something else, when wanted to rebuild whole website. And thats it. But maybe there is some smarter way. Do you need some examples on how custom queries are made?

ornate nest
#

Hi @chrome seal

Thanks for your reply! Your suggestion sounds like a solid plan, but I foresee a potential challenge:

If I commit the JSON files to Git and later modify them through the PayloadCMS Admin dashboard, it might become tricky to maintain consistency between the JSON files and the database.

Since I plan to run PayloadCMS in a Docker container, I could mount a volume to persist the database data. This way, the data wouldn’t be lost when the container is restarted. However, if the Docker volume is deleted for some reason, the database would be wiped, leaving me with empty content in PayloadCMS.

In that scenario, I’d need to:

Rebuild the database by importing the JSON files exported via the custom query.
Maintain both the custom query for exporting and a script for importing data back into PayloadCMS.
It feels like this setup might require ongoing maintenance, which adds complexity. Perhaps I should start with the SQLite adapter since it offers a file-based database solution and then evaluate how to transition to JSON-based persistence if needed.

Would love to hear your thoughts or any alternative approaches!

chrome seal
#

@ornate nest Interesting, maybe I didn't think about all this complexity. But for me, I dont store database WITH payload, I store database in something like mongo atlas, and then I can just link payload to use data from there. And then there is no problem if payload restarts or I want to move it to different server, etc. Maybe this could help?