utf8mb4rails 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4954a15b606370a431abdefc253289c341e2d647
4
- data.tar.gz: b9a7e416ec58b170053c8e6eccd03ff83730222c
2
+ SHA256:
3
+ metadata.gz: 56b87fc42083d61b0f0c48437897aef8e01241f672d0b7a2c238952d89a57807
4
+ data.tar.gz: b927e865f13370247f95ac65bcbb92a95860357b6632740397fed8972721b122
5
5
  SHA512:
6
- metadata.gz: 25fae3f7ffadec257d586c7ffa29d5d9a6c744a8743065a4acdfddc6277455283da8f3707d80c52ab2f6424c5356ebb064c3120c008150331c10628ba9ef834f
7
- data.tar.gz: 8753f0d26b1b4974c7a4c2bd88d0f3748ed0fa2aac832281d30df941827c0531abc3dae92ab34c86ae893bde23ef6e5a8419cb99e1d6fbc6bebe06474021365a
6
+ metadata.gz: 1919067c8d0592d0b40447c1be880245eca1310c34760749a0a9dfd5bb9ea23360ee985be44fc78d51b9506226fdac897ae50a3910b986f06b63342e6b25f9b9
7
+ data.tar.gz: c65d92bd56b807ffc7d83e3c557a4ceaccddc27c1500d70b7410401416c6742ad8e85955aca9912789ccbae7794f0d0159e40aee06c6462b32b5f39e034f097b
@@ -1,98 +1,103 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- utf8mb4rails (0.1.0)
5
- departure (~> 4.0, >= 4.0.1)
4
+ utf8mb4rails (0.2.0)
5
+ departure (~> 6.1)
6
6
  mysql2 (~> 0.4.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionmailer (4.2.9)
12
- actionpack (= 4.2.9)
13
- actionview (= 4.2.9)
14
- activejob (= 4.2.9)
11
+ actioncable (5.1.7)
12
+ actionpack (= 5.1.7)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.1.7)
16
+ actionpack (= 5.1.7)
17
+ actionview (= 5.1.7)
18
+ activejob (= 5.1.7)
15
19
  mail (~> 2.5, >= 2.5.4)
16
- rails-dom-testing (~> 1.0, >= 1.0.5)
17
- actionpack (4.2.9)
18
- actionview (= 4.2.9)
19
- activesupport (= 4.2.9)
20
- rack (~> 1.6)
21
- rack-test (~> 0.6.2)
22
- rails-dom-testing (~> 1.0, >= 1.0.5)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.1.7)
22
+ actionview (= 5.1.7)
23
+ activesupport (= 5.1.7)
24
+ rack (~> 2.0)
25
+ rack-test (>= 0.6.3)
26
+ rails-dom-testing (~> 2.0)
23
27
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
- actionview (4.2.9)
25
- activesupport (= 4.2.9)
28
+ actionview (5.1.7)
29
+ activesupport (= 5.1.7)
26
30
  builder (~> 3.1)
27
- erubis (~> 2.7.0)
28
- rails-dom-testing (~> 1.0, >= 1.0.5)
31
+ erubi (~> 1.4)
32
+ rails-dom-testing (~> 2.0)
29
33
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
30
- activejob (4.2.9)
31
- activesupport (= 4.2.9)
32
- globalid (>= 0.3.0)
33
- activemodel (4.2.9)
34
- activesupport (= 4.2.9)
35
- builder (~> 3.1)
36
- activerecord (4.2.9)
37
- activemodel (= 4.2.9)
38
- activesupport (= 4.2.9)
39
- arel (~> 6.0)
40
- activesupport (4.2.9)
41
- i18n (~> 0.7)
34
+ activejob (5.1.7)
35
+ activesupport (= 5.1.7)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.1.7)
38
+ activesupport (= 5.1.7)
39
+ activerecord (5.1.7)
40
+ activemodel (= 5.1.7)
41
+ activesupport (= 5.1.7)
42
+ arel (~> 8.0)
43
+ activesupport (5.1.7)
44
+ concurrent-ruby (~> 1.0, >= 1.0.2)
45
+ i18n (>= 0.7, < 2)
42
46
  minitest (~> 5.1)
43
- thread_safe (~> 0.3, >= 0.3.4)
44
47
  tzinfo (~> 1.1)
45
- arel (6.0.4)
46
- builder (3.2.3)
47
- concurrent-ruby (1.0.5)
48
- departure (4.0.1)
48
+ arel (8.0.0)
49
+ builder (3.2.4)
50
+ concurrent-ruby (1.1.6)
51
+ crass (1.0.6)
52
+ departure (6.1.0)
49
53
  mysql2 (~> 0.4.0)
50
- rails (~> 4.2.0)
54
+ rails (~> 5.1.0)
51
55
  diff-lcs (1.3)
52
- erubis (2.7.0)
53
- globalid (0.4.0)
56
+ erubi (1.9.0)
57
+ globalid (0.4.2)
54
58
  activesupport (>= 4.2.0)
55
- i18n (0.8.6)
56
- loofah (2.0.3)
59
+ i18n (1.8.2)
60
+ concurrent-ruby (~> 1.0)
61
+ loofah (2.5.0)
62
+ crass (~> 1.0.2)
57
63
  nokogiri (>= 1.5.9)
58
- mail (2.6.6)
59
- mime-types (>= 1.16, < 4)
60
- mime-types (3.1)
61
- mime-types-data (~> 3.2015)
62
- mime-types-data (3.2016.0521)
63
- mini_portile2 (2.2.0)
64
- minitest (5.10.3)
65
- mysql2 (0.4.9)
66
- nokogiri (1.8.0)
67
- mini_portile2 (~> 2.2.0)
68
- rack (1.6.8)
69
- rack-test (0.6.3)
70
- rack (>= 1.0)
71
- rails (4.2.9)
72
- actionmailer (= 4.2.9)
73
- actionpack (= 4.2.9)
74
- actionview (= 4.2.9)
75
- activejob (= 4.2.9)
76
- activemodel (= 4.2.9)
77
- activerecord (= 4.2.9)
78
- activesupport (= 4.2.9)
79
- bundler (>= 1.3.0, < 2.0)
80
- railties (= 4.2.9)
81
- sprockets-rails
82
- rails-deprecated_sanitizer (1.0.3)
83
- activesupport (>= 4.2.0.alpha)
84
- rails-dom-testing (1.0.8)
85
- activesupport (>= 4.2.0.beta, < 5.0)
86
- nokogiri (~> 1.6)
87
- rails-deprecated_sanitizer (>= 1.0.1)
88
- rails-html-sanitizer (1.0.3)
89
- loofah (~> 2.0)
90
- railties (4.2.9)
91
- actionpack (= 4.2.9)
92
- activesupport (= 4.2.9)
64
+ mail (2.7.1)
65
+ mini_mime (>= 0.1.1)
66
+ method_source (1.0.0)
67
+ mini_mime (1.0.2)
68
+ mini_portile2 (2.4.0)
69
+ minitest (5.14.0)
70
+ mysql2 (0.4.10)
71
+ nio4r (2.5.2)
72
+ nokogiri (1.10.9)
73
+ mini_portile2 (~> 2.4.0)
74
+ rack (2.2.2)
75
+ rack-test (1.1.0)
76
+ rack (>= 1.0, < 3)
77
+ rails (5.1.7)
78
+ actioncable (= 5.1.7)
79
+ actionmailer (= 5.1.7)
80
+ actionpack (= 5.1.7)
81
+ actionview (= 5.1.7)
82
+ activejob (= 5.1.7)
83
+ activemodel (= 5.1.7)
84
+ activerecord (= 5.1.7)
85
+ activesupport (= 5.1.7)
86
+ bundler (>= 1.3.0)
87
+ railties (= 5.1.7)
88
+ sprockets-rails (>= 2.0.0)
89
+ rails-dom-testing (2.0.3)
90
+ activesupport (>= 4.2.0)
91
+ nokogiri (>= 1.6)
92
+ rails-html-sanitizer (1.3.0)
93
+ loofah (~> 2.3)
94
+ railties (5.1.7)
95
+ actionpack (= 5.1.7)
96
+ activesupport (= 5.1.7)
97
+ method_source
93
98
  rake (>= 0.8.7)
94
99
  thor (>= 0.18.1, < 2.0)
95
- rake (10.5.0)
100
+ rake (13.0.1)
96
101
  rspec (3.6.0)
97
102
  rspec-core (~> 3.6.0)
98
103
  rspec-expectations (~> 3.6.0)
@@ -106,26 +111,29 @@ GEM
106
111
  diff-lcs (>= 1.2.0, < 2.0)
107
112
  rspec-support (~> 3.6.0)
108
113
  rspec-support (3.6.0)
109
- sprockets (3.7.1)
114
+ sprockets (4.0.0)
110
115
  concurrent-ruby (~> 1.0)
111
116
  rack (> 1, < 3)
112
117
  sprockets-rails (3.2.1)
113
118
  actionpack (>= 4.0)
114
119
  activesupport (>= 4.0)
115
120
  sprockets (>= 3.0.0)
116
- thor (0.20.0)
121
+ thor (1.0.1)
117
122
  thread_safe (0.3.6)
118
- tzinfo (1.2.3)
123
+ tzinfo (1.2.7)
119
124
  thread_safe (~> 0.1)
125
+ websocket-driver (0.6.5)
126
+ websocket-extensions (>= 0.1.0)
127
+ websocket-extensions (0.1.4)
120
128
 
121
129
  PLATFORMS
122
130
  ruby
123
131
 
124
132
  DEPENDENCIES
125
133
  bundler (~> 1.12)
126
- rake (~> 10.0)
134
+ rake (>= 12.3.3)
127
135
  rspec (~> 3.0)
128
136
  utf8mb4rails!
129
137
 
130
138
  BUNDLED WITH
131
- 1.12.5
139
+ 1.17.1
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "utf8mb4rails"
3
+ require 'bundler/setup'
4
+ require 'utf8mb4rails'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "utf8mb4rails"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -14,6 +14,7 @@ def usage
14
14
  puts 'You can also specify the COLLATION (utf8mb4_unicode_520_ci)'
15
15
  end
16
16
 
17
+ # Top Module
17
18
  module Utf8mb4rails
18
19
  extend Rake::DSL
19
20
 
@@ -21,7 +22,8 @@ module Utf8mb4rails
21
22
  desc 'migrates a table[/column] (TABLE, COLUMN env vars) to utf8mb encoding'
22
23
  task utf8mb4: :environment do
23
24
  require 'departure'
24
- Departure.configure do |_config|; end
25
+ Departure.configure do |_config|
26
+ end
25
27
 
26
28
  table = ENV['TABLE']
27
29
  unless table
@@ -5,7 +5,7 @@ module Utf8mb4rails
5
5
  # received from the database
6
6
  class ColumnInfo
7
7
  TEXT_TYPES = %w(CHAR VARCHAR TINYTEXT TEXT MEDIUMTEXT LONGTEXT).freeze
8
- attr_accessor :info
8
+ attr_reader :info
9
9
 
10
10
  # Receives a hash with (:type, :default, :max_length, :charset)
11
11
  def initialize(info)
@@ -19,14 +19,18 @@ module Utf8mb4rails
19
19
 
20
20
  # @return String : the sql part of the new type of the column definition
21
21
  def new_type_for_sql
22
- return "#{info[:type]}(#{info[:max_length]})" if info[:type] =~ /CHAR/
23
- info[:type]
22
+ info_type = info[:type]
23
+ return "#{info_type}(#{info[:max_length]})" if info_type =~ /CHAR/
24
+
25
+ info_type
24
26
  end
25
27
 
26
28
  # @return String : the sql part of the default value of the column definition
27
29
  def default_value_for_sql
28
- return nil unless info[:default]
29
- "default '#{info[:default]}'"
30
+ info_default = info[:default]
31
+ return nil unless info_default
32
+
33
+ "default '#{info_default}'"
30
34
  end
31
35
 
32
36
  # @return Bool : True if the column is of a text type
@@ -1,7 +1,9 @@
1
1
  module Utf8mb4rails
2
2
  module Migrator
3
+ # DB introspection (only for columns)
3
4
  class DBInspector
4
5
  # Initializes AR
6
+ # :reek:UtilityFunction
5
7
  def initialize
6
8
  ActiveRecord::Base.establish_connection(
7
9
  ActiveRecord::Base.connection_config.merge(adapter: 'percona')
@@ -10,6 +12,7 @@ module Utf8mb4rails
10
12
 
11
13
  ##
12
14
  # @returns [Array<String>] An array with column names
15
+ # :reek:UtilityFunction
13
16
  def columns(table)
14
17
  ActiveRecord::Base.connection.columns(table).map(&:name)
15
18
  end
@@ -20,6 +23,7 @@ module Utf8mb4rails
20
23
  # @param [String] column
21
24
  #
22
25
  # @returns [Hash] { type: String, default: String or nil, charset: String or nil }
26
+ # :reek:FeatureEnvy
23
27
  def column_info(table, column)
24
28
  sql = "SELECT DATA_TYPE, COLUMN_DEFAULT, CHARACTER_SET_NAME, CHARACTER_MAXIMUM_LENGTH
25
29
  FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '#{table}'
@@ -36,6 +40,7 @@ module Utf8mb4rails
36
40
 
37
41
  private
38
42
 
43
+ # :reek:UtilityFunction
39
44
  def database_name
40
45
  ActiveRecord::Base.connection.current_database
41
46
  end
@@ -1,14 +1,19 @@
1
+ require 'English'
2
+
1
3
  module Utf8mb4rails
2
4
  module Migrator
5
+ # This class will perform the actual migration, will run sql queries that
6
+ # alters tables
3
7
  class Runner
4
8
  NEW_COLLATION = ENV.fetch('COLLATION', 'utf8mb4_unicode_520_ci').freeze
5
9
 
6
- attr_accessor :inspector
10
+ attr_reader :inspector
7
11
 
8
12
  def initialize
9
13
  @inspector = DBInspector.new
10
14
  end
11
15
 
16
+ # :reek:FeatureEnvy
12
17
  def migrate_column!(table, column)
13
18
  column_info = inspector.column_info(table, column)
14
19
  if column_info.utf8mb4?
@@ -22,22 +27,31 @@ module Utf8mb4rails
22
27
  ActiveRecord::Base.connection.execute(sql)
23
28
  end
24
29
 
25
- def migrate_table_schema!(table)
26
- sql = "ALTER TABLE `#{table}` CONVERT TO CHARACTER SET utf8mb4 COLLATE #{NEW_COLLATION}"
27
- ActiveRecord::Base.connection.execute(sql)
28
- end
29
-
30
30
  def migrate_table!(table)
31
+ sql = []
31
32
  inspector.columns(table).each do |column|
32
- puts " migrating #{table}:#{column}"
33
- migrate_column!(table, column)
33
+ column_info = inspector.column_info(table, column)
34
+ next if column_info.utf8mb4? || !column_info.text_column? || skipped_column?(column)
35
+ sql << "DROP COLUMN \`#{column}`"
36
+ sql << "ADD COLUMN \`#{column}`\ #{column_info.new_type_for_sql} \
37
+ CHARACTER SET utf8mb4 COLLATE #{NEW_COLLATION} #{column_info.default_value_for_sql}"
34
38
  end
35
- migrate_table_schema!(table)
39
+ sql << "CONVERT TO CHARACTER SET utf8mb4 COLLATE #{NEW_COLLATION}"
40
+ ActiveRecord::Base.connection.execute("ALTER TABLE `#{table}` #{sql.join(' , ')};")
36
41
  rescue
37
42
  puts "Problems accesing the table #{table}"
38
- puts $!
43
+ puts $ERROR_INFO
39
44
  exit 1
40
45
  end
46
+
47
+ private
48
+
49
+ # :reek:UtilityFunction
50
+ def skipped_column?(column_name)
51
+ return false unless ENV.key? 'SKIP_COLUMNS'
52
+ skipped_columns = ENV['SKIP_COLUMNS'].join(',')
53
+ skipped_columns.include(column_name)
54
+ end
41
55
  end
42
56
  end
43
57
  end
@@ -1,3 +1,3 @@
1
1
  module Utf8mb4rails
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'utf8mb4rails/version'
@@ -10,19 +11,22 @@ Gem::Specification.new do |spec|
10
11
  spec.email = ['joseferper@gmail.com']
11
12
 
12
13
  spec.summary = 'Adds a task to migrate mysql utf8 tables to utf8mb4 (emojis)'
13
- spec.description = 'Poetry is so XIX century, nowadays we express ourselves using emojis. This gem adds a task to migrate mysql utf8 tables to utf8mb4 in rails projects.'
14
+ spec.description = 'Poetry is so XIX century, nowadays we express ourselves using emojis.
15
+ This gem adds a task to migrate mysql utf8 tables to utf8mb4 in rails projects.'
14
16
  spec.homepage = 'https://github.com/magec/utf8mb4rails'
15
17
  spec.license = 'MIT'
16
18
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
18
22
  spec.bindir = 'exe'
19
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
24
  spec.require_paths = ['lib']
21
25
 
22
- spec.add_runtime_dependency 'departure', '~> 4.0', '>= 4.0.1'
26
+ spec.add_runtime_dependency 'departure', '~> 6.1'
23
27
  spec.add_runtime_dependency 'mysql2', '~> 0.4.0'
24
28
 
25
29
  spec.add_development_dependency 'bundler', '~> 1.12'
26
- spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rake', '>= 12.3.3'
27
31
  spec.add_development_dependency 'rspec', '~> 3.0'
28
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utf8mb4rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Fernandez (magec)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-07 00:00:00.000000000 Z
11
+ date: 2020-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: departure
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 4.0.1
19
+ version: '6.1'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '4.0'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 4.0.1
26
+ version: '6.1'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: mysql2
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -62,16 +56,16 @@ dependencies:
62
56
  name: rake
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
- - - "~>"
59
+ - - ">="
66
60
  - !ruby/object:Gem::Version
67
- version: '10.0'
61
+ version: 12.3.3
68
62
  type: :development
69
63
  prerelease: false
70
64
  version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
- - - "~>"
66
+ - - ">="
73
67
  - !ruby/object:Gem::Version
74
- version: '10.0'
68
+ version: 12.3.3
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: rspec
77
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,7 +80,8 @@ dependencies:
86
80
  - - "~>"
87
81
  - !ruby/object:Gem::Version
88
82
  version: '3.0'
89
- description: Poetry is so XIX century, nowadays we express ourselves using emojis.
83
+ description: |-
84
+ Poetry is so XIX century, nowadays we express ourselves using emojis.
90
85
  This gem adds a task to migrate mysql utf8 tables to utf8mb4 in rails projects.
91
86
  email:
92
87
  - joseferper@gmail.com
@@ -130,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
125
  version: '0'
131
126
  requirements: []
132
127
  rubyforge_project:
133
- rubygems_version: 2.4.5.1
128
+ rubygems_version: 2.7.6
134
129
  signing_key:
135
130
  specification_version: 4
136
131
  summary: Adds a task to migrate mysql utf8 tables to utf8mb4 (emojis)