Repository navigation
feat(migration): Session & Secret Data Migration (#875) - #879
Merged
Merged
Conversation
Implements migration scripts for user attribution and ownership: **Session User Attribution (migrate_sessions_user_attribution.py):** - Adds owner_id to existing sessions (inferred from first message sender) - Adds created_at timestamps if missing - Registers ownership in Redis indices (user/org/team) - Generates rollback SQL **Secret Ownership (migrate_secrets_ownership.py):** - Adds owner_id to secrets (inferred from creation metadata) - Adds scope field (default: 'user') - Ensures encryption on all secret values - Registers ownership in Redis indices **Orphaned Session Cleanup (cleanup_orphaned_sessions.py):** - Identifies sessions with no messages AND no activities - Removes sessions with corrupt metadata - Minimum age check (default: 7 days) - Lists deleted sessions **Activity Backfill (backfill_activity_user_ids.py):** - Adds user_id to chat messages (from metadata or session owner) - Links activities to users - Batch processing for large message volumes **Migration Validation (validate_migration.py):** - Verifies all sessions have owner_id - Verifies all secrets have owner_id and scope - Checks encryption status - Reports orphaned entities - Generates detailed validation report All scripts support --dry-run mode, detailed logging, rollback generation, and are idempotent. Includes comprehensive README with migration workflow. Part of #608 - User-Centric Session Tracking (Phase 7) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
19 tasks
42 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #875 - Migration scripts for session and secret data.
Part of #608 - User-Centric Session Tracking (Phase 7)
Changes
Migration Scripts Created
migrate_sessions_user_attribution.py
owner_idto 74 existing sessionscreated_attimestamps if missingmigrate_secrets_ownership.py
owner_idandscopeto secretscleanup_orphaned_sessions.py
backfill_activity_user_ids.py
user_idto existing chat messagesvalidate_migration.py
Features
All scripts include:
Documentation
Testing
Dry-Run Tests
# All scripts tested in dry-run mode python3 migrate_sessions_user_attribution.py --dry-run python3 migrate_secrets_ownership.py --dry-run python3 backfill_activity_user_ids.py --dry-run python3 cleanup_orphaned_sessions.py --dry-run python3 validate_migration.pyCode Quality
Production Execution Plan
Prerequisites:
redis-cli BGSAVEExecution Order:
migrate_sessions_user_attribution.py(add owners to 74 sessions)migrate_secrets_ownership.py(add owners to secrets)backfill_activity_user_ids.py(link messages/activities to users)validate_migration.py(verify success)cleanup_orphaned_sessions.py(remove 45 empty sessions)validate_migration.py --verboseExpected Results:
Rollback Plan
Each script generates rollback documentation:
/tmp/session_migration_rollback.sql/tmp/secrets_migration_rollback.sql/tmp/deleted_sessions.txtManual reversal required (Redis operations documented in rollback files).
Acceptance Criteria
Dependencies
None - scripts are standalone and can run independently.
Related Issues
Closes #875
🤖 Generated with Claude Code