1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Merge pull request #3017 from adrpac/master

Use inet column type when generating migrations under PostgreSQL
This commit is contained in:
José Valim 2014-05-07 10:08:39 +02:00
commit f611b63069
2 changed files with 21 additions and 2 deletions

View file

@ -53,8 +53,8 @@ module ActiveRecord
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
t.#{ip_column} :current_sign_in_ip
t.#{ip_column} :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
@ -68,6 +68,19 @@ module ActiveRecord
# t.datetime :locked_at
RUBY
end
def ip_column
# Padded with spaces so it aligns nicely with the rest of the columns.
"%-8s" % (inet? ? "inet" : "string")
end
def inet?
Devise.rails4? && postgresql?
end
def postgresql?
ActiveRecord::Base.connection.adapter_name.downcase == "postgresql"
end
end
end
end

View file

@ -37,6 +37,12 @@ if DEVISE_ORM == :active_record
assert_no_file "app/models/monster.rb"
assert_no_migration "db/migrate/devise_create_monsters.rb"
end
test "use string column type for ip addresses" do
run_generator %w(monster)
assert_migration "db/migrate/devise_create_monsters.rb", /t.string :current_sign_in_ip/
assert_migration "db/migrate/devise_create_monsters.rb", /t.string :last_sign_in_ip/
end
end
module RailsEngine