Skip to content

Feature: Backend/prisma: add support for postgresql database #833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

JulesdeCube
Copy link
Contributor

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

Define the `base` image templated to select the node and alpine version.
Define the `NODE_VERSION` and `ALPINE_VERSION` to configure base image.
@JulesdeCube JulesdeCube closed this May 9, 2025
@JulesdeCube JulesdeCube deleted the backend-db-postgresql branch May 9, 2025 18:01
@JulesdeCube JulesdeCube restored the backend-db-postgresql branch May 9, 2025 18:01
@JulesdeCube JulesdeCube reopened this May 9, 2025
Copy link
Owner

@stonith404 stonith404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, that's a nice addition!

The backend/prisma/schema folder is obsolete, isn't it?

Currently the Docker container can't start anymore. The npm run prod command probably has to be adapted:

Error: Could not find Prisma Schema that is required for this command.
You can either provide it with `--schema` argument,
set it in your `prisma.config.ts`,
set it as `prisma.schema` in your package.json,
or put it into the default location (`./prisma/schema.prisma`, or `./schema.prisma`.
Checked following paths:

schema.prisma: file not found
prisma/schema.prisma: file not found

@JulesdeCube JulesdeCube force-pushed the backend-db-postgresql branch from 653129e to 912dc5a Compare May 19, 2025 16:45
@JulesdeCube
Copy link
Contributor Author

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.

Jules Lefebvre added 3 commits May 19, 2025 22:15
Move the `sqlite` prisma schema to a separate folder.

- Split the schema into multiple file and use.
- Enable `prismaSchemaFolder` feature flag. stable in next version (v6.7.0)
- Add `--schema` to docker file contributing and configuration docs
- Add `..` to database location to move it back where it was previously
Add prisma schema and init migration for postgresql database.
Add a new job to build and publish special image for postgresql.
@stonith404
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants