pingvin-share icon indicating copy to clipboard operation
pingvin-share copied to clipboard

Feature: Backend/prisma: add support for postgresql database

Open JulesdeCube opened this issue 7 months ago • 2 comments

Context

I am currently deploying Pingvin on kubernetes in high availability (multiple instance of the backend and frontend).

Issue

Currently Pingvin share only support SQLite as backend database. This work well for small deployment withonly one instance of the backend.

But this don't scale with multiple backends as SQLite is a filesystem only database. This can work with a share filesystem but defeat the purpose/performance of the database.

PR

Prisma don't currently support dynamic datasource so this pr duplicate (with symlink) the schema files.

This also build and publish postgresql image (tag postgresql-vX.X.X).

Note

This PR is related to #832

JulesdeCube avatar May 09 '25 17:05 JulesdeCube

Normally it's fixed.

I also fix the misplace migration folder (backend/prisma/sqlite/migrations -> backend/prisma/sqlite/schema/migrations)

also note that the future migrations should be generated for sqlite and postgresql.

JulesdeCube avatar May 19 '25 16:05 JulesdeCube

Thanks for the changes. The container with the DB_DATASOURCE=postgresql build arg doesn't start:

> [email protected] prod
> prisma migrate deploy --schema=prisma/sqlite/schema/ && prisma db seed --schema=prisma/sqlite/schema/ && node dist/src/main

 ✓ Ready in 396ms
Environment variables loaded from prisma/sqlite/.env
Prisma schema loaded from prisma/sqlite/schema
Error: Prisma schema validation - (get-config wasm)
Error code: P1012
error: Error validating datasource `db`: the URL must start with the protocol `file:`.
  -->  prisma/sqlite/schema/datasource.prisma:3
   | 
 2 |   provider = "sqlite"
 3 |   url      = env("DATABASE_URL")

The issue is probably caused by the npm run prod command because you've hardcoded --schema=prisma/sqlite/schema/ in it. The schema here must be dynamically set based on the build arg because the Sqlite schema doesn't exist in the Postgres image.

stonith404 avatar Jun 04 '25 09:06 stonith404