Skip to content

feat: added column type change migration#3208

Open
dankgarlic1 wants to merge 8 commits intofrappe:developfrom
dankgarlic1:fix/migrate-ticket-naming
Open

feat: added column type change migration#3208
dankgarlic1 wants to merge 8 commits intofrappe:developfrom
dankgarlic1:fix/migrate-ticket-naming

Conversation

@dankgarlic1
Copy link
Copy Markdown
Contributor

@dankgarlic1 dankgarlic1 commented Apr 8, 2026

Moving the ticket naming system from simple auto-incrementing integers to a structured, year-based format: HD-TKT-YYYY-#####.

The Architectural Approach
I split this into a two-phase migration to ensure the database stays stable:

Phase 1: Schema Alignment
The first patch converts the name column from BigInt to VarChar. Since we are moving from numbers to strings, the "pipe" had to be widened first before we could push any new data through.

Phase 2: Data Transformation & Seeding
The second patch handles the heavy lifting:

Backfilling: It iterates through legacy tickets and renames them to the new format based on their original creation year.

Series Recovery: It calculates the highest existing ID for each year to seed the tabSeries table. This ensures the next ticket created in the UI follows the sequence perfectly without crashing.

Performance Note
For the series seeding, the logic looks a bit less readable and ugly, but I thought if I did it in Python the OOM could happen. Not sure what kind of volumes the Helpdesk users have, so I went with SQL to keep the RAM safe by letting the DB handle the grouping and max-ID calculations.

fixes #3207

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 42.85714% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.13%. Comparing base (11c8e28) to head (29b6e43).
⚠️ Report is 33 commits behind head on develop.

Files with missing lines Patch % Lines
helpdesk/search_sqlite.py 0.00% 3 Missing ⚠️
helpdesk/helpdesk/doctype/hd_ticket/api.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3208      +/-   ##
===========================================
- Coverage    57.17%   57.13%   -0.05%     
===========================================
  Files          128      128              
  Lines         6167     6170       +3     
===========================================
- Hits          3526     3525       -1     
- Misses        2641     2645       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dankgarlic1 dankgarlic1 force-pushed the fix/migrate-ticket-naming branch from 96c32e6 to e4404e9 Compare April 15, 2026 11:12
@dankgarlic1 dankgarlic1 marked this pull request as ready for review April 15, 2026 15:39
Comment on lines +36 to +46
yearly_max_data = frappe.db.sql(
"""
SELECT
SUBSTRING(name, 8, 4) as year,
MAX(CAST(RIGHT(name, 5) AS UNSIGNED)) as max_id
FROM `tabHD Ticket`
WHERE name LIKE 'HD-TKT-____-_____'
GROUP BY year
""",
as_dict=True,
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The series seeding logic looks a bit less readable and ugly, but I thought if I did it in Python the OOM could happen. Not sure what kind of volumes the Helpdesk users have, so I went with SQL to keep the RAM safe

@dankgarlic1
Copy link
Copy Markdown
Contributor Author

@RitvikSardana please take a look at this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate naming series of HD Ticket from auto-increment to custom naming series

1 participant