Some checks failed
✅ Check / 🔬 ESLint (push) Failing after 21s
✅ Check / 🏷️ Typecheck (push) Failing after 11s
✅ Check / 🔎 Test (push) Failing after 11s
✅ Check / e2e-test (push) Failing after 11s
✅ Check / 🔨 Build (push) Failing after 11s
🚀 Deploy / 🚀 Deploy (doc) (push) Failing after 12s
🚀 Deploy / 🚀 Deploy (demo) (push) Failing after 12s
🚀 Deploy / 🚀 Deploy (supabase) (push) Failing after 18s
7.5 KiB
7.5 KiB
Deleting companies
A spine/link resource: it owns the companies table and is a company_id link on both contacts and deals, its companies_summary view aggregates nb_contacts/nb_deals, and it adds a denormalized company_name to the Contact type. So it fans out far wider than its folder (≈50 frontend files + backend).
Confirm cascade scope first
Remove company_id fully — drop the column from the Contact/Deal types, the CSV import/export, mergeContacts, the fakerest generators, and i18n. This full removal is what makes the deletion large.
Frontend specifics
- Activity log — a dedicated
company.createdbranch (deleteActivityLogCompanyCreated.tsxoutright + the branch inActivityLogIterator.tsx+COMPANY_CREATEDinconsts.ts/types.ts) and a"company"member in the context union. Narrowing the union turns the=== "company"checks inActivityLogContactCreated/ActivityLogContactNoteCreated/ActivityLogDealCreated/ActivityLogDealNoteCreatedinto type errors — prune those branches (thecompany_id"to/at<company>" ReferenceField + theCompanyAvatarin the deal-note header).ActivityLog.tsxhas acompanyIdprop +company_idfilter;providers/commons/activity.tshas agetNewCompaniesfetcher +companyIdparam. company_idlink on contacts (ContactInputsselector,ContactShow/ContactListContentavatar+name, the exporter'sfetchRelatedRecords+ thecompanyCSV column,contactModel.ts's vCardORG:line,ExportVCardButton.tsx) and on deals (DealInputsrequired selector,DealCard/DealShow/DealEditavatar,DealListfilter), plus the note-headerCompanyAvatarinnotes/Note.tsx.- Denormalized
company_name(fromcompanies_summary'sc.name as company_name) — read inContactOption.tsx,deals/ContactList.tsx,dashboard/HotContacts.tsx, and theposition_at_companyrendering. Invisible to a\bcompan(y|ies)\bgrep — grepcompany_nameseparately. companySectorsconfig prop — see SKILL.md "Shapes a resource takes" for the standard config-prop locations. Companies-specific: the<Card>holds only acompanySectorsArrayInput(novalidateItemsInUse), and it's also read inuseImportFromJson.tsto validate an importedsector.- Providers — supabase
getList/getOneroutecompanies -> companies_summary(drop both); the contacts FTS list addscompany_name. FakeRest hasprocessCompanyLogo(favicon),fetchAndUpdateCompanyData(stampscompany_nameonto contacts, called from the contactsbeforeCreate/beforeUpdate),updateCompany(maintainsnb_contacts/nb_dealsfrom the contacts/dealsafterCreate/afterDelete), the wholecompaniescallback block, thecompaniesarm of thesalesbeforeDeletereassignment, and thegetActivityLog(dataProvider, companyId, salesId)call (drop thecompanyIdarg + thecompanyId/company_idfilter plumbing inproviders/commons/activity.ts). Deleteproviders/commons/getCompanyAvatar.ts+ test. - FakeRest generators are deeply company-coupled —
dataGenerator/companies.tsdeleted outright + dropped fromindex.ts(mind the order: sales → tags → [companies] → contacts → …) andtypes.ts(Db.companies).contacts.tspicks a company to derivecompany_id/company_name/sales_id/first_seen(+ a per-companymaxContactscap), anddeals.tspicks a company then filters contacts bycompany_idforcontact_ids— rewrite both to pick a randomdb.sales+randomDate()(and random contacts for deals). Thefakercompanynamespace import is unrelated — keep it. - JSON importer treats
companiesas a top-level type (importCompany,$.companies.*,CompanyImport/isCompany,mapSizeToCategory,companySectorsvalidation, stats/idsMaps keys) + thecompany_idmapping on imported contacts. Mirror inImportPage.tsx+import-sample.json. CSV importer (useContactImport.tsx) has agetCompaniescache + acompanycolumn →company_id. - Mislabeled i18n:
deals/OnlyMineInput.tsxusesresources.companies.filters.only_mine("Only companies I manage") even though it filters deals — re-point it to a deals key, don't delete the input.
Backend
- Drop the
companiestable +companies_id_seqgrant + RLS-enable line + its 4 policies + table grants. Dropcompany_idon bothcontactsanddeals(FKscontacts_company_id_fkey/deals_company_id_fkey+ indexescontacts_company_id_idx/deals_company_id_idx). Drop thecompanies_summaryview (+ grant). Updatecontacts_summary: dropco.company_id, thec.name as company_namecolumn, theleft join public.companies, and narrow thegroup bytoco.id. activity_logview carries the company pattern (acompanycolumn on every branch and a dedicatedcompany.createdbranch) — remove thecompany+company_idcolumns from all branches (thecontactNote/dealNotebranches only joined a table to fetchcompany_id, so drop those now-unused joins) and delete the branch.- Drop the company-only function
handle_company_saved(favicon-from-website trigger) + itscompany_savedtrigger + grant, and theset_company_sales_id_trigger. Drop thecompany_idline frommerge_contacts. Orphan subtlety:handle_company_savedcallsget_domain_favicon, but so doesget_avatar_for_email(contact avatars) — so it is not orphaned; keepget_domain_faviconand thefavicons_excluded_domainstable. - Edge functions: unlike
contacts(delete the whole function), keeppostmark/and surgically remove the company bits — it auto-creates a company from the sender's email domain (getOrCreateCompanyFromDomaininaddNoteToContact.ts,extractCompanyNameinextractMailContactData.ts) and links the new contact viacompany_id. DeletegetOrCreateCompanyFromDomain, drop thedomain/companyName/websiteparams threaded throughgetOrCreateContactFromEmailInfo/addNoteToContact/index.ts, dropcompany_idfrom the contact insert, removeextractCompanyName+ thecompanyName/websiteoutput fields + the now-unusedtldtsimport fromextractMailContactData.ts, and update the postmark tests (addNoteToContact.test.ts,extractMailContactData.test.ts). Flag that auto-company-creation on inbound email is gone but contact+note creation still works. Elsewhere:_shared/db.tsdeclarescompany_idon bothContactsTableandDealsTable(no dedicatedCompaniesTable);merge_contacts/index.tsmergescompany_idinmergeContactData;mcp/index.ts+mcp/validateSql.test.tsmentioncompanies/companies_summaryin prompt examples/fixtures (swap for a surviving table). Noconfig.tomlblock changes are needed (postmark + merge_contacts both survive).
grep — benign matches to leave
- The
fakercompanynamespace import indataGenerator/contacts.ts(used forbsAdjective()titles), thereference="companies"/source="company_id"JSDoc examples in the mutableadmin/reference-input.tsx/admin/list.tsx, and email-domain fixtures like@company.com/original.recipient@company.comin test bodies. - Dead i18n keys (
resources.companies.*,position_at_company,you_added_company/at_company,crm.settings.companies.*) — flag, don't force (both catalogs or neither).test-data/contacts.csvkeepscompany_id/company_name/companycolumns — the importer ignores them, so leaving them is harmless; dropping means editing the header and all ~500 rows — flag it.