iqvoc 4.12.0 → 4.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +5 -0
- data/Gemfile +13 -5
- data/Gemfile.lock +94 -77
- data/README.md +11 -2
- data/app/controllers/dashboard_controller.rb +5 -1
- data/app/controllers/user_sessions_controller.rb +1 -1
- data/app/helpers/dashboard_helper.rb +3 -3
- data/app/views/concepts/new.html.erb +2 -1
- data/app/views/concepts/sidebars/_singular.html.erb +11 -7
- data/app/views/dashboard/_table.html.erb +1 -1
- data/app/views/dashboard/glance.html.erb +1 -1
- data/app/views/search_results/_sidebar.html.erb +7 -2
- data/config/database.template.yml +3 -3
- data/config/database.yml +13 -18
- data/config/database.yml.mysql +7 -7
- data/config/database.yml.postgresql +6 -5
- data/config/initializers/mysql_column_limit.rb +14 -0
- data/config/locales/activerecord.de.yml +3 -0
- data/config/locales/activerecord.en.yml +3 -0
- data/db/migrate/20170626074649_add_note_annotations_index.rb +5 -1
- data/db/migrate/20180430163647_utf8mb4_conversion.rb +122 -0
- data/db/migrate/20180525135715_fix_note_annotations_index.rb +6 -0
- data/db/migrate/20190403133600_change_collation.rb +39 -0
- data/db/schema.rb +63 -64
- data/db/seeds.rb +4 -4
- data/iqvoc.gemspec +5 -5
- data/lib/iqvoc/version.rb +1 -1
- data/public/export/192518761412858257538294365837284445543.nt +28 -0
- data/public/export/222655544999381011796369687711131211507.nt +28 -0
- data/public/export/28094.nt +28 -0
- data/public/export/317743731342877661346578631544287380698.nt +28 -0
- data/public/export/59040722386799844495905115730928244680.nt +28 -0
- data/public/export/65316.nt +28 -0
- data/public/uploads/import/0090c45f8a575ba948e9e1f9346e8bd8.nt +259 -0
- data/public/uploads/import/10b55d476cc7905edd5bf2ea3339266f.nt +259 -0
- data/public/uploads/import/29f4bdb935b9ba14344c38808e2fc172.nt +259 -0
- data/public/uploads/import/5686fe12a4157c537fe4f83de393e436.nt +259 -0
- data/public/uploads/import/a46e5777d14959f0a264fc27170a9aca.nt +259 -0
- data/public/uploads/import/f47c4c34a7652d03188ef8815667a546.nt +259 -0
- data/public/uploads/tmp/1565090696-8977-0904/hobbies.nt +259 -0
- data/public/uploads/tmp/1565092660-26284-7315/hobbies.nt +259 -0
- data/public/uploads/tmp/1565092837-26720-3638/hobbies.nt +259 -0
- data/public/uploads/tmp/1565093111-27724-9556/hobbies.nt +259 -0
- data/public/uploads/tmp/1565093198-28993-6950/hobbies.nt +259 -0
- data/public/uploads/tmp/1565093353-29520-6028/hobbies.nt +259 -0
- data/test/integration/dashboard_test.rb +2 -2
- data/test/integration/user_management_test.rb +2 -2
- metadata +37 -16
@@ -31,6 +31,8 @@ class DashboardController < ApplicationController
|
|
31
31
|
order_params = order_params.gsub('value', 'labels.value').gsub('locking_user', 'users.surname').gsub('follow_up', 'concepts.follow_up').gsub('updated_at', 'concepts.updated_at')
|
32
32
|
|
33
33
|
concepts = concepts.includes(:pref_labels, :locking_user).references(:pref_labels).references(:locking_user).order(order_params)
|
34
|
+
else
|
35
|
+
concepts = concepts.includes(:pref_labels).order('labels.value')
|
34
36
|
end
|
35
37
|
|
36
38
|
@items = Kaminari.paginate_array(concepts).page(params[:page])
|
@@ -52,6 +54,8 @@ class DashboardController < ApplicationController
|
|
52
54
|
order_params = order_params.gsub('value', 'labels.value').gsub('locking_user', 'users.surname').gsub('updated_at', 'concepts.updated_at')
|
53
55
|
|
54
56
|
collections = collections.includes(:pref_labels, :locking_user).references(:pref_labels).references(:locking_user).order(order_params)
|
57
|
+
else
|
58
|
+
collections = collections.includes(:pref_labels).order('labels.value')
|
55
59
|
end
|
56
60
|
|
57
61
|
@items = Kaminari.paginate_array(collections).page(params[:page])
|
@@ -65,7 +69,7 @@ class DashboardController < ApplicationController
|
|
65
69
|
object = objects.send(params[:published] == "1" ? 'published' : 'unpublished').first
|
66
70
|
|
67
71
|
@title = object.to_s
|
68
|
-
@editorial_notes = Note::SKOS::EditorialNote
|
72
|
+
@editorial_notes = object.notes_for_class(Note::SKOS::EditorialNote)
|
69
73
|
|
70
74
|
@path = send(object.class_path, id: object, published: params[:published])
|
71
75
|
|
@@ -26,7 +26,7 @@ class UserSessionsController < ApplicationController
|
|
26
26
|
def create
|
27
27
|
authorize! :create, UserSession
|
28
28
|
|
29
|
-
@user_session = UserSession.new(user_session_params)
|
29
|
+
@user_session = UserSession.new(user_session_params.to_h)
|
30
30
|
if @user_session.save
|
31
31
|
@current_ability = nil
|
32
32
|
flash[:success] = I18n.t('txt.controllers.user_sessions.login_success')
|
@@ -18,9 +18,9 @@ module DashboardHelper
|
|
18
18
|
def sorting_controls_for(name)
|
19
19
|
content_tag :div, class: 'sorting-controls' do
|
20
20
|
link_to(icon('arrow-circle-o-up', 'sorting-arrow'),
|
21
|
-
params.merge(sort: "#{name} ASC"
|
22
|
-
|
23
|
-
params.merge(sort: "#{name} DESC"
|
21
|
+
params.merge({ sort: "#{name} ASC" })) +
|
22
|
+
link_to(icon('arrow-circle-o-down', 'sorting-arrow'),
|
23
|
+
params.merge({ sort: "#{name} DESC" }))
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
<%= page_header :title => t("txt.views.concepts.new", :concept_class_name => Iqvoc::Concept.base_class.model_name.human(:count => 1)) %>
|
2
2
|
|
3
3
|
<%= error_messages_for @concept %>
|
4
|
-
<%= render 'concepts/form', :concept => @concept %>
|
4
|
+
<%= render 'concepts/form', :concept => @concept %>
|
5
|
+
<%= render 'concepts/sidebars/singular' %>
|
@@ -1,13 +1,17 @@
|
|
1
|
-
<%- published_param = concept.published? ? nil : "0" -%>
|
1
|
+
<%- published_param = concept.published? ? nil : "0" if defined?(concept) -%>
|
2
2
|
|
3
3
|
<%= sidebar do %>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
<% if defined?(concept) %>
|
5
|
+
<%= sidebar_header t('txt.common.representations') %>
|
6
|
+
<%= sidebar_item :icon => 'link', :text => 'HTML', :path => concept_path(:id => concept, :format => :html, :published => published_param) %>
|
7
|
+
<%= sidebar_item :icon => 'link', :text => 'RDF/XML', :path => concept_path(:id => concept, :format => :rdf, :published => published_param), :id => 'rdf_link_xml' %>
|
8
|
+
<%= sidebar_item :icon => 'link', :text => 'RDF/Turtle', :path => concept_path(:id => concept, :format => :ttl, :published => published_param), :id => 'rdf_link_ttl' %>
|
9
|
+
<%= sidebar_item :icon => 'link', :text => 'RDF/NTriples', :path => concept_path(:id => concept, :format => :nt, :published => published_param), :id => 'rdf_link_nt' %>
|
10
|
+
<% end %>
|
9
11
|
<%= sidebar_header 'Links' if can?(:create, Iqvoc::Concept.base_class) %>
|
10
|
-
|
12
|
+
<% if defined?(concept) %>
|
13
|
+
<%= sidebar_item :icon => 'link', :text => t('txt.models.concept.uri'), :path => rdf_url(concept.origin, :format => nil, :published => published_param, :lang => nil) %>
|
14
|
+
<% end %>
|
11
15
|
<%= sidebar_item :icon => :edit, :text => t('txt.views.concepts.new', :concept_class_name => Iqvoc::Concept.base_class.model_name.human), :path => new_concept_path,
|
12
16
|
:perms => [:create, Iqvoc::Concept.base_class], :active => params[:action] == 'new' %>
|
13
17
|
<% end %>
|
@@ -22,7 +22,7 @@
|
|
22
22
|
<td>
|
23
23
|
<%= render item.class.edit_link_partial_name, :item => item %>
|
24
24
|
</td>
|
25
|
-
<
|
25
|
+
<td><a href="<%= dashboard_glance_path(type: item.class, origin: item.origin, published: item.published? ? 1 : 0) %>" class="dashboard-glance-link"><i class="fa fa-search-plus"></i></a</td>
|
26
26
|
<td class="text-nowrap"><%= item.locking_user.blank? ? "" : item.locking_user.name %></td>
|
27
27
|
<% unless item.class == Iqvoc::Collection.base_class %>
|
28
28
|
<td class="<%= 'dashboard-activated-follow-up-column' if item.follow_up.present? %>"><%= l(item.follow_up) if item.follow_up.present? %></td>
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<ul class="label-list">
|
19
19
|
<% @editorial_notes.each do |note| %><!--
|
20
20
|
--><li class="label-list-item">
|
21
|
-
<span class="label-list-item-value"><%=
|
21
|
+
<span class="label-list-item-value"><%= note.value %></span>
|
22
22
|
</li><!--
|
23
23
|
--><% end %>
|
24
24
|
</ul>
|
@@ -1,8 +1,13 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
<%= sidebar do %>
|
2
|
+
<% if results %>
|
3
3
|
<%= sidebar_header t('txt.common.representations') %>
|
4
4
|
<%= sidebar_item :icon => 'link', :text => 'RDF/XML', :path => rdf_search_path({:lang => nil, :page => results.current_page, :format => :rdf}.merge(request.query_parameters)), :id => 'rdf_link_xml' %>
|
5
5
|
<%= sidebar_item :icon => 'link', :text => 'RDF/Turtle', :path => rdf_search_path({:lang => nil, :page => @results.current_page, :format => :ttl}.merge(request.query_parameters)), :id => 'rdf_link_ttl' %>
|
6
6
|
<%= sidebar_item :icon => 'link', :text => 'RDF/NTriples', :path => rdf_search_path({:lang => nil, :page => @results.current_page, :format => :nt}.merge(request.query_parameters)), :id => 'rdf_link_nt' %>
|
7
7
|
<% end %>
|
8
|
+
|
9
|
+
<%= sidebar_header 'Links' if can?(:create, Iqvoc::Concept.base_class) %>
|
10
|
+
<% (Iqvoc.first_level_classes - [Collection::SKOS::Unordered]).each do |klass| %>
|
11
|
+
<%= sidebar_item { render(klass.new_link_partial_name) } %>
|
12
|
+
<% end %>
|
8
13
|
<% end %>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
development:
|
2
2
|
adapter: mysql2
|
3
|
-
encoding:
|
3
|
+
encoding: utf8mb4
|
4
4
|
reconnect: false
|
5
5
|
database: iqvoc_development
|
6
6
|
pool: 5
|
@@ -10,7 +10,7 @@ development:
|
|
10
10
|
|
11
11
|
test:
|
12
12
|
adapter: mysql2
|
13
|
-
encoding:
|
13
|
+
encoding: utf8mb4
|
14
14
|
reconnect: false
|
15
15
|
database: iqvoc_test
|
16
16
|
pool: 5
|
@@ -20,7 +20,7 @@ test:
|
|
20
20
|
|
21
21
|
production:
|
22
22
|
adapter: mysql2
|
23
|
-
encoding:
|
23
|
+
encoding: utf8mb4
|
24
24
|
reconnect: false
|
25
25
|
database: iqvoc_production
|
26
26
|
pool: 5
|
data/config/database.yml
CHANGED
@@ -1,29 +1,24 @@
|
|
1
1
|
development:
|
2
|
-
adapter:
|
3
|
-
encoding:
|
4
|
-
reconnect: false
|
2
|
+
adapter: postgresql
|
3
|
+
encoding: unicode
|
5
4
|
database: iqvoc_development
|
6
5
|
pool: 5
|
7
|
-
username:
|
6
|
+
username: mjansing
|
8
7
|
password:
|
9
|
-
host: 127.0.0.1
|
10
8
|
|
11
9
|
test:
|
12
|
-
adapter:
|
13
|
-
encoding:
|
14
|
-
reconnect: false
|
10
|
+
adapter: postgresql
|
11
|
+
encoding: unicode
|
15
12
|
database: iqvoc_test
|
16
13
|
pool: 5
|
17
|
-
username:
|
14
|
+
username: mjansing
|
18
15
|
password:
|
19
|
-
host: 127.0.0.1
|
20
16
|
|
21
17
|
production:
|
22
|
-
adapter:
|
23
|
-
encoding:
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
host: 127.0.0.1
|
18
|
+
adapter: <%= ENV['DB_ADAPTER'] ||= 'postgresql' %>
|
19
|
+
encoding: unicode
|
20
|
+
database: <%= ENV["DB_NAME"] %>
|
21
|
+
pool: 20
|
22
|
+
username: <%= ENV["DB_USER"] %>
|
23
|
+
password: <%= ENV["DB_PW"] %>
|
24
|
+
host: <%= ENV["DB_HOST"] %>
|
data/config/database.yml.mysql
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
development:
|
2
2
|
adapter: mysql2
|
3
|
-
encoding:
|
3
|
+
encoding: utf8mb4
|
4
4
|
reconnect: false
|
5
5
|
database: iqvoc_development
|
6
6
|
pool: 5
|
@@ -10,7 +10,7 @@ development:
|
|
10
10
|
|
11
11
|
test:
|
12
12
|
adapter: mysql2
|
13
|
-
encoding:
|
13
|
+
encoding: utf8mb4
|
14
14
|
reconnect: false
|
15
15
|
database: iqvoc_test
|
16
16
|
pool: 5
|
@@ -20,10 +20,10 @@ test:
|
|
20
20
|
|
21
21
|
production:
|
22
22
|
adapter: mysql2
|
23
|
-
encoding:
|
23
|
+
encoding: utf8mb4
|
24
24
|
reconnect: false
|
25
|
-
database:
|
25
|
+
database: <%= ENV["DB_NAME"] %>
|
26
26
|
pool: 5
|
27
|
-
username:
|
28
|
-
password:
|
29
|
-
host:
|
27
|
+
username: <%= ENV["DB_USER"] %>
|
28
|
+
password: <%= ENV["DB_PW"] %>
|
29
|
+
host: <%= ENV["DB_HOST"] %>
|
@@ -15,9 +15,10 @@ test:
|
|
15
15
|
password:
|
16
16
|
|
17
17
|
production:
|
18
|
-
adapter: postgresql
|
18
|
+
adapter: <%= ENV['DB_ADAPTER'] ||= 'postgresql' %>
|
19
19
|
encoding: unicode
|
20
|
-
database:
|
21
|
-
pool:
|
22
|
-
username:
|
23
|
-
password:
|
20
|
+
database: <%= ENV["DB_NAME"] %>
|
21
|
+
pool: 20
|
22
|
+
username: <%= ENV["DB_USER"] %>
|
23
|
+
password: <%= ENV["DB_PW"] %>
|
24
|
+
host: <%= ENV["DB_HOST"] %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'active_record/connection_adapters/abstract_mysql_adapter'
|
2
|
+
|
3
|
+
# Hack to set max varchar column size to 191 instead of 255.
|
4
|
+
# This is necessary to use mysql's utf8mb4 encoding and use
|
5
|
+
# full unicode support
|
6
|
+
module ActiveRecord
|
7
|
+
module ConnectionAdapters
|
8
|
+
class AbstractMysqlAdapter
|
9
|
+
if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
|
10
|
+
NATIVE_DATABASE_TYPES[:string] = { :name => "varchar", :limit => 191 }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
class AddNoteAnnotationsIndex < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
|
3
|
+
# causes https://github.com/innoq/iqvoc/issues/389
|
4
|
+
# outcommented as fix because we either could have had a custom index name
|
5
|
+
# or migrated to utf8mb4 to create the index afterwards
|
6
|
+
# we have chosen utf8mb4 since that also fixes utf8 encoding problems in mysql and avoids customized solutions per database
|
7
|
+
# add_index :note_annotations, :value
|
4
8
|
end
|
5
9
|
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
class Utf8mb4Conversion < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def up
|
4
|
+
if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
|
5
|
+
change_column :collection_members, :type, :string, limit: 191
|
6
|
+
change_column :concept_relations, :type, :string, limit: 191
|
7
|
+
change_column :concepts, :type, :string, limit: 191
|
8
|
+
|
9
|
+
change_column :configuration_settings, :key, :string, limit: 191
|
10
|
+
change_column :configuration_settings, :value, :string, limit: 191
|
11
|
+
|
12
|
+
change_column :delayed_jobs, :locked_by, :string, limit: 191
|
13
|
+
change_column :delayed_jobs, :queue, :string, limit: 191
|
14
|
+
change_column :delayed_jobs, :error_message, :string, limit: 191
|
15
|
+
change_column :delayed_jobs, :delayed_reference_type, :string, limit: 191
|
16
|
+
change_column :delayed_jobs, :delayed_global_reference_id, :string, limit: 191
|
17
|
+
|
18
|
+
change_column :exports, :token, :string, limit: 191
|
19
|
+
change_column :exports, :default_namespace, :string, limit: 191
|
20
|
+
|
21
|
+
change_column :imports, :import_file, :string, limit: 191
|
22
|
+
change_column :imports, :default_namespace, :string, limit: 191
|
23
|
+
|
24
|
+
change_column :labelings, :type, :string, limit: 191
|
25
|
+
|
26
|
+
change_column :labels, :type, :string, limit: 191
|
27
|
+
change_column :labels, :language, :string, limit: 191
|
28
|
+
|
29
|
+
change_column :matches, :type, :string, limit: 191
|
30
|
+
change_column :matches, :value, :string, limit: 191
|
31
|
+
|
32
|
+
change_column :note_annotations, :value, :string, limit: 191
|
33
|
+
change_column :note_annotations, :language, :string, limit: 191
|
34
|
+
|
35
|
+
change_column :notes, :owner_type, :string, limit: 191
|
36
|
+
|
37
|
+
change_column :schema_migrations, :version, :string, limit: 191
|
38
|
+
|
39
|
+
change_column :users, :forename, :string, limit: 191
|
40
|
+
change_column :users, :surname, :string, limit: 191
|
41
|
+
change_column :users, :email, :string, limit: 191
|
42
|
+
change_column :users, :crypted_password, :string, limit: 191
|
43
|
+
change_column :users, :password_salt, :string, limit: 191
|
44
|
+
change_column :users, :persistence_token, :string, limit: 191
|
45
|
+
change_column :users, :perishable_token, :string, limit: 191
|
46
|
+
change_column :users, :role, :string, limit: 191
|
47
|
+
change_column :users, :telephone_number, :string, limit: 191
|
48
|
+
change_column :users, :type, :string, limit: 191
|
49
|
+
|
50
|
+
change_database_encoding('utf8mb4', 'utf8mb4_general_ci')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def down
|
55
|
+
if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
|
56
|
+
change_database_encoding('utf8', 'utf8_general_ci')
|
57
|
+
|
58
|
+
change_column :collection_members, :type, :string, limit: 255
|
59
|
+
change_column :concept_relations, :type, :string, limit: 255
|
60
|
+
change_column :concepts, :type, :string, limit: 255
|
61
|
+
|
62
|
+
change_column :configuration_settings, :key, :string, limit: 255
|
63
|
+
change_column :configuration_settings, :value, :string, limit: 255
|
64
|
+
|
65
|
+
change_column :delayed_jobs, :locked_by, :string, limit: 255
|
66
|
+
change_column :delayed_jobs, :queue, :string, limit: 255
|
67
|
+
change_column :delayed_jobs, :error_message, :string, limit: 255
|
68
|
+
change_column :delayed_jobs, :delayed_reference_type, :string, limit: 255
|
69
|
+
change_column :delayed_jobs, :delayed_global_reference_id, :string, limit: 255
|
70
|
+
|
71
|
+
change_column :exports, :token, :string, limit: 255
|
72
|
+
change_column :exports, :default_namespace, :string, limit: 255
|
73
|
+
|
74
|
+
change_column :imports, :import_file, :string, limit: 255
|
75
|
+
change_column :imports, :default_namespace, :string, limit: 255
|
76
|
+
|
77
|
+
change_column :labelings, :type, :string, limit: 255
|
78
|
+
|
79
|
+
change_column :labels, :type, :string, limit: 255
|
80
|
+
change_column :labels, :language, :string, limit: 255
|
81
|
+
|
82
|
+
change_column :matches, :type, :string, limit: 255
|
83
|
+
change_column :matches, :value, :string, limit: 255
|
84
|
+
|
85
|
+
change_column :note_annotations, :value, :string, limit: 255
|
86
|
+
change_column :note_annotations, :language, :string, limit: 255
|
87
|
+
|
88
|
+
change_column :notes, :owner_type, :string, limit: 255
|
89
|
+
|
90
|
+
change_column :schema_migrations, :version, :string, limit: 255
|
91
|
+
|
92
|
+
change_column :users, :forename, :string, limit: 255
|
93
|
+
change_column :users, :surname, :string, limit: 255
|
94
|
+
change_column :users, :email, :string, limit: 255
|
95
|
+
change_column :users, :crypted_password, :string, limit: 255
|
96
|
+
change_column :users, :password_salt, :string, limit: 255
|
97
|
+
change_column :users, :persistence_token, :string, limit: 255
|
98
|
+
change_column :users, :perishable_token, :string, limit: 255
|
99
|
+
change_column :users, :role, :string, limit: 255
|
100
|
+
change_column :users, :telephone_number, :string, limit: 255
|
101
|
+
change_column :users, :type, :string, limit: 255
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def change_database_encoding(encoding, collation)
|
108
|
+
connection = ActiveRecord::Base.connection
|
109
|
+
database = connection.current_database
|
110
|
+
tables = connection.tables
|
111
|
+
|
112
|
+
execute <<-SQL
|
113
|
+
ALTER DATABASE #{database} CHARACTER SET #{encoding} COLLATE #{collation};
|
114
|
+
SQL
|
115
|
+
|
116
|
+
tables.each do |table|
|
117
|
+
execute <<-SQL
|
118
|
+
ALTER TABLE #{database}.#{table} CONVERT TO CHARACTER SET #{encoding} COLLATE #{collation};
|
119
|
+
SQL
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class ChangeCollation < ActiveRecord::Migration
|
2
|
+
MYSQL_COLLATION_SUPPORT_VERSION = 8
|
3
|
+
|
4
|
+
def up
|
5
|
+
change_database_encoding('utf8mb4', 'utf8mb4_0900_as_ci') if check_supporting_mysql_version
|
6
|
+
end
|
7
|
+
|
8
|
+
def down
|
9
|
+
change_database_encoding('utf8', 'utf8mb4_general_ci') if check_supporting_mysql_version
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def check_supporting_mysql_version
|
14
|
+
connection = ActiveRecord::Base.connection
|
15
|
+
if connection.adapter_name == 'Mysql2'
|
16
|
+
version_row = connection.select_rows("SHOW VARIABLES WHERE variable_name = 'version'").try(:first)
|
17
|
+
raise "There is a problem of our code with your MySQL version, please report in GitHub Repository" if version_row.first != "version"
|
18
|
+
version_row.last.first.to_i >= MYSQL_COLLATION_SUPPORT_VERSION
|
19
|
+
else
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def change_database_encoding(encoding, collation)
|
25
|
+
connection = ActiveRecord::Base.connection
|
26
|
+
database = connection.current_database
|
27
|
+
tables = connection.tables
|
28
|
+
|
29
|
+
execute <<-SQL
|
30
|
+
ALTER DATABASE #{database} CHARACTER SET #{encoding} COLLATE #{collation};
|
31
|
+
SQL
|
32
|
+
|
33
|
+
tables.each do |table|
|
34
|
+
execute <<-SQL
|
35
|
+
ALTER TABLE #{database}.#{table} CONVERT TO CHARACTER SET #{encoding} COLLATE #{collation};
|
36
|
+
SQL
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|