File tree Expand file tree Collapse file tree
migrations/20260630000000_add_stream_token_address_index Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Database
22DATABASE_URL = " postgresql://user:password@localhost:5433/flowfi?schema=public"
33
4+ # PostgreSQL pool settings
5+ # Maximum database connections per backend process (default: 10)
6+ PG_POOL_MAX = 10
7+ # How long an idle connection stays open before being closed (milliseconds, default: 30000)
8+ PG_IDLE_TIMEOUT_MS = 30000
9+ # How long to wait when establishing a new database connection (milliseconds, default: 5000)
10+ PG_CONNECTION_TIMEOUT_MS = 5000
11+ # Maximum time a PostgreSQL statement may run before cancellation (milliseconds, default: 30000)
12+ PG_STATEMENT_TIMEOUT_MS = 30000
13+
414# Server
515PORT = 3001
616NODE_ENV = development
Original file line number Diff line number Diff line change 1+ -- CreateIndex
2+ CREATE INDEX IF NOT EXISTS " Stream_tokenAddress_idx" ON " Stream" (" tokenAddress" );
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ model Stream {
5151
5252 @@index ([sender ] )
5353 @@index ([recipient ] )
54+ @@index ([tokenAddress ] )
5455 @@index ([streamId ] )
5556 @@index ([isActive ] )
5657 @@index ([isPaused ] )
Original file line number Diff line number Diff line change 1- import pg from 'pg' ;
21import { PrismaPg } from '@prisma/adapter-pg' ;
32import { PrismaClient } from '../src/generated/prisma/index.js' ;
3+ import { createPgPool } from '../src/lib/pg-pool.js' ;
44
5- const connectionString = process . env . DATABASE_URL ;
6- const pool = new pg . Pool ( { connectionString } ) ;
5+ const pool = createPgPool ( ) ;
76const adapter = new PrismaPg ( pool ) ;
87const prisma = new PrismaClient ( { adapter } ) ;
98
Original file line number Diff line number Diff line change 1+ import pg from 'pg' ;
2+
3+ const parsePositiveIntegerEnv = ( name : string , defaultValue : number ) : number => {
4+ const rawValue = process . env [ name ] ;
5+
6+ if ( ! rawValue ) return defaultValue ;
7+
8+ const parsedValue = Number . parseInt ( rawValue , 10 ) ;
9+
10+ return Number . isInteger ( parsedValue ) && parsedValue > 0 ? parsedValue : defaultValue ;
11+ } ;
12+
13+ export const createPgPoolConfig = ( ) : pg . PoolConfig => ( {
14+ connectionString : process . env . DATABASE_URL ,
15+ max : parsePositiveIntegerEnv ( 'PG_POOL_MAX' , 10 ) ,
16+ idleTimeoutMillis : parsePositiveIntegerEnv ( 'PG_IDLE_TIMEOUT_MS' , 30_000 ) ,
17+ connectionTimeoutMillis : parsePositiveIntegerEnv ( 'PG_CONNECTION_TIMEOUT_MS' , 5_000 ) ,
18+ statement_timeout : parsePositiveIntegerEnv ( 'PG_STATEMENT_TIMEOUT_MS' , 30_000 ) ,
19+ } ) ;
20+
21+ export const createPgPool = ( ) => new pg . Pool ( createPgPoolConfig ( ) ) ;
Original file line number Diff line number Diff line change 11import pg from 'pg' ;
22import { PrismaPg } from '@prisma/adapter-pg' ;
33import { PrismaClient } from '../generated/prisma/index.js' ;
4+ import { createPgPool } from './pg-pool.js' ;
45
56const globalForPrisma = global as unknown as {
67 prisma ?: PrismaClient ;
78 pool ?: pg . Pool ;
89} ;
910
10- const connectionString = process . env . DATABASE_URL ;
11-
1211if ( ! globalForPrisma . pool ) {
13- globalForPrisma . pool = new pg . Pool ( { connectionString } ) ;
12+ globalForPrisma . pool = createPgPool ( ) ;
1413}
1514
1615const adapter = new PrismaPg ( globalForPrisma . pool ) ;
You can’t perform that action at this time.
0 commit comments