{"record":{"id":"47b490c63f44a9fc","repo":"we-promise/sure","slug":"postal-code-was-changed-from-integer-to-string-al","errorCode":null,"errorMessage":"postal_code was changed from integer to string; alphanumeric values cannot be cast back to integer","messagePattern":"postal_code was changed from integer to string; alphanumeric values cannot be cast back to integer","errorType":"exception","errorClass":"ActiveRecord::IrreversibleMigration","httpStatus":null,"severity":"error","filePath":"db/migrate/20260428120000_change_postal_code_to_string_in_addresses.rb","lineNumber":7,"sourceCode":"class ChangePostalCodeToStringInAddresses < ActiveRecord::Migration[7.2]\n  def up\n    change_column :addresses, :postal_code, :string, using: \"postal_code::text\"\n  end\n\n  def down\n    raise ActiveRecord::IrreversibleMigration, \"postal_code was changed from integer to string; alphanumeric values cannot be cast back to integer\"\n  end\nend\n","sourceCodeStart":1,"sourceCodeEnd":10,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/db/migrate/20260428120000_change_postal_code_to_string_in_addresses.rb#L1-L10","documentation":"Raised as ActiveRecord::IrreversibleMigration by the down method of ChangePostalCodeToStringInAddresses (db/migrate/20260428120000_change_postal_code_to_string_in_addresses.rb:7). The up direction permanently converts addresses.postal_code from integer to string (using postal_code::text). Once any row has stored an alphanumeric postal code (e.g. Canadian 'K1A 0B1' or UK 'SW1A 1AA'), casting back to integer would fail or corrupt data, so the rollback is explicitly forbidden rather than attempted.","triggerScenarios":"Running rails db:rollback, db:migrate:down VERSION=20260428120000, or any tooling that rewinds past this migration after it has run — regardless of whether alphanumeric values actually exist; the down unconditionally raises.","commonSituations":"Developers habitually rolling back to re-run a neighboring migration and stepping one step too far; schema.rb vs migration version drift; attempting db:rollback on production while debugging.","solutions":["Don't roll back — write a new forward migration that reverses the column type if you truly need integers.","If you only meant to re-run a different migration, target it explicitly with db:migrate:down VERSION=<that one> instead of db:rollback stepping.","On dev machines where the data is disposable: rails db:drop db:create db:migrate to rebuild from scratch.","If integer postal codes are genuinely required, first check no row matches /[^0-9]/ in postal_code, then add a new change_column migration."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"abort 'postal_code rollback is forbidden' if ActiveRecord::Base.connection.migration_context.get_all_versions.include?(20260428120000.to_s)","typeGuard":null,"tryCatchPattern":"begin\n  rails_rollback\nrescue ActiveRecord::IrreversibleMigration\n  # expected for int->string data migrations; write a new forward migration instead\nend","preventionTips":["Prefer reversible pairs (revert-safe up/down or change with reversible blocks) when writing type changes.","Target specific versions with db:migrate:down VERSION= instead of stepping db:rollback.","Treat IrreversibleMigration in down as documentation: the data transform was lossy by design."],"tags":["rails","migration","irreversible","schema-change","postal-code"],"backgroundTag":"irreversible-migration","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}