Skip to content

Instantly share code, notes, and snippets.

@hkraji
Created August 14, 2025 15:23
Show Gist options
  • Select an option

  • Save hkraji/a083c02535fb5b7dd7c5e15eae63654f to your computer and use it in GitHub Desktop.

Select an option

Save hkraji/a083c02535fb5b7dd7c5e15eae63654f to your computer and use it in GitHub Desktop.
Pipeline CRM fix stru

Fix Structure SQL

When running rake db:migrate, Rails scrambles the entire db/structure.sql file, making git diffs unreadable. This command helps you manually add only the new changes while preserving the original structure.

Instructions:

  1. Before running migrations: Always backup or check the current state of db/structure.sql

  2. After running rake db:migrate:

    • DO NOT commit the scrambled structure.sql file
    • Revert db/structure.sql to its previous state: git checkout HEAD -- db/structure.sql
  3. Manual addition process:

    • Look at the migration file to understand what table/changes were added
    • Manually add the new table definition to db/structure.sql in the appropriate alphabetical location
    • Add the new migration version to the schema_migrations INSERT statement at the bottom
    • Ensure proper formatting matches the existing style
  4. Verify the changes:

    • Run git diff db/structure.sql to see only the actual changes
    • The diff should show only the new table definition and migration version
    • Commit these clean, minimal changes

This approach keeps the git history clean and makes it easy to see exactly what database changes were made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment