Shelf-nu / shelf.nu

shelf is open source Asset Management Infrastructure for absolutely everyone.
https://shelf.nu
GNU Affero General Public License v3.0
1.76k stars 157 forks source link

[Bug]: The provided database string is invalid #918

Closed sbrl closed 5 months ago

sbrl commented 5 months ago

Contact Details

I'm opening an issue, you do not need my email address. We can go back and forth as needed in this issue.

What happened?

Steps to reproduce:

  1. Follow the official Docker instructions: https://github.com/Shelf-nu/shelf.nu/blob/dev/docs/docker.md
  2. See error

What is the expected behaviour?

It should start without crashing.

Context, since your form doesn't seem to ask for it

The issue appears to be with DATABASE_URL ref the docker container ghcr.io/shelf-nu/shelf.nu:latest.

I tried this:

postgres://{USER}:{PASSWORD}@{HOST}:6543/{DB_NAME}?pgbouncer=true

...I also tried postgresql as the schema name ref linked prism documentation.

I tried a local PostgreSQL database container.

Also I tried a connection string from Supabase.

The Docker documentation is unclear on what is required ref the connection string.

I'm writing a Docker compose file for Shelf.nu. I print it below:

name: shelf

services:
  shelf:
    image: ghcr.io/shelf-nu/shelf.nu:latest
    container_name: shelf
    environment:
      - DATABASE_URL="postgres://postgres.[USER]:[PASSWORD]@aws-0-eu-west-2.pooler.supabase.com:6543/postgres?pgbouncer=true"
      - DIRECT_URL="postgres://postgres.[USER]:[PASSWORD]@aws-0-eu-west-2.pooler.supabase.com:6543/postgres"
      - SUPABASE_ANON_PUBLIC=[REDACTED]
      - SUPABASE_SERVICE_ROLE=[REDACTED]
      - SUPABASE_URL=https://[USER].supabase.co
      - SESSION_SECRET=[REDACTED]
      - SERVER_URL=supabase:6747
    ports:
      - 6746:8080
    networks:
      - shelf
    restart: unless-stopped

networks:
  shelf:
    name: shelf

Version

Self-hosted

What browsers are you seeing the problem on?

n/a

Relevant log output

[ref this being only relevant for the hosted version.... that is clearly false.]
shelf  | + npm run db:deploy
shelf  | 
shelf  | > db:deploy
shelf  | > prisma migrate deploy
shelf  | 
shelf  | Prisma schema loaded from app/database/schema.prisma
shelf  | Datasource "db": PostgreSQL database
shelf  | 
shelf  | Error: P1013: The provided database string is invalid. The scheme is not recognized in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.
shelf  | npm notice 
shelf  | npm notice New patch version of npm available! 10.5.0 -> 10.5.2
shelf  | npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.5.2>
shelf  | npm notice Run `npm install -g npm@10.5.2` to update!
shelf  | npm notice 
shelf exited with code 0
DonKoko commented 5 months ago

hey @sbrl . Thanks for opening an issue and your feedback. I will make sure to update the docker documentation to make it a bit more clear. Please refer to the getting started docs to see what is required for setting up the DB: https://github.com/Shelf-nu/shelf.nu/blob/main/docs/get-started.md#development

Based on the error, it seems like the string provided is invalid string. Is that an error you get when you run the docker like this:

docker run -d \
  --name "shelf" \
  -e "DATABASE_URL=postgres://{USER}:{PASSWORD}@{HOST}:6543/{DB_NAME}?pgbouncer=true" \
  -e "DIRECT_URL=postgres://{USER}:{PASSWORD}@{HOST}:5432/{DB_NAME}" \
  -e 'SUPABASE_ANON_PUBLIC=ANON_PUBLIC' \
  -e 'SUPABASE_SERVICE_ROLE=SERVICE_ROLE' \
  -e 'SUPABASE_URL=https://{YOUR_INSTANCE_NAME}.supabase.co' \
  -e 'SESSION_SECRET=super-duper-s3cret' \
  -e 'SERVER_URL=http://localhost:3000' \
  -e 'MAPTILER_TOKEN=maptiler-token' \
  -e 'SMTP_HOST=mail.example.com' \
  -e 'SMTP_USER=some-email@example.com' \
  -e 'SMTP_FROM="Carlos from shelf.nu" <carlos@shelf.nu>' \
  -e 'SMTP_PWD=super-safe-passw0rd' \
  -p 3000:8080 \
  --restart unless-stopped \
  ghcr.io/shelf-nu/shelf.nu:latest

@anatolinicolae do you have any idea what the issue is with this?

anatolinicolae commented 5 months ago

🤔 My deployment has the same formatting as OP's, so it should be working just fine.

Best tip off the top of my head is probably adding a command and just using printenv to see if those were correctly passed, so:

name: shelf

services:
  shelf:
    image: ghcr.io/shelf-nu/shelf.nu:latest
    container_name: shelf
    environment:
      - DATABASE_URL="postgres://postgres.[USER]:[PASSWORD]@aws-0-eu-west-2.pooler.supabase.com:6543/postgres?pgbouncer=true"
      - DIRECT_URL="postgres://postgres.[USER]:[PASSWORD]@aws-0-eu-west-2.pooler.supabase.com:6543/postgres"
      - SUPABASE_ANON_PUBLIC=[REDACTED]
      - SUPABASE_SERVICE_ROLE=[REDACTED]
      - SUPABASE_URL=https://[USER].supabase.co
      - SESSION_SECRET=[REDACTED]
      - SERVER_URL=supabase:6747
    ports:
      - 6746:8080
    networks:
      - shelf
    restart: unless-stopped
    command: printenv

networks:
  shelf:
    name: shelf

If that doesn't work, try the same overriding the entrypoint instead.

cn-ml commented 5 months ago

I just had the same problem as OP. I fixed this issue by removing the quotation marks in the docker compose environment description. The variables in yaml spec are either supposed to be strings in dotenv format, i.e.

environment:
  # wrong
  - key="incorrect"
  # right
  - key=correct

or an object with yaml values (those are optionally quoted)

environment:
  # right
  key1: "correct1"
  # also right
  key2: correct2

I assume this causes your actual variable to be prefixed with a quotation char. This means the URI protocol is now literally "postgres: which does not work.

anatolinicolae commented 5 months ago

Great tip, Michael!

If you'd like to still use quotes, I believe the best way to do is to fully wrap the var like:

environment:
    - "DATABASE_URL=postgres://postgres.[USER]:[PASSWORD]@aws-0-eu-west-2.pooler.supabase.com:6543/postgres?pgbouncer=true"
sbrl commented 5 months ago

Thanks for all the help, everyone! I hate yaml so much........

It's now hanging on npm run db_deploy, but that's likely due to an internal firewall issue.

Thanks for the help!