Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Nov 19, 2025

Summary by CodeRabbit

  • New Features

    • Added db seed command to run seed scripts configured in package.json.
    • Database reset now runs seed scripts automatically; use --skip-seed to disable.
    • Seed command accepts extra arguments passed through --.
  • Tests

    • Added tests verifying seeding behavior: direct seed, post-reset seeding, and no-op when no seed script is configured.

Copilot AI review requested due to automatic review settings November 19, 2025 07:44
@claude
Copy link

claude bot commented Nov 19, 2025

Claude Code is working…

I'll analyze this and get back to you.

View job run

@coderabbitai
Copy link

coderabbitai bot commented Nov 19, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a new CLI "db seed" action that reads a seed script from package.json, executes it via execa, integrates optional automatic seeding into migrate reset/dev flows (with a --skip-seed flag), extends getPkgJsonConfig to return seed, and adds tests covering seeding behavior.

Changes

Cohort / File(s) Summary
Dependency
packages/cli/package.json
Added runtime dependency execa: "^9.6.0"
Seed action
packages/cli/src/actions/seed.ts
New module exporting run(options, args) that reads zenstack.seed from package.json, constructs and runs the seed command with execaCommand, logs status, and throws on failure
Config utils
packages/cli/src/actions/action-utils.ts
getPkgJsonConfig(startPath: string) extended to parse and return `seed: string
Actions index
packages/cli/src/actions/index.ts
Exported the new seed action alongside existing action exports
Migrate changes
packages/cli/src/actions/migrate.ts
Added skipSeed?: boolean to CommonOptions; made runReset async; invoke seed after reset unless skipped; include --skip-seed in reset and dev commands
CLI wiring
packages/cli/src/index.ts
Added seedAction wrapper, new db seed subcommand (accepts extra args), and threaded --skip-seed into migrate reset command
Tests
packages/cli/test/db.test.ts
Added tests: run db seed with a configured seed script, run seed after migrate reset --force, and ensure running db seed without config is a no-op (no error)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to:
    • async conversion of runReset and interplay with error propagation when seeding fails
    • accurate path resolution of zenstack.seed relative to package.json
    • correct propagation of CLI extra args into the seed command and handling of --skip-seed

Possibly related PRs

Poem

🐇🌱 I found a script in package.json neat,

I run it quick — the DB gets treats to eat.
Reset, then seed, unless you say "no",
A rabbit's hop brings data where it should grow.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(cli): db seed command' accurately summarizes the main change: adding a new db seed CLI command to the CLI package.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch seed

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c4fa082 and 46cfa6a.

📒 Files selected for processing (1)
  • packages/cli/src/index.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/cli/src/index.ts (1)
packages/cli/src/telemetry.ts (1)
  • telemetry (139-139)
🔇 Additional comments (2)
packages/cli/src/index.ts (2)

37-39: LGTM! Clean telemetry wrapper.

The seedAction function follows the established pattern for action wrappers in this file and correctly integrates with telemetry tracking.


94-94: LGTM! Option addition is clean.

The --skip-seed option is properly integrated into the migrate reset command and aligns with the PR's goal of adding optional automatic seeding to the reset flow.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@ymc9
Copy link
Member Author

ymc9 commented Nov 19, 2025

fixes #387

Copilot finished reviewing on behalf of ymc9 November 19, 2025 07:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new db seed command to the ZenStack CLI that allows users to seed their database using a custom script defined in package.json. The seeding functionality is also integrated into the migrate reset command with an option to skip it.

Key Changes:

  • New zen db seed command that executes a seed script from package.json configuration
  • Integration with migrate reset to automatically run seeding after reset (with --skip-seed opt-out)
  • Both migrate dev and migrate reset now pass --skip-seed to Prisma to use ZenStack's custom seeding instead

Reviewed Changes

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

Show a summary per file
File Description
pnpm-lock.yaml Adds execa ^9.6.0 dependency for command execution
packages/cli/package.json Adds execa dependency to the CLI package
packages/cli/src/actions/seed.ts New seed action that executes custom seed scripts from package.json
packages/cli/src/actions/index.ts Exports the new seed action
packages/cli/src/actions/action-utils.ts Extends getPkgJsonConfig to support seed script configuration
packages/cli/src/actions/migrate.ts Integrates seeding into migrate reset with skip-seed option
packages/cli/src/index.ts Registers new db seed command and adds skip-seed option to migrate reset
packages/cli/test/db.test.ts Adds comprehensive tests for seeding functionality
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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: 4

🧹 Nitpick comments (1)
packages/cli/src/actions/action-utils.ts (1)

80-112: Inconsistent path handling for seed configuration.

Lines 100-107 resolve schema and output to absolute paths using path.resolve, but Line 108 treats seed as a raw string without path resolution. This inconsistency could be confusing.

However, this appears intentional since seed is a shell command (e.g., "node seed.js" or "npm run seed"), not a file path. Consider adding a comment to clarify this distinction.

Add a clarifying comment:

         result.seed = typeof pkgJson.zenstack.seed === 'string' && pkgJson.zenstack.seed;
+        // Note: seed is a shell command string, not a file path, so it's not resolved
     }

Additionally, consider refactoring the logical AND pattern for better clarity:

     if (pkgJson.zenstack && typeof pkgJson.zenstack === 'object') {
-        result.schema =
-            pkgJson.zenstack.schema &&
-            typeof pkgJson.zenstack.schema === 'string' &&
-            path.resolve(path.dirname(pkgJsonFile), pkgJson.zenstack.schema);
-        result.output =
-            pkgJson.zenstack.output &&
-            typeof pkgJson.zenstack.output === 'string' &&
-            path.resolve(path.dirname(pkgJsonFile), pkgJson.zenstack.output);
-        result.seed = typeof pkgJson.zenstack.seed === 'string' && pkgJson.zenstack.seed;
+        if (pkgJson.zenstack.schema && typeof pkgJson.zenstack.schema === 'string') {
+            result.schema = path.resolve(path.dirname(pkgJsonFile), pkgJson.zenstack.schema);
+        }
+        if (pkgJson.zenstack.output && typeof pkgJson.zenstack.output === 'string') {
+            result.output = path.resolve(path.dirname(pkgJsonFile), pkgJson.zenstack.output);
+        }
+        if (typeof pkgJson.zenstack.seed === 'string') {
+            result.seed = pkgJson.zenstack.seed;
+        }
     }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 127393e and c4fa082.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • packages/cli/package.json (1 hunks)
  • packages/cli/src/actions/action-utils.ts (2 hunks)
  • packages/cli/src/actions/index.ts (1 hunks)
  • packages/cli/src/actions/migrate.ts (3 hunks)
  • packages/cli/src/actions/seed.ts (1 hunks)
  • packages/cli/src/index.ts (3 hunks)
  • packages/cli/test/db.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
packages/cli/src/actions/seed.ts (2)
packages/cli/src/actions/action-utils.ts (1)
  • getPkgJsonConfig (80-112)
packages/cli/src/cli-error.ts (1)
  • CliError (4-4)
packages/cli/src/actions/migrate.ts (2)
packages/cli/src/utils/exec-utils.ts (1)
  • execPrisma (32-53)
packages/cli/src/actions/action-utils.ts (1)
  • handleSubProcessError (58-64)
packages/cli/src/index.ts (1)
packages/cli/src/telemetry.ts (1)
  • telemetry (139-139)
packages/cli/test/db.test.ts (1)
packages/cli/test/utils.ts (2)
  • createProject (12-18)
  • runCli (20-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Agent
  • GitHub Check: build-test (20.x, sqlite)
  • GitHub Check: build-test (20.x, postgresql)
  • GitHub Check: claude-review
🔇 Additional comments (10)
packages/cli/src/actions/index.ts (1)

8-10: LGTM!

The seed action export follows the existing pattern and integrates cleanly with the other action exports.

packages/cli/src/actions/seed.ts (1)

14-21: Clean early return handling.

The early return when no seed script is defined is well-structured, with appropriate warning suppression via the noWarnings option.

packages/cli/src/index.ts (2)

37-39: LGTM!

The seedAction follows the established pattern for action wrappers and correctly tracks the command as 'db seed' for telemetry.


94-94: Good integration with migrate reset workflow.

The --skip-seed option provides appropriate control over the seeding behavior during reset operations.

packages/cli/test/db.test.ts (1)

57-60: LGTM!

The test correctly validates that the CLI handles the absence of a seed script gracefully without errors.

packages/cli/src/actions/migrate.ts (4)

6-6: Good integration with seed action.

Importing the seed runner enables post-migration seeding in the reset workflow.


11-11: LGTM!

The skipSeed option is appropriately added to CommonOptions to control seeding behavior across migrate commands.


69-83: Clarify seeding behavior in dev command.

The dev command unconditionally passes --skip-seed to Prisma (Line 75), but there's no corresponding ZenStack seed execution after the migration like in the reset command. This means users cannot seed during migrate dev workflow.

Is this intentional? Consider whether the dev command should also respect the skipSeed option and conditionally run the ZenStack seed after migration, similar to the reset command.

Please clarify if:

  1. Seeding is intentionally not supported during migrate dev
  2. If supported, should it follow the same pattern as reset (Lines 99-101)?
// Potential enhancement for consistency:
async function runDev(prismaSchemaFile: string, options: DevOptions) {
    try {
        const cmd = [
            'migrate dev',
            ` --schema "${prismaSchemaFile}"`,
            ' --skip-generate',
            ' --skip-seed',  // Skip Prisma's seed
            options.name ? ` --name "${options.name}"` : '',
            options.createOnly ? ' --create-only' : '',
        ].join('');
        execPrisma(cmd);
    } catch (err) {
        handleSubProcessError(err);
    }
    
    // Should we add this?
    if (!options.skipSeed && !options.createOnly) {
        await runSeed({ noWarnings: true, printStatus: true }, []);
    }
}

85-102: Well-implemented post-reset seeding.

The async conversion of runReset and the conditional seeding logic (Lines 99-101) is clean and follows good practices. The noWarnings: true and printStatus: true options are appropriate for this context.

packages/cli/package.json (1)

37-37: Execa version 9.6.0 has no known security vulnerabilities; however, compatibility verification is incomplete.

The security check passed with no known vulnerabilities for execa 9.6.0. The package requires Node.js "^18.19.0 || >=20.5.0", which are modern versions. However, the project does not declare explicit Node.js version requirements in packages/cli/package.json or the root package.json. Confirm that the project's actual runtime environment supports one of execa's required Node.js versions.

@claude
Copy link

claude bot commented Nov 19, 2025

Claude Code is working…

I'll analyze this and get back to you.

View job run

@ymc9 ymc9 merged commit 1d4011b into dev Nov 19, 2025
4 of 5 checks passed
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