Skip to content

Adapt new Prisma TS engine - #406

Merged
samchon merged 1 commit into
masterfrom
prisma-ts-engine
Sep 16, 2025
Merged

Adapt new Prisma TS engine#406
samchon merged 1 commit into
masterfrom
prisma-ts-engine

Conversation

@samchon

@samchon samchon commented Sep 16, 2025

Copy link
Copy Markdown
Owner

This pull request updates the way the application connects to PostgreSQL by adopting Prisma's new @prisma/adapter-pg adapter, enhancing configuration flexibility and aligning with Prisma best practices. The changes also refactor environment variable handling and Prisma client instantiation to use singletons for improved consistency and maintainability.

Prisma Adapter Integration and Database Configuration:

  • Adopted @prisma/adapter-pg for PostgreSQL connections: Added the @prisma/adapter-pg dependency and updated Prisma client instantiations in both src/MyGlobal.ts and src/executable/schema.ts to use the new adapter, allowing for advanced configuration such as specifying the schema directly. [1] [2] [3] [4]

  • Updated Prisma generator configuration: Modified the Prisma schema generator to use engineType = "client" and removed the binaryTargets field, aligning with recent Prisma recommendations.

Environment Variable Management and Singleton Refactoring:

  • Centralized environment variable parsing and validation: Introduced an IEnvironments interface and a singleton to parse, expand, and validate environment variables using typia. All environment access now goes through this singleton. [1] [2] [3]

  • Singleton pattern for Prisma client: Replaced direct instantiation of PrismaClient with a singleton getter, ensuring a single, consistently configured instance throughout the application. [1] [2]

  • Removed legacy environment and mode wrappers: Cleaned up old environment and mode wrapper code, consolidating logic to use the new singleton-based approach.

@samchon
samchon requested a review from Copilot September 16, 2025 15:13
@samchon samchon self-assigned this Sep 16, 2025
@samchon samchon added enhancement New feature or request dependencies Pull requests that update a dependency file labels Sep 16, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request updates the application to use Prisma's new @prisma/adapter-pg adapter for PostgreSQL connections, replacing the previous direct datasource configuration approach. The changes also introduce singleton patterns for better resource management and centralize environment variable handling.

  • Adopts Prisma's new PostgreSQL adapter with enhanced configuration options
  • Refactors to use singleton patterns for Prisma client and environment variables
  • Updates Prisma generator configuration to use the new engine type

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
package.json Adds the new @prisma/adapter-pg dependency
prisma/schema/main.prisma Updates generator to use "client" engine type and removes binary targets
src/MyGlobal.ts Implements singleton patterns for environment and Prisma client management
src/executable/schema.ts Updates PrismaClient instantiation to use the new adapter

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/MyGlobal.ts
MODE: "local" | "dev" | "real";
API_PORT: `${number}`;
SYSTEM_PASSWORD: string;

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The POSTGRES_URL environment variable is referenced in the code but not documented in the interface. Consider adding a comment explaining its purpose and expected format, especially since it's used alongside the individual connection components.

Suggested change
/**
* PostgreSQL connection string used by Prisma.
* Expected format: "postgresql://USER:PASSWORD@HOST:PORT/DATABASE"
* If provided, this will be used to connect to the database instead of the individual connection components below.
*/

Copilot uses AI. Check for mistakes.
Comment thread src/executable/schema.ts
url: `postgresql://${username}:${password}@${MyGlobal.env.POSTGRES_HOST}:${MyGlobal.env.POSTGRES_PORT}/${database}`,
adapter: new PrismaPg(
{
connectionString: `postgresql://${username}:${password}@${MyGlobal.env.POSTGRES_HOST}:${MyGlobal.env.POSTGRES_PORT}/${database}?schema=${MyGlobal.env.POSTGRES_SCHEMA}`,

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The connection string is manually constructed here while MyGlobal.env.POSTGRES_URL is available and used elsewhere. Consider using the existing POSTGRES_URL environment variable or a helper function to maintain consistency across the codebase.

Copilot uses AI. Check for mistakes.
@samchon
samchon merged commit 55a13eb into master Sep 16, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants