kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: switch prod db to neon
rodzic
5b171df484
commit
c32f94c05d
|
@ -43,6 +43,7 @@
|
||||||
"@fisch0920/drizzle-zod": "catalog:",
|
"@fisch0920/drizzle-zod": "catalog:",
|
||||||
"@hono/node-server": "catalog:",
|
"@hono/node-server": "catalog:",
|
||||||
"@hono/zod-openapi": "catalog:",
|
"@hono/zod-openapi": "catalog:",
|
||||||
|
"@neondatabase/serverless": "catalog:",
|
||||||
"@paralleldrive/cuid2": "catalog:",
|
"@paralleldrive/cuid2": "catalog:",
|
||||||
"@sentry/node": "catalog:",
|
"@sentry/node": "catalog:",
|
||||||
"bcryptjs": "catalog:",
|
"bcryptjs": "catalog:",
|
||||||
|
|
|
@ -1,18 +1,33 @@
|
||||||
import { drizzle } from '@fisch0920/drizzle-orm/postgres-js'
|
import { drizzle as neonPostgresDrizzle } from '@fisch0920/drizzle-orm/neon-http'
|
||||||
|
import { drizzle as postgresDrizzle } from '@fisch0920/drizzle-orm/postgres-js'
|
||||||
|
import { neon } from '@neondatabase/serverless'
|
||||||
import postgres from 'postgres'
|
import postgres from 'postgres'
|
||||||
|
|
||||||
import { env } from '@/lib/env'
|
import { env } from '@/lib/env'
|
||||||
|
|
||||||
import * as schema from './schema'
|
import * as schema from './schema'
|
||||||
|
|
||||||
type PostgresClient = ReturnType<typeof postgres>
|
type PostgresClient = ReturnType<typeof postgres> | ReturnType<typeof neon>
|
||||||
|
|
||||||
// TODO: consider using [neon serverless driver](https://orm.drizzle.team/docs/connect-neon) for production
|
// TODO: consider using neon for both dev and prod; it would be simpler, but
|
||||||
|
// we'd lose the ability to connect to a 100% local postgres database which is
|
||||||
|
// nice for flights.
|
||||||
let _postgresClient: PostgresClient | undefined
|
let _postgresClient: PostgresClient | undefined
|
||||||
const postgresClient =
|
const postgresClient =
|
||||||
_postgresClient ?? (_postgresClient = postgres(env.DATABASE_URL))
|
_postgresClient ??
|
||||||
|
(_postgresClient = env.isDev
|
||||||
|
? postgres(env.DATABASE_URL)
|
||||||
|
: neon(env.DATABASE_URL))
|
||||||
|
|
||||||
export const db = drizzle({ client: postgresClient, schema })
|
export const db = env.isDev
|
||||||
|
? postgresDrizzle({
|
||||||
|
client: postgresClient as ReturnType<typeof postgres>,
|
||||||
|
schema
|
||||||
|
})
|
||||||
|
: neonPostgresDrizzle({
|
||||||
|
client: postgresClient as ReturnType<typeof neon>,
|
||||||
|
schema
|
||||||
|
})
|
||||||
|
|
||||||
export * as schema from './schema'
|
export * as schema from './schema'
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -57,6 +57,9 @@ catalogs:
|
||||||
'@modelcontextprotocol/sdk':
|
'@modelcontextprotocol/sdk':
|
||||||
specifier: ^1.13.0
|
specifier: ^1.13.0
|
||||||
version: 1.13.0
|
version: 1.13.0
|
||||||
|
'@neondatabase/serverless':
|
||||||
|
specifier: ^1.0.1
|
||||||
|
version: 1.0.1
|
||||||
'@number-flow/react':
|
'@number-flow/react':
|
||||||
specifier: ^0.5.10
|
specifier: ^0.5.10
|
||||||
version: 0.5.10
|
version: 0.5.10
|
||||||
|
@ -506,6 +509,9 @@ importers:
|
||||||
'@hono/zod-openapi':
|
'@hono/zod-openapi':
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 0.19.8(hono@4.8.1)(zod@3.25.67)
|
version: 0.19.8(hono@4.8.1)(zod@3.25.67)
|
||||||
|
'@neondatabase/serverless':
|
||||||
|
specifier: 'catalog:'
|
||||||
|
version: 1.0.1
|
||||||
'@paralleldrive/cuid2':
|
'@paralleldrive/cuid2':
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 2.2.2
|
version: 2.2.2
|
||||||
|
@ -8852,7 +8858,6 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 22.15.33
|
'@types/node': 22.15.33
|
||||||
'@types/pg': 8.15.4
|
'@types/pg': 8.15.4
|
||||||
optional: true
|
|
||||||
|
|
||||||
'@next/env@15.3.4': {}
|
'@next/env@15.3.4': {}
|
||||||
|
|
||||||
|
@ -10296,7 +10301,6 @@ snapshots:
|
||||||
'@types/node@22.15.33':
|
'@types/node@22.15.33':
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: 6.21.0
|
undici-types: 6.21.0
|
||||||
optional: true
|
|
||||||
|
|
||||||
'@types/node@24.0.4':
|
'@types/node@24.0.4':
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -14581,8 +14585,7 @@ snapshots:
|
||||||
jiti: 2.4.2
|
jiti: 2.4.2
|
||||||
quansync: 0.2.10
|
quansync: 0.2.10
|
||||||
|
|
||||||
undici-types@6.21.0:
|
undici-types@6.21.0: {}
|
||||||
optional: true
|
|
||||||
|
|
||||||
undici-types@7.8.0: {}
|
undici-types@7.8.0: {}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ catalog:
|
||||||
"@hono/zod-openapi": ^0.19.8
|
"@hono/zod-openapi": ^0.19.8
|
||||||
"@hono/zod-validator": ^0.7.0
|
"@hono/zod-validator": ^0.7.0
|
||||||
"@modelcontextprotocol/sdk": ^1.13.0
|
"@modelcontextprotocol/sdk": ^1.13.0
|
||||||
|
"@neondatabase/serverless": ^1.0.1
|
||||||
"@number-flow/react": ^0.5.10
|
"@number-flow/react": ^0.5.10
|
||||||
"@paralleldrive/cuid2": ^2.2.2
|
"@paralleldrive/cuid2": ^2.2.2
|
||||||
"@pmndrs/assets": ^1.7.0
|
"@pmndrs/assets": ^1.7.0
|
||||||
|
|
Ładowanie…
Reference in New Issue