Skip to content
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

bug: not working with local running postgres #1183

Open
princejoogie opened this issue Sep 13, 2024 · 2 comments
Open

bug: not working with local running postgres #1183

princejoogie opened this issue Sep 13, 2024 · 2 comments

Comments

@princejoogie
Copy link

princejoogie commented Sep 13, 2024

Provide environment information

System:
  OS: macOS 14.6.1
  CPU: (8) arm64 Apple M1
  Memory: 159.75 MB / 16.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 20.17.0 - ~/.local/state/fnm_multishells/28536_1726247644124/bin/node
  npm: 10.8.2 - ~/.local/state/fnm_multishells/28536_1726247644124/bin/npm
  pnpm: 9.7.1 - ~/.local/state/fnm_multishells/28536_1726247644124/bin/pnpm
  bun: 1.1.27 - /opt/homebrew/bin/bun

Describe the bug

I wanted to run a local db for development so I created a docker-compose.yml to quickly spin up a postgres instance

services:
  postgres:
    image: postgres
    container_name: bazaarkit
    environment:
      POSTGRES_DB: bazaar
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "2345:5432"

volumes:
  postgres_data:

then I have my .env point to this local db

POSTGRES_URL="postgres://postgres:postgres@localhost:2345/bazaar"

Link to reproduction

https://github.com/princejoogie/t3-turbo-local-postgres-reproduction

To reproduce

git clone https://github.com/princejoogie/t3-turbo-local-postgres-reproduction.git
pnpm i

cp .env.example .env # fill in discord oauth fields

docker compose up # run the local db
pnpm run db:push

pnpm run dev

Additional information

No response

@OopsOverflow
Copy link

I see that you are using @vercel/postgres which is not compatible with the regular postgres driver. You should replace that with a different client, say for example postgres.js.

After that you need to configure drizzle to use that client and you should be good to go.

@younes200
Copy link

younes200 commented Oct 17, 2024

Works with local Vercel Posgres :

version: "3.5"
volumes:
  postgres:

services:
  postgres:
    image: postgres
    volumes:
      - postgres:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: root
    # Expose the Postgres port to the host machine,
    # so you can inspect and administrate it
    ports:
      - "54320:5432"
  pg_proxy:
    image: ghcr.io/neondatabase/wsproxy:latest
    environment:
      APPEND_PORT: "postgres:5432"
      ALLOW_ADDR_REGEX: ".*"
      LOG_TRAFFIC: "true"
    ports:
      # Expose the WebSocket proxy port to the host machine,
      # this is where @vercel/postgres will connect
      - "54330:80"
    depends_on:
      - postgres

packages/db/src/client.ts

import { neonConfig } from '@neondatabase/serverless';

if (process.env.VERCEL_ENV === 'development') {
  neonConfig.wsProxy = (host) => `${host}:54330/v1`;
  neonConfig.useSecureWebSocket = false;
  neonConfig.pipelineTLS = false;
  neonConfig.pipelineConnect = false;
}
import { sql } from "@vercel/postgres";
import { drizzle } from "drizzle-orm/vercel-postgres";

import * as schema from "./schema";

export const db = drizzle({
  client: sql,
  schema,
  casing: "snake_case",
});

.env
POSTGRES_URL="postgres://postgres:root@localhost:54320/db"

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

No branches or pull requests

3 participants