Skip to content

feat: Migrate gift collection from slug to ID#225

Merged
danoctua merged 8 commits intodevfrom
feat/migrate-gift-collection-to-id
Mar 4, 2026
Merged

feat: Migrate gift collection from slug to ID#225
danoctua merged 8 commits intodevfrom
feat/migrate-gift-collection-to-id

Conversation

@danoctua
Copy link
Collaborator

@danoctua danoctua commented Mar 4, 2026

Migrate Gift Collection Indexing from Slug to Telegram Internal ID

Description

Migrate Gift Collection and Gift Unique indexing from slug-based primary keys to integer IDs (Telegram gift IDs). This is Phase 0 of the gift indexer rewrite — the schema and codebase are updated to support integer-based lookups while the full indexer rewrite is planned separately.

Checklist

Before submitting your pull request, please ensure the following:

  • I have read the contributing guidelines.
  • I ran all tests and they passed successfully.
  • I added/updated documentation (if applicable).
  • I reviewed my own code and followed the project's code style.
  • I included relevant details in the PR description or commit messages.

Changes

  • Database models: Replaced GiftCollection.slug (VARCHAR PK) with GiftCollection.id (BigInteger PK). Added options (JSONB) and blockchain_address fields. Replaced collection_slug FK with collection_id FK in GiftUnique
  • Alembic migration: Three-phase migration — schema changes, data migration from ID-to-name JSON mapping, and schema cleanup. Supports upgrade and downgrade.
  • DTOs & Services: Updated GiftCollectionDTO, GiftUniqueDTO, GiftFilterDTO, GiftCollectionService, and GiftUniqueService to use integer IDs.
  • Actions & API routes: Updated GiftUniqueAction, TelegramChatGiftCollectionAction, and API endpoint from /gifts/{collection_slug} to /gifts/{collection_id}.
  • Chat eligibility logic: Fixed find_relevant_gift_items to compare collection_id instead of collection_slug.
  • Indexer (temporarily disabled): Added early returns to indexer tasks, commented out Celery Beat schedule and slug-dependent indexer methods pending future rewrite.

How Has This Been Tested?

  • All unit tests pass via make test.
  • Verified migration correctness by seeding 109 dummy collections (with gift_unique items and telegram_chat_gift_collection rules using collection_slug) and validating all three tables were correctly mapped to integer IDs after running the migration.
  • Verified both alembic upgrade and alembic downgrade work correctly.

Screenshots (if applicable)

N/A — backend-only changes.

Additional Notes

  • The gift indexer is intentionally disabled in this PR. Methods that relied on the old slug schema are commented out and will be rewritten in a follow-up.

Thank you for contributing! 🎉

@danoctua danoctua self-assigned this Mar 4, 2026
@danoctua danoctua added the enhancement New feature or request label Mar 4, 2026
- Update GiftCollection model: replace slug PK with integer id, add options (JSONB) and blockchain_address fields
- Update GiftUnique model: replace collection_slug FK with collection_id FK
- Update TelegramChatGiftCollection model: replace collection_slug FK with collection_id FK
- Create Alembic migration with schema changes, data migration from JSON mapping, and cleanup
- Refactor DTOs, services, actions, and API routes to use integer IDs
- Update chat eligibility logic (find_relevant_gift_items) to use collection_id
- Temporarily disable gift indexer tasks and comment out slug-dependent indexer methods
@danoctua danoctua force-pushed the feat/migrate-gift-collection-to-id branch from 49ad88f to 49387de Compare March 4, 2026 15:24
@danoctua danoctua merged commit b3bd5ef into dev Mar 4, 2026
2 checks passed
@danoctua danoctua deleted the feat/migrate-gift-collection-to-id branch March 4, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant