DA10: Capstone: three automations for Sharma Textiles
Project 3: the weekly CRM tidy-up
🎯You'll be able to
Build the CRM tidy-up with a dry run, backup, change limit and approval, and prove it with the acceptance tests.
🏠The everyday picture
Every Sunday, a shopkeeper sorts the stockroom: duplicate boxes combined, wrong labels fixed, empty boxes thrown out. Then they note what changed, so nothing surprising happens on Monday.
📘What it really is
- Schedule: a weekly trigger at a quiet time, such as Sunday 7 am IST.
- Fetch every contact with pagination (DA7), checking the count.
- Clean: phones to E.164 and names tidied, using the shared cleaning step (DA4).
-
Find duplicates by phone or email, and merge using a written rule: newest value per field, without overwriting a filled field with an empty one (DA5).
-
Flag, don't guess: invalid phones, missing consent and contacts with no owner go to a review list.
- Change report: before and after counts, merges made with both records' IDs, fields changed, and items for review.
- Safety: dry-run mode that produces the report without changing anything; a backup export before each live run; a limit, such as "stop if more than 10% of contacts would change", that needs a person's approval.
📝A worked example
A learner's first live run, after two dry runs:
| Measure | Value |
|---|---|
| Contacts before | 412 |
| Phones cleaned | 63 |
| Duplicates merged | 41 (report lists each pair) |
| Sent to review | 9 invalid phones, 4 missing owner |
| Contacts after | 371 |
| Change share | 137 of 412 contacts touched (about 33%): above the 10% limit, so it paused for approval |
The owner reviewed the report and approved. Because this was the first clean-up, the large change was expected; the following week only 6 contacts changed.
🌍Where it's used
- Sales and marketing teams whose CRM fills with duplicates from forms, imports and events.
- Before campaigns, so messages reach the right people once.
- Data protection work: finding records without consent.
📝Case scenario
A tidy-up script without a dry run or change limit merges 200 contacts wrongly after a CRM field was renamed, so every email field looked empty. The learner restores from the backup, adds a check that stops the run if a key field is empty for most contacts, adds the dry run and the 10% limit, and runs two dry runs before going live again.
🖱️Try it
Build the tidy-up with dry-run mode, a backup export, a change report and a change limit. Run it twice in dry-run mode on your sample CRM, compare the reports with a manual check of 20 contacts, then run it live.
⚠️Common mistakes
- Validating phones before merging. Sign: duplicates with an empty phone are flagged as invalid. Fix: merge first, then validate the merged record.
- No stop rule for strange data. Sign: a renamed field leads to hundreds of wrong merges. Fix: stop when key fields are empty for most records.
🛠️For your project
This is Project 3. Run node tests/tidyup.js; it runs a dry run, a live run with approval, and a second live run that should change nothing.
✅Quick check
What is a dry run?
Show the answer
A run that produces the full report of what would change, without changing anything.
Why set a limit on how many contacts one run can change?
Show the answer
So an unexpected large change, often caused by a bug or a changed field, waits for a person to check it.
