Migration Strategy
Migration Strategy
This document outlines the migration strategies for database schema changes, including both planned migrations and completed ones.
Completed Migrations
HD Wallet Path Registry (July 2025)
Migration: Added path_registry and manufacturer_registry tables to PostgreSQL
Strategy:
- Created new tables with full constraints and triggers
- Pre-populated with Plings manufacturer registration
- Added base path allocations for generic tags
- No data migration needed (new feature)
Files:
/migrations/create_hd_wallet_path_registry.sql- See HD Wallet Schema for details
Planned Migrations
PlingsIdentifier Path Enhancement
Current State: PlingsIdentifier nodes in Neo4j without path information
Target State: Include path data for all identifiers
Migration Strategy:
- Phase 1: Add path property to new PlingsIdentifier nodes
- Phase 2: Backfill paths for existing identifiers based on creation order
- Phase 3: Make path required for all new identifiers
// Phase 2: Backfill example
MATCH (pi:PlingsIdentifier)
WHERE pi.path IS NULL
WITH pi
ORDER BY pi.created_at
WITH collect(pi) as identifiers
UNWIND range(0, size(identifiers)-1) as idx
WITH identifiers[idx] as pi, idx
SET pi.path = '1.1.' + toString(idx + 1)
RETURN count(pi) as updated
Organization-Specific Paths
Future Enhancement: Allow organizations to have dedicated path ranges
Migration Plan:
- Update
path_registryto support organization-specific allocations - Add RLS policies for organization isolation
- Migrate existing organization identifiers to new paths
Migration Best Practices
For PostgreSQL
- Always use transactions for schema changes
- Create indexes CONCURRENTLY in production
- Test migrations on a copy of production data
- Include rollback scripts with every migration
For Neo4j
- Use APOC procedures for bulk operations
- Create indexes before bulk imports
- Monitor query performance during migration
- Backup before major schema changes
Version Control
All migrations should be:
- Named with timestamp prefix (e.g.,
2025_07_11_add_path_registry.sql) - Include UP and DOWN migrations
- Document the business reason
- Reference related issues/PRs
Status: Updated July 2025 with HD wallet migration