Skip to content

armgit / sure

Public Imported from GitHub
0

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.rb
new file mode 100644
index 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
+end
diff --git a/db/schema.rb b/db/schema.rb
index 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 database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@@ -116,7 +116,7 @@ ActiveRecord::Schema[7.2].define(version: 2026_04_12_120000) do
t.string "locality"
t.string "region"
t.string "country"
- t.integer "postal_code"
+ t.string "postal_code"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["addressable_type", "addressable_id"], name: "index_addresses_on_addressable"
diff --git a/test/fixtures/addresses.yml b/test/fixtures/addresses.yml
index 0124887ec8..4d01359a60 100644
--- a/test/fixtures/addresses.yml
+++ b/test/fixtures/addresses.yml
@@ -4,6 +4,6 @@ one:
locality: Los Angeles
region: CA
country: US
- postal_code: 90001
+ postal_code: "90001"
addressable: one
addressable_type: Property
diff --git a/test/models/address_test.rb b/test/models/address_test.rb
index 47890d0400..6e23eadc70 100644
--- a/test/models/address_test.rb
+++ b/test/models/address_test.rb
@@ -39,6 +39,12 @@ class AddressTest < ActiveSupport::TestCase
assert_equal "", address.to_s
end
+ 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" do
address = Address.new(
line1: "123 Main St ,",