grit remove resource — clean undo
Reverse the 8 files + 10 injection points in one command.
Generation is one half of the resource lifecycle. The other half is removal. When a feature gets cut, a prototype doesn't pan out, or you realised you spelled Cunstomer wrong — you need to undo all 8 files plus the 10+ injection points cleanly. That's grit remove resource.
The command
$grit remove resource Contact
You'll see a confirmation prompt, then:
⚠ This will remove all files and injections for resource "Contact".Continue? [y/N]: yRemoving resource: ContactDeleting files...✗ apps/api/internal/models/contact.go✗ apps/api/internal/services/contact.go✗ apps/api/internal/handlers/contact.go✗ packages/shared/schemas/contact.ts✗ packages/shared/types/contact.ts✗ apps/web/hooks/use-contacts.ts✗ apps/admin/hooks/use-contacts.ts✗ apps/admin/resources/contacts.ts✗ apps/admin/app/(dashboard)/resources/contacts/page.tsxCleaning injections...✗ Removed model from AutoMigrate✗ Removed model from GORM Studio✗ Removed handler initialization✗ Removed API routes✗ Removed admin sidebar entry✗ Removed registry entry✗ Removed shared schemas/index.ts export✗ Removed shared types/index.ts export✗ Removed admin resources/index.ts re-export✅ Contact has been removed.Next steps:grit migrate # drop the contacts table (or do it manually)
What it deletes
The mirror image of the 8 files grit generate wrote, plus a couple of admin-only artefacts:
Generated file Removed?─────────────────────────────────────────────────────── ────────apps/api/internal/models/contact.go ✓apps/api/internal/services/contact.go ✓apps/api/internal/handlers/contact.go ✓packages/shared/schemas/contact.ts ✓packages/shared/types/contact.ts ✓apps/web/hooks/use-contacts.ts ✓apps/admin/hooks/use-contacts.ts ✓apps/admin/resources/contacts.ts ✓apps/admin/app/(dashboard)/resources/contacts/page.tsx ✓apps/admin/app/(dashboard)/resources/contacts/ (empty dir, also removed)
What it un-injects
Every edit the generator made to existing files gets reversed, marker by marker:
apps/api/internal/models/user.go— the line that added&Contact{}toAutoMigrate.apps/api/internal/routes/routes.go— the GORM-Studio model list, the handler initialisation block, the public/admin route group, and any role-restricted routes.packages/shared/schemas/index.ts— the re-exports ofCreateContactSchema/UpdateContactSchema.packages/shared/types/index.ts— theContacttype re-export.packages/shared/constants/index.ts— any related route constants.apps/admin/resources/index.ts— the resource registry entry, so the sidebar link disappears too.
// grit:routes:contact. Removal walks those markers and excises the exact block between them. Custom code you wrote between markers is safe; only the marker-fenced lines are deleted.What it does NOT do
- Drop the database table. Your data stays. Run a manual
DROP TABLE contacts;or write a down-migration if you want the table gone. - Touch any custom code you wrote. If you added methods to the service, edited the admin form, or wrote a custom hook — those edits live outside the marker fences and are wiped along with the file that contains them. Move any custom logic out before running remove if you want to keep it.
- Reverse relationships. If another resource (Group) still has
contact:belongs_to:Contact, those references compile-error until you fix them.
Flags
$grit remove resource Contact --force # skip confirmation, useful in CI
The full lifecycle, end-to-end
# Day 1 — prototype a Contact resource$grit generate resource Contact --fields "name:string,email:string:unique"$grit migrate# Day 2 — realised Contact is actually two things: Lead + Customer$grit remove resource Contact # gone in one command$grit generate resource Lead --fields "name:string,email:string,source:string"$grit generate resource Customer --fields "name:string,email:string:unique,plan:string"$grit migrate# Now you have two clean resources instead of one half-finished one.
Quick check
Try it
Practice the round trip in your contact-app project:
- Generate a throwaway resource:
grit generate resource Widget --fields "name:string,color:string" grit migrate- Confirm the admin sidebar has a "Widgets" entry and
GET /api/widgetsreturns the empty paginated list. - Remove it:
grit remove resource Widget - Confirm the sidebar entry is gone, the 8 files are deleted, and
grep -r Widget apps/returns no matches.
Paste the removal output into notes.md.
What's next
You can now generate, sync, and remove. The remaining lessons zoom in on the surfaces you'll customise the most after the generator runs — the admin form, the admin table, and the web-app integration that consumes the generated React Query hook.
Spot a typo? Have an idea?
Help us improve this lesson. One click opens a GitHub issue with the lesson URL pre-filled — suggest clearer wording, report a bug, or request more depth. The course keeps improving thanks to learners like you.
Suggest an improvement on GitHub