Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Jun 17, 2025

Summary by CodeRabbit

  • New Features
    • Updated documentation and code samples to require explicit database configuration when initializing the client.
  • Bug Fixes
    • Adjusted tests and sample projects to use explicit database configuration for improved reliability.
  • Refactor
    • Simplified client and schema setup by removing internal provider functions and utilities for database configuration.
    • Removed the custom signUp procedure from sample code and schema.
  • Documentation
    • Improved and clarified setup instructions and code examples in README files.
    • Updated migration guides to reflect new client initialization requirements.
  • Style
    • Improved formatting and alignment in schema files for better readability.
  • Chores
    • Updated project scaffolding to generate essential config files manually and include necessary dependencies.
    • Removed obsolete internal utilities and exports related to database configuration.

* refactor: get rid of ds config provider from generated schema

* update
@coderabbitai
Copy link

coderabbitai bot commented Jun 17, 2025

Walkthrough

This update refactors the way database dialect configuration is supplied to the ZenStackClient, making the dialectConfig option mandatory and removing schema-embedded configuration providers. All related code, documentation, tests, and templates are updated to reflect this change. Utility functions and exports for dialect config generation are eliminated, and project scaffolding is adjusted accordingly.

Changes

File(s) Change Summary
README.md, samples/blog/README.md Updated usage examples and instructions to require explicit dialectConfig in ZenStackClient instantiation.
TODO.md Added a new unchecked ORM task: "Implement changesets."
packages/cli/src/actions/generate.ts, packages/cli/src/actions/templates.ts Modified code snippets and templates to show explicit dialectConfig usage in ZenStackClient creation.
packages/create-zenstack/src/index.ts Removed package manager initialization commands; now manually creates package.json and tsconfig.json with expanded dev dependencies.
packages/runtime/package.json, packages/runtime/tsup.config.ts Removed exports and build entries for internal dialect utility modules; dropped pg-connection-string dependency.
packages/runtime/src/client/client-impl.ts, packages/runtime/src/client/options.ts Made dialectConfig required in ClientOptions and ZenStackClient; simplified dialect instantiation logic.
packages/runtime/src/utils/pg-utils.ts, packages/runtime/src/utils/sqlite-utils.ts Deleted utility files for converting connection strings to dialect configs.
packages/runtime/test/client-api/*, packages/runtime/test/plugin/*, packages/runtime/test/typing/* Updated tests to supply explicit dialectConfig when creating ZenStackClient; removed schema-embedded config providers.
packages/runtime/test/utils.ts Refactored test client creation: improved dialect config setup, added helper for file-based SQLite, updated types.
packages/sdk/src/schema/schema.ts, packages/sdk/src/ts-schema-generator.ts Removed dialectConfigProvider from provider type and schema code generation.
samples/blog/main.ts, samples/blog/zenstack/schema.ts Removed custom signUp procedure; now uses explicit SQLite dialect config in client setup.
samples/blog/zenstack/schema.zmodel Whitespace and formatting adjustments in the User model.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant ZenStackClient
    participant Database

    User->>App: Start application
    App->>ZenStackClient: Instantiate with schema and { dialectConfig }
    ZenStackClient->>Database: Connect using provided dialectConfig
    App->>ZenStackClient: Perform queries/mutations
    ZenStackClient->>Database: Execute operations via dialect
    Database-->>ZenStackClient: Return results
    ZenStackClient-->>App: Return results
Loading

Poem

In the warren of code, a change hops through,
Dialect configs now required—no more guessing what to do!
Old helpers are gone, the path is now clear,
Every client’s connection is explicit and dear.
With schemas and tests all tidied anew,
This rabbit approves—hip hop, hooray for the crew! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ymc9 ymc9 added this pull request to the merge queue Jun 17, 2025
Merged via the queue into main with commit 77ea76c Jun 17, 2025
5 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
packages/create-zenstack/src/index.ts (1)

113-118: Wrong sub-command for non-npm package managers

yarn install <pkg> --dev, pnpm install <pkg> etc. are invalid; they should be add.
Switching to add when the agent is not npm avoids a hard failure.

-function installPackage(pkg: { name: string; dev: boolean }) {
-    runCommand(
-        `${agent} install ${pkg.name} ${pkg.dev ? saveDev : ''}`,
-        `Installing "${pkg.name}"`
-    );
+function installPackage(pkg: { name: string; dev: boolean }) {
+    const verb = agent === 'npm' ? 'install' : 'add';
+    runCommand(
+        `${agent} ${verb} ${pkg.name} ${pkg.dev ? saveDev : ''}`,
+        `Installing "${pkg.name}"`
+    );
 }
♻️ Duplicate comments (2)
packages/runtime/test/client-api/default-values.test.ts (1)

67-69: Same DB-handle-cleanup concern as other tests

The test builds a new better-sqlite3 connection that is never closed. Consider applying the afterEach cleanup pattern suggested in query-lifecycle.test.ts to prevent descriptor leaks.

packages/runtime/test/client-api/name-mapping.test.ts (1)

90-92: Same resource-cleanup concern as above

Mirror the fix in the second test case to avoid open handles.

🧹 Nitpick comments (20)
TODO.md (1)

69-69: Normalize list indentation
The newly added task uses 8-space indentation, whereas other checklist items in this subsection are indented by 4 spaces.
Apply this diff to align with the existing style:

-        -   [ ] Implement changesets
+    -   [ ] Implement changesets
packages/runtime/test/typing/verify-typing.ts (1)

3-8: Use an in-memory DB to avoid stray artefacts

Persisting ./zenstack/test.db will leave a file on disk after the type-check run and may cause CI parallelisation conflicts. An in-memory database is usually sufficient for typing tests and keeps the repo clean.

-import SQLite from 'better-sqlite3';
+import SQLite from 'better-sqlite3';
 ...
-        database: new SQLite('./zenstack/test.db'),
+        database: new SQLite(':memory:'),
packages/runtime/test/policy/utils.ts (1)

9-15: Drop the double type assertions – they mask real typing issues

createTestClient is already generic; the extra as any on schema and the cast on the options object are unnecessary and weaken type safety.

-    return createTestClient(
-        schema as any,
-        {
-            ...options,
-            plugins: [new PolicyPlugin()],
-        } as CreateTestClientOptions<SchemaDef>
-    );
+    return createTestClient(schema, {
+        ...options,
+        plugins: [new PolicyPlugin()],
+    });
packages/runtime/test/plugin/mutation-hooks.test.ts (2)

7-7: Remove duplicate space in suite title

-describe('Entity  lifecycle tests', () => {
+describe('Entity lifecycle tests', () => {

11-15: Consider closing the SQLite handle after the suite

better-sqlite3 keeps the connection open until db.close() is called.
Add an afterAll to close it and release resources:

 let _client: ClientContract<typeof schema>;
+let _db: SQLite.Database;

 beforeEach(async () => {
-    _client = new ZenStackClient(schema, {
-        dialectConfig: {
-            database: new SQLite(':memory:'),
-        },
-    });
+    _db = new SQLite(':memory:');
+    _client = new ZenStackClient(schema, { dialectConfig: { database: _db } });
     await _client.$pushSchema();
 });
+
+afterAll(() => _db.close());
packages/cli/src/actions/templates.ts (1)

34-38: Path mismatch between Prisma URL and runtime DB

The datasource URL in the generated schema points to file:./dev.db, but the sample code opens ./zenstack/dev.db.
To prevent confusion (two separate files depending on the working dir) align the paths:

-            database: new SQLite('./zenstack/dev.db'),
+            database: new SQLite('./dev.db'),

(or change the datasource URL to file:./zenstack/dev.db).

Please verify which location you want.

packages/runtime/test/plugin/query-lifecycle.test.ts (1)

10-14: Dispose the in-memory SQLite handle to avoid leaked FDs across tests

Each beforeEach creates a fresh better-sqlite3 instance but it’s never closed, so file descriptors accumulate when the suite grows.
A minimal fix is to retain the Database object and call db.close() in an afterEach.

 let _client: ClientContract<typeof schema>;
+let _db: SQLite.Database;

 beforeEach(async () => {
-    _client = new ZenStackClient(schema, {
-        dialectConfig: {
-            database: new SQLite(':memory:'),
-        },
-    });
+    _db = new SQLite(':memory:');
+    _client = new ZenStackClient(schema, {
+        dialectConfig: { database: _db },
+    });
     await _client.$pushSchema();
 });

+afterEach(() => {
+    _db.close();
+});
samples/blog/README.md (1)

25-28: Nit: make the DB path OS-portable

Using a hard-coded './zenstack/dev.db' is fine, but path.join avoids subtle issues with differing CWDs or separators:

-import SQLite from 'better-sqlite3';
-const db = ZenStackClient(schema, {
-    dialectConfig: { database: new SQLite('./zenstack/dev.db') },
-});
+import path from 'path';
+import SQLite from 'better-sqlite3';
+const db = ZenStackClient(schema, {
+    dialectConfig: {
+        database: new SQLite(path.join(__dirname, 'zenstack', 'dev.db')),
+    },
+});
samples/blog/main.ts (1)

2-2: Portability & cleanup improvements

  1. path.join (see README note) avoids path issues when main.ts is executed from a different CWD.
  2. Consider storing the SQLite.Database instance in a variable and calling close() before process.exit, especially in long-running demos.
-import SQLite from 'better-sqlite3';
+import path from 'path';
+import SQLite from 'better-sqlite3';

-        dialectConfig: {
-            database: new SQLite('./zenstack/dev.db'),
-        },
+        dialectConfig: {
+            database: new SQLite(
+                path.join(__dirname, 'zenstack', 'dev.db')
+            ),
+        },

Also applies to: 7-9

README.md (4)

51-52: Great call-out to the sample – consider linking to the runnable entry file

The added note is helpful. A quick link to samples/blog/main.ts (or equivalent) would make navigation even smoother for readers skimming the README.


141-145: Code snippet could use a concrete driver example

New users may not realise they need to pass an actual driver instance, e.g.

import SQLite from 'better-sqlite3';
const client = new ZenStackClient(schema, {
    dialectConfig: { database: new SQLite('db.sqlite') },
});

Explicitly showing one realistic config avoids “what goes inside { ... }?” questions.


214-215: Minor formatting: stray leading spaces

There’s an extra indentation before postCount making the fenced code block mis-align. Shaving those two spaces keeps the example tidy.


375-376: Replace absolute path interpolation with a relative one

'${outputPath}/schema' in the migration guide may expand to an absolute path (/Users/alex/dev/…) which won’t compile in published code. Using './schema' (or leaving the path unresolved) avoids confusion.

-import { schema } from '${outputPath}/schema';
+import { schema } from './schema';
packages/runtime/test/client-api/name-mapping.test.ts (1)

58-60: Keep a handle to the SQLite instance so it can be closed

better-sqlite3 keeps the DB open until db.close() is called. In long test runs this leaks file descriptors.

-const client = new ZenStackClient(schema, {
-    dialectConfig: { database: new SQLite(':memory:') },
-});
+const db = new SQLite(':memory:');
+const client = new ZenStackClient(schema, {
+    dialectConfig: { database: db },
+});
+afterAll(() => db.close());
packages/cli/src/actions/generate.ts (1)

43-45: Sample import path may output an absolute filesystem path

When outputPath is absolute, the snippet inside the green message turns into import { schema } from '/tmp/foo/schema', which breaks copy-paste usage. Prefer a relative path in the example:

-import { schema } from '${outputPath}/schema';
+import { schema } from './schema';
packages/runtime/test/plugin/kysely-on-query.test.ts (1)

17-19: Close the in-memory SQLite DB after each suite

Just like the other tests, hold a reference to new SQLite(':memory:') and close it in an afterEach hook to keep the test runner clean.

-let _client: ClientContract<typeof schema>;
+let _client: ClientContract<typeof schema>;
+let _db: SQLite.Database;

-beforeEach(async () => {
-    _client = new ZenStackClient(schema, {
-        dialectConfig: { database: new SQLite(':memory:') },
-    });
+beforeEach(async () => {
+    _db = new SQLite(':memory:');
+    _client = new ZenStackClient(schema, {
+        dialectConfig: { database: _db },
+    });
 });

+afterEach(() => _db.close());
packages/runtime/src/client/client-impl.ts (1)

59-64: Redundant nullish-coalescing – options can no longer be undefined

options is now mandatory, so the fallback ?? {} is dead code.

-        this.$options = options ?? ({} as ClientOptions<Schema>);
+        this.$options = options;
packages/runtime/test/utils.ts (3)

21-25: Heavy casting hides type gaps

as unknown as ClientOptions<Schema> circumvents the new mandatory dialectConfig at compile-time. Prefer building a proper object and letting the compiler ensure safety.


98-104: plugins removed from options before being typed

After destructuring, _options is asserted as ClientOptions but is still missing dialectConfig (added later).
Until the assignment below, the object violates the type – remove the premature cast.

-    const _options: ClientOptions<Schema> = {
-        ...rest,
-    } as ClientOptions<Schema>;
+    const _options = {
+        ...rest,
+    } as Partial<ClientOptions<Schema>>;

136-151: provider defaulting to SQLite is implicit

When provider is omitted the else-branch assumes SQLite.
Explicitly defaulting improves readability and prevents silent mis-config.

-    if (options?.provider === 'postgresql') {
+    const provider = options?.provider ?? 'sqlite';
+    if (provider === 'postgresql') {
         _options.dialectConfig = {
@@
-    } else {
+    } else if (provider === 'sqlite') {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a43be54 and 6cd7e2e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (28)
  • README.md (4 hunks)
  • TODO.md (1 hunks)
  • packages/cli/src/actions/generate.ts (1 hunks)
  • packages/cli/src/actions/templates.ts (1 hunks)
  • packages/cli/test/ts-schema-gen.test.ts (0 hunks)
  • packages/create-zenstack/src/index.ts (1 hunks)
  • packages/runtime/package.json (0 hunks)
  • packages/runtime/src/client/client-impl.ts (4 hunks)
  • packages/runtime/src/client/options.ts (1 hunks)
  • packages/runtime/src/utils/pg-utils.ts (0 hunks)
  • packages/runtime/src/utils/sqlite-utils.ts (0 hunks)
  • packages/runtime/test/client-api/default-values.test.ts (1 hunks)
  • packages/runtime/test/client-api/name-mapping.test.ts (2 hunks)
  • packages/runtime/test/plugin/kysely-on-query.test.ts (2 hunks)
  • packages/runtime/test/plugin/mutation-hooks.test.ts (1 hunks)
  • packages/runtime/test/plugin/query-lifecycle.test.ts (2 hunks)
  • packages/runtime/test/policy/utils.ts (1 hunks)
  • packages/runtime/test/test-schema.ts (0 hunks)
  • packages/runtime/test/typing/schema.ts (1 hunks)
  • packages/runtime/test/typing/verify-typing.ts (1 hunks)
  • packages/runtime/test/utils.ts (5 hunks)
  • packages/runtime/tsup.config.ts (0 hunks)
  • packages/sdk/src/schema/schema.ts (0 hunks)
  • packages/sdk/src/ts-schema-generator.ts (0 hunks)
  • samples/blog/README.md (1 hunks)
  • samples/blog/main.ts (1 hunks)
  • samples/blog/zenstack/schema.ts (1 hunks)
  • samples/blog/zenstack/schema.zmodel (1 hunks)
💤 Files with no reviewable changes (8)
  • packages/cli/test/ts-schema-gen.test.ts
  • packages/runtime/tsup.config.ts
  • packages/sdk/src/schema/schema.ts
  • packages/runtime/package.json
  • packages/runtime/src/utils/pg-utils.ts
  • packages/runtime/test/test-schema.ts
  • packages/sdk/src/ts-schema-generator.ts
  • packages/runtime/src/utils/sqlite-utils.ts
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/runtime/test/plugin/query-lifecycle.test.ts (2)
packages/runtime/src/client/client-impl.ts (1)
  • ZenStackClient (41-47)
packages/runtime/test/test-schema.ts (1)
  • schema (7-328)
packages/runtime/test/typing/verify-typing.ts (2)
packages/runtime/src/client/client-impl.ts (1)
  • ZenStackClient (41-47)
packages/runtime/test/typing/schema.ts (1)
  • schema (11-417)
🪛 markdownlint-cli2 (0.17.2)
TODO.md

69-69: Unordered list indentation
Expected: 4; Actual: 8

(MD007, ul-indent)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test (20.x)
🔇 Additional comments (6)
samples/blog/zenstack/schema.zmodel (1)

12-20: Formatting-only change looks good

Pure whitespace/indentation tweak, no semantic impact on the schema.

packages/runtime/src/client/options.ts (1)

46-51: Making dialectConfig mandatory is a breaking change – scan for missing arguments

Great to see the option becoming explicit, but any call‐sites that still rely on the old optional behaviour will now fail at compile/run time.

Run the quick grep below; expect zero results. Any hit indicates residual-code that needs updating.

#!/bin/bash
# list ZenStackClient constructions that don't mention "dialectConfig"
rg -n --no-heading $'ZenStackClient\\([^,]*\\)$' -g '!**/node_modules/**'
samples/blog/zenstack/schema.ts (1)

8-10: Explicit provider looks good – remember to always pass dialectConfig at client construction time

Removing the dialectConfigProvider and keeping only type: "sqlite" matches the new API requirement.
Just double-check that every place constructing a ZenStackClient for this schema now supplies a proper { dialectConfig } option, otherwise runtime connection errors will surface.

packages/runtime/test/plugin/kysely-on-query.test.ts (1)

27-32: Updated interceptor signature looks correct

The destructured { query, proceed } signature aligns with the new API – no issues spotted.

packages/create-zenstack/src/index.ts (1)

14-24: To confirm how agentExec is used and whether it needs to call the binary runner (e.g. pnpm exec, yarn dlx, bunx), let’s inspect the surrounding code:

#!/bin/bash
# Locate the file under review
file=$(find . -type f -path "*packages/create-zenstack/src/index.ts")
echo "File: $file"

# Show where agentExec is set
echo "----- agentExec declaration -----"
rg -n "agentExec" -A3 -B3 "$file"

# Show how agentExec is actually executed (execa/spawn/etc.)
echo "----- Usage of agentExec / execa / spawn -----"
rg -n -e "agentExec" -e "execa" -e "spawn" -e "execSync" -A3 -B3 "$file"
packages/runtime/test/typing/schema.ts (1)

6-10: Generated file – skipped

This file is generated; no manual changes required.

Comment on lines 142 to +151
private makePostgresKyselyDialect(): PostgresDialect {
const { dialectConfigProvider } = this.schema.provider;
const mergedConfig = {
...dialectConfigProvider(),
...this.options?.dialectConfig,
} as PostgresDialectConfig;
return new PostgresDialect(mergedConfig);
return new PostgresDialect(
this.options.dialectConfig as PostgresDialectConfig
);
}

private makeSqliteKyselyDialect(): SqliteDialect {
const { dialectConfigProvider } = this.schema.provider;
const mergedConfig = {
...dialectConfigProvider(),
...this.options?.dialectConfig,
} as SqliteDialectConfig;
return new SqliteDialect(mergedConfig);
return new SqliteDialect(
this.options.dialectConfig as SqliteDialectConfig
);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

No runtime guard that dialectConfig matches provider

If a caller passes a PostgreSQL dialectConfig while schema.provider.type is 'sqlite' (or vice-versa) the dialect will be built with an incompatible config and fail later.

Add an assertion to fail fast:

 private makePostgresKyselyDialect(): PostgresDialect {
-        return new PostgresDialect(
-            this.options.dialectConfig as PostgresDialectConfig
-        );
+        if (this.schema.provider.type !== 'postgresql') {
+            throw new Error('PostgreSQL dialect requested for non-postgres provider');
+        }
+        return new PostgresDialect(
+            this.options.dialectConfig as PostgresDialectConfig
+        );
 }

(Same check for SQLite.)

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private makePostgresKyselyDialect(): PostgresDialect {
const { dialectConfigProvider } = this.schema.provider;
const mergedConfig = {
...dialectConfigProvider(),
...this.options?.dialectConfig,
} as PostgresDialectConfig;
return new PostgresDialect(mergedConfig);
return new PostgresDialect(
this.options.dialectConfig as PostgresDialectConfig
);
}
private makeSqliteKyselyDialect(): SqliteDialect {
const { dialectConfigProvider } = this.schema.provider;
const mergedConfig = {
...dialectConfigProvider(),
...this.options?.dialectConfig,
} as SqliteDialectConfig;
return new SqliteDialect(mergedConfig);
return new SqliteDialect(
this.options.dialectConfig as SqliteDialectConfig
);
private makePostgresKyselyDialect(): PostgresDialect {
if (this.schema.provider.type !== 'postgresql') {
throw new Error('PostgreSQL dialect requested for non-postgres provider');
}
return new PostgresDialect(
this.options.dialectConfig as PostgresDialectConfig
);
}
private makeSqliteKyselyDialect(): SqliteDialect {
return new SqliteDialect(
this.options.dialectConfig as SqliteDialectConfig
);
}
🤖 Prompt for AI Agents
In packages/runtime/src/client/client-impl.ts around lines 142 to 151, add
runtime assertions to verify that the dialectConfig matches the expected
provider type before constructing the dialect. For the PostgreSQL dialect,
assert that the provider type is 'postgres', and for the SQLite dialect, assert
that it is 'sqlite'. This will ensure that incompatible configs are caught early
and prevent later failures.

Comment on lines +169 to +180
const content = fs.readFileSync(prismaSchemaPath, 'utf-8');
const found = content.match(/^\s*url\s*=(\s|")*([^"]+)(\s|")*$/m);
if (!found) {
throw new Error('No url found in prisma schema');
}
const dbPath = found[2]!;
// convert 'file:./dev.db' to './dev.db'
const r = path.join(
path.dirname(prismaSchemaPath),
dbPath.replace(/^file:/, '')
);
return r;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

❓ Verification inconclusive

Fragile regex for extracting DB path from Prisma schema

The current pattern breaks when:
• the url is wrapped in env()
• the value is single-quoted
• there are additional attributes on the line.

Consider using Prisma’s own parser or a stricter block parser instead of a single-line regex.


Fragile regex for extracting DB path from Prisma schema

The current pattern breaks when:
• the url is wrapped in env()
• the value is single-quoted
• there are additional attributes on the line.

Consider using Prisma’s own parser or a stricter block parser instead of a single-line regex.

🤖 Prompt for AI Agents
In packages/runtime/test/utils.ts around lines 169 to 180, the regex used to
extract the database path from the Prisma schema is fragile and fails with env()
usage, single quotes, or extra attributes. Replace the regex approach with
Prisma's official schema parser or a more robust block parser to accurately
extract the url value, handling different quoting styles and ignoring additional
attributes on the line.

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

Successfully merging this pull request may close these issues.

2 participants