mnemo_cards/mnemo_cards_backend/workflow_state.md
2026-01-03 16:14:27 +03:00

60 lines
3.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Workflow State: Isar to PostgreSQL Migration
## PLAN
Break down DB_PLAN.md into actionable todos and execute migration in stages:
1. Infrastructure setup (PostgreSQL, dependencies, env)
2. Create Drift schemas (all tables)
3. Create DAOs (all data access objects)
4. Refactor code (replace Isar with Drift)
5. Testing (unit + integration)
6. Deployment (Docker, migration scripts)
## NEXT_ACTIONS
1. Continue Stage 4: Refactor remaining managers and APIs
- UserManager (complex - needs model conversion)
- PackManager
- TestManager
- Other managers and API endpoints
2. Update DI injector (regenerate after all managers updated)
3. Fix remaining isar references in codebase
## ASSUMPTIONS
- Using Docker Compose for local PostgreSQL
- PostgreSQL 16-alpine image
- Development environment first, production later
- All existing Isar models have equivalent PostgreSQL tables
## PROGRESS_LOG
- [2025-01-XX] Started migration planning
- Created project_config.md and workflow_state.md
- Breaking down DB_PLAN.md into actionable todos
- ✅ Stage 1: Infrastructure setup complete (docker-compose, pubspec.yaml, .env.example)
- ✅ Stage 2: All Drift table schemas created (users, auth, packs, relations, subscriptions, payments, tests, tasks, promo_codes, discounts, statistics, telegram)
- ✅ Stage 2.6: Created main database.dart file with AppDatabase class
- ✅ Stage 2.7: Generated Drift code successfully
- ✅ Stage 3: All DAOs created and fixed (UserDao, PackDao, TestDao, PaymentDao, SubscriptionDao, TaskDao, PromoCodeDao, DiscountDao, StatisticsDao)
- ✅ All DAOs code generation successful
- ✅ Testing completed: Structure verified, all files present
- ⚠️ Some analyzer warnings remain (non-critical, code generates successfully)
- ✅ Stage 4 started: Refactor code to use Drift
- ✅ Stage 4.1: main.dart updated - replaced Isar with AppDatabase, updated initialization and shutdown (compiles)
- ✅ Stage 4.4: jwt_service.dart updated - replaced Isar refresh tokens with Drift UserDao methods (compiles, no errors)
- ✅ Stage 4.3: auth_api_v2.dart updated - added AppDatabase to constructor (matches injector config, compiles)
- 🔄 Stage 4.6: pack_manager.dart - AppDatabase added to constructor, but full conversion pending (31 isar calls, needs CardPackModel→CardPack conversion and PackDtoConverter update)
- 🔄 Stage 4.5: payment_manager.dart - AppDatabase added to constructor, but full conversion pending (34 isar calls need Isar→Drift model conversion)
- 🔄 Stage 4.2: UserManager refactoring pending (complex - needs replacement of UserModel with Drift User throughout codebase)
**Key Insight:** Слой конвертации между Isar и Drift моделями НЕ нужен. Правильный подход:
- Заменить Isar модели (UserModel) на Drift модели (User) везде в коде
- Создать extension User.toDto() который использует DAOs для получения связанных данных
- UserDto остается тем же (не зависит от БД)
## OPEN_ISSUES
- None yet
## NOTES
- **Слой конвертации НЕ нужен** - правильный подход:
1. Заменить Isar модели (UserModel) на Drift модели (User) везде в коде
2. Создать extension User.toDto() который использует DAOs для получения связанных данных
3. UserDto остается тем же (не зависит от БД)
- Это проще и чище чем поддерживать два типа моделей одновременно