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 eight 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