Conversation
WalkthroughSwitches CockroachDB generator output from a pg Pool to Bun SQL, changes DATABASE_URL scheme for CockroachDB to PostgreSQL-style, updates Docker init templates and image/command, replaces unique_rowid() with a sequence for uid, and adds CockroachDB lifecycle scripts to package.json. Changes
Sequence DiagramsequenceDiagram
participant Gen as Generator
participant CG as Codegen
participant DB as CockroachDB
rect rgb(245,245,255)
Note over Gen,CG: Old flow (pg Pool / unique_rowid)
Gen->>CG: emit DB block using Pool(DATABASE_URL)
CG->>DB: pg.Pool connect
DB-->>CG: unique_rowid() IDs
end
rect rgb(245,255,245)
Note over Gen,CG: New flow (bun SQL / sequence)
Gen->>CG: emit DB block using SQL(DATABASE_URL)
CG->>DB: Bun SQL connect
DB-->>CG: sequence-based IDs (nextval)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (2)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/generators/db/dockerInitTemplates.ts (1)
114-114: Clarify the purpose of sleep 1 in the CLI command.The
sleep 1prefix in the CockroachDB CLI command suggests a timing-related workaround. If this addresses a known race condition, consider adding a comment explaining why it's needed.src/generators/db/generateDockerContainer.ts (1)
8-8: Pin to a specific patch version instead of using the movinglatest-v25.3tag.Using
latest-v25.3prevents reproducible builds as it's a moving target. Pin to the latest stable patch versionv25.3.5(released November 14, 2025):image: 'cockroachdb/cockroach:v25.3.5',
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
src/generators/configurations/generateEnv.ts(1 hunks)src/generators/configurations/generatePackageJson.ts(1 hunks)src/generators/db/dockerInitTemplates.ts(2 hunks)src/generators/db/generateDockerContainer.ts(9 hunks)src/generators/db/handlerTemplates.ts(1 hunks)src/generators/project/generateDBBlock.ts(1 hunks)src/generators/project/generateImportsBlock.ts(1 hunks)
🔇 Additional comments (8)
src/generators/db/generateDockerContainer.ts (2)
11-11: Verify the command field implementation for empty strings.The
commandfield is emitted for all database templates, including those with empty strings. In Docker Compose, an emptycommand:directive may override the default container command, potentially breaking databases that rely on default startup behavior.Consider either:
- Conditionally omitting the command field when it's empty
- Verifying that empty command strings don't affect other database containers
Apply this diff to conditionally emit the command:
const { image, port, env, volumePath, command } = templates[databaseEngine]; const envLines = Object.entries(env) .map(([key, value]) => ` ${key}: ${value}`) .join('\n'); + const commandLine = command ? ` command: ${command}\n` : ''; return `services: db: image: ${image} restart: always environment: ${envLines} ports: - "${port}" - command: ${command} +${commandLine} volumes: - db_data:${volumePath}
6-6: No issues found — COCKROACH_DATABASE is the correct environment variable.COCKROACH_DATABASE is a documented CockroachDB Docker environment variable that creates a database automatically at first startup when using the start-single-node command. The current implementation with
COCKROACH_DATABASE: 'database'and the commandstart-single-node --insecureis correct. The variable name and value align with CockroachDB's official Docker configuration requirements and are consistent with the database initialization pattern used for other engines in this file (e.g.,MONGO_INITDB_DATABASE,POSTGRES_DB,MYSQL_DATABASE).src/generators/project/generateDBBlock.ts (1)
7-9: LGTM! CockroachDB correctly uses Bun SQL.The switch from Pool to SQL-based connection for CockroachDB is appropriate and aligns with PostgreSQL's implementation, leveraging CockroachDB's PostgreSQL wire protocol compatibility.
src/generators/project/generateImportsBlock.ts (1)
148-154: LGTM! CockroachDB correctly included in no-ORM PostgreSQL path.The extension of the import logic to include CockroachDB alongside PostgreSQL is appropriate, given their wire protocol compatibility. This ensures proper imports for both local (Bun SQL) and remote (Neon) configurations.
src/generators/configurations/generatePackageJson.ts (1)
183-199: LGTM! CockroachDB lifecycle scripts follow established patterns.The script block correctly mirrors the PostgreSQL pattern with appropriate adjustments for CockroachDB's CLI tools and project naming.
src/generators/configurations/generateEnv.ts (1)
13-13: No issues found—CockroachDB configuration is consistent.The DATABASE_URL and Docker environment are properly aligned:
- Database name matches: both use
'database'- Connection string correctly uses
root@localhost:26257/databasewith no password (appropriate for insecure mode)- Docker startup command includes
--insecure, aligning with the passwordless root user connection- CockroachDB's default behavior in insecure mode allows root to connect without authentication
src/generators/db/dockerInitTemplates.ts (1)
55-60: No issues found; code is correct.CockroachDB supports PostgreSQL-style CREATE SEQUENCE and the sequence functions nextval(), confirming the syntax is valid. The choice of BIGINT for the CockroachDB implementation is intentional and differs from other databases in the file (PostgreSQL uses INTEGER, MySQL/MariaDB/SingleStore use INT), which is appropriate for CockroachDB's distributed architecture. The sequence name
count_history_uid_seqfollows standard SQL naming conventions.src/generators/db/handlerTemplates.ts (1)
317-321: Verify Bun SQL integration with CockroachDB at runtime.The configuration correctly reuses
postgresSqlQueryOperationsfor CockroachDB, which is sound because CockroachDB implements the PostgreSQL wire protocol. Bun's built-in SQL can connect to CockroachDB by using Bun's PostgreSQL adapter/connection string. However, expect possible SQL-dialect or feature differences since CockroachDB does not implement all Postgres extensions/behaviors, so test the queries, transactions, and any Postgres-specific features before deployment.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/generators/db/dockerInitTemplates.ts (1)
55-60: Consider using IDENTITY columns instead of manual sequences.CockroachDB supports
GENERATED ALWAYS AS IDENTITYsyntax (similar to PostgreSQL on line 8), which is cleaner, more maintainable, and automatically idempotent compared to manually creating sequences.Apply this diff to align with PostgreSQL's approach:
-const cockroachdbCountHistory = `CREATE SEQUENCE count_history_uid_seq START WITH 1 INCREMENT BY 1; -CREATE TABLE IF NOT EXISTS count_history ( - uid BIGINT PRIMARY KEY DEFAULT nextval('count_history_uid_seq'), +const cockroachdbCountHistory = `CREATE TABLE IF NOT EXISTS count_history ( + uid BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, count INT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT NOW() );`;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/generators/configurations/generatePackageJson.ts(1 hunks)src/generators/db/dockerInitTemplates.ts(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/generators/configurations/generatePackageJson.ts
🔇 Additional comments (1)
src/generators/db/dockerInitTemplates.ts (1)
114-115: CockroachDB CLI syntax verified—no issues found.The
cockroach sqlcommand supports both--databaseand--insecureflags. The implementation correctly uses these flags for local development without TLS, and the wait condition adequately tests server readiness with aselect 1check. The code properly addresses the previous review feedback about database session context.
absolutejs
left a comment
There was a problem hiding this comment.
Just fix the code rabbit suggestion
Summary by CodeRabbit
New Features
Improvements
Behavioral
✏️ Tip: You can customize this high-level summary in your review settings.