t3-oss / create-t3-turbo

Clean and simple starter repo using the T3 Stack along with Expo React Native
https://turbo.t3.gg
MIT License
4.73k stars 408 forks source link

bug: not working with local running postgres #1183

Open princejoogie opened 2 months ago

princejoogie commented 2 months ago

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 commented 2 months ago

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 commented 1 month ago

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"