Skip to content

Commit

Permalink
Added json support for tokens
Browse files Browse the repository at this point in the history
In the installation generator script, the migration template checks to
see if the app is using postgres by seeing what sub-class of
``ActiveRecord::ConnectionAdapter`` the app is using. If it is postgres, or mysql with the correct version, the app will use a token column instead of a text one

Postgres has JSON types as of 9.3
Mysql has JSON types as of 5.7.7
http://mysqlserverteam.com/json-labs-release-native-json-data-type-and-binary-format/

teeny refactoring
  • Loading branch information
Nicholas Shook committed Jul 3, 2015
1 parent 62f3d13 commit 7a2fc52
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 7a2fc52

Please sign in to comment.