mirror of
https://github.com/we-promise/sure.git
synced 2026-05-07 12:54:04 +00:00
fix: change postal_code column from integer to string (#1585)
* fix: change postal_code column from integer to string Allows non-numeric postal codes such as UK format (e.g. SW1A 2AA). The integer column was silently dropping any alphanumeric input. The migration is marked irreversible — once alphanumeric postal codes exist, they cannot be safely cast back to integer. * fix: update schema.rb, quote fixture postal_code, and add alphanumeric test * fix: use conventional migration timestamp
This commit is contained in:
@@ -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
|
||||
4
db/schema.rb
generated
4
db/schema.rb
generated
@@ -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"
|
||||
|
||||
2
test/fixtures/addresses.yml
vendored
2
test/fixtures/addresses.yml
vendored
@@ -4,6 +4,6 @@ one:
|
||||
locality: Los Angeles
|
||||
region: CA
|
||||
country: US
|
||||
postal_code: 90001
|
||||
postal_code: "90001"
|
||||
addressable: one
|
||||
addressable_type: Property
|
||||
|
||||
@@ -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 ,",
|
||||
|
||||
Reference in New Issue
Block a user