Skip to content

fix(cli): stop model scaffolding when the schema already exists - #1053

Merged
cpojer merged 4 commits into
voidzero-dev:mainfrom
niteshseram:fix/model-gen-rerun
Dec 6, 2026
Merged

cpojer merged 4 commits into
voidzero-dev:mainfrom
niteshseram:fix/model-gen-rerun

Conversation

@niteshseram

Copy link
Copy Markdown
Contributor

Summary

Rerunning void gen model for an existing model could report success after generating routes that disagree with the schema. For example, if posts has a required title column and its collection route is missing, void gen model posts body:text keeps the existing schema but creates a POST handler that accepts and inserts body.

Check the model’s schema path before prompting for a validator or writing any files. If the file exists, the command exits with code 1 and reports:

Model 'posts' already exists at db/schema/posts.ts. Edit the schema and update any affected routes.

The check respects sourceDir and reads the project config without writing a cache. New schema files are created exclusively so concurrent invocations for the same model cannot overwrite each other.

Tests

  • gen.test.ts covers reruns with the collection route present and missing. Both cases fail before prompting, creating files, or changing existing files. The existing-route case also covers a custom sourceDir

cpojer
cpojer previously approved these changes Dec 6, 2026

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contributions! 🙇‍♂️

@cpojer
cpojer enabled auto-merge (squash) December 6, 2026 00:20
# Conflicts:
#	packages/void/src/cli/gen.ts
#	packages/void/test/unit/gen.test.ts

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contributions! 🙇‍♂️

@cpojer
cpojer merged commit 5bfa569 into voidzero-dev:main Dec 6, 2026
20 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