Skip to content

Commit

Permalink
Merge pull request #276 from shicholas/postgres_token_support
Browse files Browse the repository at this point in the history
Added json support for tokens
  • Loading branch information
booleanbetrayal committed Jul 10, 2015
2 parents d9f8e78 + 7a2fc52 commit b8254e7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions lib/generators/devise_token_auth/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,33 @@ def parse_file_for_line(filename, str)
end
match
end

def json_supported_database?
(postgres? && postgres_correct_version?) || (mysql? && mysql_correct_version?)
end

def postgres?
database_name == 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
end

def postgres_correct_version?
database_version > '9.3'
end

def mysql?
database_name == 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
end

def mysql_correct_version?
database_version > '5.7.7'
end

def database_name
ActiveRecord::Base.connection.class.name
end

def database_version
ActiveRecord::Base.connection.select_value('SELECT VERSION()')
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DeviseTokenAuthCreate<%= user_class.pluralize %> < ActiveRecord::Migration
t.string :email

## Tokens
t.text :tokens
<%= json_supported_database? ? 't.json :tokens' : 't.text :tokens' %>

t.timestamps
end
Expand Down

0 comments on commit b8254e7

Please sign in to comment.