Repository navigation
[Feature Request] External Database support #386
|
Hello, Any plan on supporting external databases such as PostgreSQL ? Thanks ! |
Replies: 6 comments 4 replies
|
Yes please! |
|
I'm currently exploring what could be possible to implement. Supporting multiple db engines is a nightmare, I've been trying for the last 2 days to come up with a proper solution but there's always trade-offs. While TypeORM is the only ORM that truly abstract the database layer, the db migrations are per engine which is a huge burden regarding DX. It means having a postgres instance, a mysql/mariadb instance and the sqlite db, all running at the same time to generate any migrations. Then there's the testing part that will be complicated as certain cases will be db dependent. DB agnostic apps do not usually exists, and when they exists, there's always a big team behind it. It is much easier to support a single db engine type. TREK was made with sqlite in the 1st place because it's just a file, there's no other server to have and the performances are really good if there isn't thousand of users. So no other server dependency. I don't think that making trek truly db agnostic is the right call there as it adds a ton of complexity. I'd like your input on all that, I'm kinda conflicted on all possible solutions.. (poke @Naimadnap and @samip5 as you opened similar feature requests) |
|
I think community adapters could also be a good angle. Seems like a large refactor though, but there is real need for expanding to multiple supported backends. I would like to see support for global serverless databases so I get my minimal latency when I am in another country 😄. |
|
The biggest issue with SQLite (as far as I'm concerned, at least) appears when the storage backend is NFS. I've had issues with SQLite-based applications before (*arr stack, Forgejo), and once I migrated each of them to Postgres, the issues disappeared. |
|
Hey everyone, good news: TREK runs on PostgreSQL now. It's merged into How you turn it on Set No SQLite file on the data volume Plugins that keep their own data get a schema of their own in TREK's database instead of a Moving an existing install There's a move command that copies a SQLite install into an empty Postgres database: every table, every plugin's data and the id sequences, in one transaction. Before it commits, it compares the row count and a checksum of every table. A value Postgres can't store exactly is refused and listed, never quietly changed. It never touches your With Docker Compose: docker compose down
docker compose -f docker-compose.postgres.yml up -d db
docker compose -f docker-compose.postgres.yml run --rm --user node -w /app/server app \
node --require tsconfig-paths/register dist/move-to-postgres.js
docker compose -f docker-compose.postgres.yml up -dKeep the same Backups and restore These work as before through the admin panel, just with A few things to know
How it's built, for the curious @dtamm, since you asked about ORMs: TREK is on MikroORM and Kysely now. The SQL that differs between engines lives in one small dialect layer, and a CI gate refuses SQLite-only SQL anywhere else. Every change runs the full server test suite against real Postgres 14 and 18 on top of SQLite. A probe also calls every repository method on Postgres, and migrations are written once per engine, with a generator printing the Postgres side. Plugins get a sandboxed schema with their SQL checked. Big thanks to isaiastavares, whose PR #2984 laid the groundwork this is built on. The full guide (requirements, SSL, the move, upgrades, backups, Supabase) is the wiki page Database: Postgres, which goes live with the release. If you try it, we'd love to hear how it goes. @Billos, thanks for opening this one. It was the most upvoted request we had. 🎉 |
|
Thanks so much! Giving it a go |

Hey everyone, good news: TREK runs on PostgreSQL now. It's merged into
devand ships with 5.2.0. Thanks a lot for the patience, and for all the input here. @samip5 and @aronsky, your NFS point was the main thing we designed around.How you turn it on
Set
TREK_DB_URLto apostgres://URL and TREK uses Postgres instead of the SQLite file. Without that variable nothing changes, and SQLite stays the default. Supported are PostgreSQL 14 to 18. The image ships the version 18 client tools, which handle every supported server for backups and restores. There's a ready-madedocker-compose.postgres.ymlthat runs apostgres:17service next to TREK, and the Helm chart takesdatabase.urlor an existing…