feat(api): add local-dev seed command and document it - #308
Conversation
Add `api seed`, a subcommand that populates a local database with a demo user (demo@devlane.test / Demo1234!), a workspace, a project with the standard workflow states, and a handful of sample work items, so a fresh clone has something to explore without clicking through first-run setup. It's idempotent: a second run is a no-op once the demo user exists, and it only seeds instance admin/settings when the instance isn't set up yet. Document it in the root README, CONTRIBUTING (Local development), and the API README commands. Closes Devlaner#24 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 6 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe API now supports a ChangesLocal development seeding
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Developer
participant API
participant Database
participant Services
Developer->>API: run go run ./cmd/api seed
API->>Database: initialize connection
API->>Services: create demo user, workspace, project, states
Services->>Database: persist demo data
API->>Services: create sample issues
Services->>Database: persist issues
API-->>Developer: print seed summary and credentials
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/api/cmd/api/seed.go`:
- Around line 84-95: Update seedDevData to propagate store errors: at
apps/api/cmd/api/seed.go:61-68, return GetByEmail errors except
gorm.ErrRecordNotFound; at apps/api/cmd/api/seed.go:84-95, handle and return
errors from CountActive, Create, settings.Get, and settings.Upsert; at
apps/api/cmd/api/seed.go:131-136, return ListByProjectID errors instead of
leaving stateByName empty. Preserve successful and not-found handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 79501450-643b-40c1-8a97-c96ab9f1080d
📒 Files selected for processing (6)
CONTRIBUTING.mdREADME.mdapps/api/README.mdapps/api/cmd/api/main.goapps/api/cmd/api/seed.goapps/api/cmd/api/seed_test.go
|
@martian56 this one's green (build + lint) with no open review comments. Small one: adds an api seed command for local dev plus docs. Good to merge when you get a chance. |
…them The seed discarded errors from the user lookup, instance-admin count/create, settings read/write, and state listing. A transient DB error would then be misread (e.g. "needs seeding") and could leave a half-seeded instance. Each is now checked and wrapped, treating only gorm.ErrRecordNotFound as "absent". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@martian56 addressed the review note (seed now surfaces store errors instead of swallowing them). Green — good to merge. |
Feature summary
A new
go run ./cmd/api seedcommand populates a local database with a demo user, workspace, project, workflow states, and sample work items, so a fresh clone is explorable in one step instead of clicking through first-run setup.Linked issues / discussion
Closes #24
User-facing behavior
From
apps/api, a contributor runs:It creates a demo user (
demo@devlane.test/Demo1234!), a Demo Workspace, a Getting Started project with the standard five workflow states (one marked default), and five sample work items across those states/priorities. Signing in with those credentials shows a populated instance. Running it again prints "already exists — nothing to do" and changes nothing.What changed
API (
apps/api/)cmd/api/seed.gowith aseedsubcommand (wired inmain.gonext to the existingadminsubcommand). It reuses the real services (auth.SignUp, workspace/project/issue services, state store) so seeded data goes through the same paths as normal creation. Idempotent via a demo-user existence check; instance admin +generalsettings are only seeded when the instance isn't already set up.Database
Docs
README.md,CONTRIBUTING.md(Local development), andapps/api/README.md(Commands) now mention the seed as an alternative to manual first-run setup.Why this design
Driving the existing services rather than raw inserts keeps the seed correct as the domain evolves (sequence IDs, memberships, default-state fallback, activity rows all happen for free) and avoids a parallel data-creation path that could drift. Idempotency makes it safe to re-run in a shared/long-lived dev DB.
Test plan
go test ./cmd/api—TestSeedDevData_CreatesDemoAndIsIdempotentasserts the demo user/workspace/project, 5 states with exactly one default, 5 issues, and that a second run adds nothinggo run ./cmd/api seedagainst a live local DB: created the demo data; a second run was a clean no-opgo vet/ pre-commit greenAI assistance
Claude Code (Claude Opus 4.8)— and AI-assisted commits include aCo-Authored-By:trailerChecklist
Summary by CodeRabbit
New Features
seedcommand to create a demo account, workspace, project, workflow states, and sample work items.Documentation