Before applying database migrations, systematically validate existing data and check for potential conflicts with current schema constraints. This prevents migration failures and ensures backward compatibility.

When modifying database schema or constants that affect database state:

  1. Validate existing data - Check current data integrity and identify potential constraint violations
  2. Check for naming conflicts - Ensure new constraints don’t conflict with existing constraint names
  3. Plan data transformation - Create a step-by-step approach for handling existing data
  4. Create migration scripts - Generate proper migrations for any changes that affect database state

Example approach for constraint modifications:

# 1. Select all, validate all names per user and update db
# 2. Create new table with constraint that does not conflict with existing constraint  
# 3. Insert into it
# 4. Delete old table

This systematic validation prevents issues like foreign key conflicts during table recreation and ensures that changes to constants (like DEFAULT_FOLDER_NAME) don’t break existing database functions that depend on those values.