The personal finance app for everyone (by everyone)
Ruby
fix: change postal_code column from integer to string (#1585)
Will Wilsonad23820a2eea
diff --git a/db/migrate/20260428120000_change_postal_code_to_string_in_addresses.rb b/db/migrate/20260428120000_change_postal_code_to_string_in_addresses.rbnew file mode 100644index 0000000000..a67374b956--- /dev/null+++ b/db/migrate/20260428120000_change_postal_code_to_string_in_addresses.rb@@ -0,0 +1,9 @@+class ChangePostalCodeToStringInAddresses < ActiveRecord::Migration[7.2]+ def up+ change_column :addresses, :postal_code, :string, using: "postal_code::text"+ end++ def down+ raise ActiveRecord::IrreversibleMigration, "postal_code was changed from integer to string; alphanumeric values cannot be cast back to integer"+ end+enddiff --git a/db/schema.rb b/db/schema.rbindex 1c7ecd6939..079f83bd68 100644--- a/db/schema.rb+++ b/db/schema.rb@@ -10,7 +10,7 @@## It's strongly recommended that you check this file into your version control system.-ActiveRecord::Schema[7.2].define(version: 2026_04_12_120000) do+ActiveRecord::Schema[7.2].define(version: 2026_04_28_120000) do# These are extensions that must be enabled in order to support this databaseenable_extension "pgcrypto"enable_extension "plpgsql"@@ -116,7 +116,7 @@ ActiveRecord::Schema[7.2].define(version: 2026_04_12_120000) dot.string "locality"t.string "region"t.string "country"- t.integer "postal_code"+ t.string "postal_code"t.datetime "created_at", null: falset.datetime "updated_at", null: falset.index ["addressable_type", "addressable_id"], name: "index_addresses_on_addressable"diff --git a/test/fixtures/addresses.yml b/test/fixtures/addresses.ymlindex 0124887ec8..4d01359a60 100644--- a/test/fixtures/addresses.yml+++ b/test/fixtures/addresses.yml@@ -4,6 +4,6 @@ one:locality: Los Angelesregion: CAcountry: US- postal_code: 90001+ postal_code: "90001"addressable: oneaddressable_type: Propertydiff --git a/test/models/address_test.rb b/test/models/address_test.rbindex 47890d0400..6e23eadc70 100644--- a/test/models/address_test.rb+++ b/test/models/address_test.rb@@ -39,6 +39,12 @@ class AddressTest < ActiveSupport::TestCaseassert_equal "", address.to_send+ test "accepts alphanumeric postal codes" do+ address = addresses(:one)+ address.update!(postal_code: "SW1A 2AA")+ assert_equal "SW1A 2AA", address.reload.postal_code+ end+test "can strip extras commas and spaces" doaddress = Address.new(line1: "123 Main St ,",