utf8mb4rails 0.1.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 +7 -0
- data/.gitignore +47 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +131 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/utf8mb4rails/migrator/column_info.rb +38 -0
- data/lib/utf8mb4rails/migrator/db_inspector.rb +44 -0
- data/lib/utf8mb4rails/migrator/runner.rb +43 -0
- data/lib/utf8mb4rails/migrator.rb +4 -0
- data/lib/utf8mb4rails/version.rb +3 -0
- data/lib/utf8mb4rails.rb +43 -0
- data/utf8mb4rails.gemspec +28 -0
- metadata +137 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: fc9eaa8412f0244ac69818e4cbdc16c3377c270f
|
|
4
|
+
data.tar.gz: 7a709d08a0b45673c9361b4cdc29460195d4c30b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 353b22f722ddc2bd6952a738f20fe363e8bd694127e00d09cd3de0d021189930e058619722951db699cd2f5f500b8f072e73f0316f49312a0dcdb75dd62feb10
|
|
7
|
+
data.tar.gz: 3e46c8ed9491b05e916177a717d1dd4a350f895f9e6a9102a180ccce211636efa5e406c10d5442b8b1604921b96e9b4bf2e83d30c0ea4d61101ab9b112231b8d
|
data/.gitignore
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
*.rbc
|
|
2
|
+
capybara-*.html
|
|
3
|
+
.rspec
|
|
4
|
+
/log
|
|
5
|
+
/tmp
|
|
6
|
+
/db/*.sqlite3
|
|
7
|
+
/db/*.sqlite3-journal
|
|
8
|
+
/public/system
|
|
9
|
+
/coverage/
|
|
10
|
+
/spec/tmp
|
|
11
|
+
*.orig
|
|
12
|
+
rerun.txt
|
|
13
|
+
pickle-email-*.html
|
|
14
|
+
*log
|
|
15
|
+
|
|
16
|
+
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
|
|
17
|
+
config/initializers/secret_token.rb
|
|
18
|
+
|
|
19
|
+
# Only include if you have production secrets in this file, which is no longer a Rails default
|
|
20
|
+
# config/secrets.yml
|
|
21
|
+
|
|
22
|
+
# dotenv
|
|
23
|
+
# TODO Comment out this rule if environment variables can be committed
|
|
24
|
+
.env
|
|
25
|
+
|
|
26
|
+
## Environment normalization:
|
|
27
|
+
/.bundle
|
|
28
|
+
/vendor/bundle
|
|
29
|
+
|
|
30
|
+
# these should all be checked in to normalize the environment:
|
|
31
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
|
32
|
+
|
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
34
|
+
.rvmrc
|
|
35
|
+
|
|
36
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
|
37
|
+
/vendor/assets/bower_components
|
|
38
|
+
*.bowerrc
|
|
39
|
+
bower.json
|
|
40
|
+
|
|
41
|
+
# Ignore pow environment settings
|
|
42
|
+
.powenv
|
|
43
|
+
|
|
44
|
+
# Ignore Byebug command history file.
|
|
45
|
+
.byebug_history
|
|
46
|
+
|
|
47
|
+
*~
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
utf8mb4rails (0.1.0)
|
|
5
|
+
departure (~> 4.0, >= 4.0.1)
|
|
6
|
+
mysql2 (~> 0.4.0)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
actionmailer (4.2.9)
|
|
12
|
+
actionpack (= 4.2.9)
|
|
13
|
+
actionview (= 4.2.9)
|
|
14
|
+
activejob (= 4.2.9)
|
|
15
|
+
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)
|
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
24
|
+
actionview (4.2.9)
|
|
25
|
+
activesupport (= 4.2.9)
|
|
26
|
+
builder (~> 3.1)
|
|
27
|
+
erubis (~> 2.7.0)
|
|
28
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
29
|
+
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)
|
|
42
|
+
minitest (~> 5.1)
|
|
43
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
|
44
|
+
tzinfo (~> 1.1)
|
|
45
|
+
arel (6.0.4)
|
|
46
|
+
builder (3.2.3)
|
|
47
|
+
concurrent-ruby (1.0.5)
|
|
48
|
+
departure (4.0.1)
|
|
49
|
+
mysql2 (~> 0.4.0)
|
|
50
|
+
rails (~> 4.2.0)
|
|
51
|
+
diff-lcs (1.3)
|
|
52
|
+
erubis (2.7.0)
|
|
53
|
+
globalid (0.4.0)
|
|
54
|
+
activesupport (>= 4.2.0)
|
|
55
|
+
i18n (0.8.6)
|
|
56
|
+
loofah (2.0.3)
|
|
57
|
+
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)
|
|
93
|
+
rake (>= 0.8.7)
|
|
94
|
+
thor (>= 0.18.1, < 2.0)
|
|
95
|
+
rake (10.5.0)
|
|
96
|
+
rspec (3.6.0)
|
|
97
|
+
rspec-core (~> 3.6.0)
|
|
98
|
+
rspec-expectations (~> 3.6.0)
|
|
99
|
+
rspec-mocks (~> 3.6.0)
|
|
100
|
+
rspec-core (3.6.0)
|
|
101
|
+
rspec-support (~> 3.6.0)
|
|
102
|
+
rspec-expectations (3.6.0)
|
|
103
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
104
|
+
rspec-support (~> 3.6.0)
|
|
105
|
+
rspec-mocks (3.6.0)
|
|
106
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
107
|
+
rspec-support (~> 3.6.0)
|
|
108
|
+
rspec-support (3.6.0)
|
|
109
|
+
sprockets (3.7.1)
|
|
110
|
+
concurrent-ruby (~> 1.0)
|
|
111
|
+
rack (> 1, < 3)
|
|
112
|
+
sprockets-rails (3.2.1)
|
|
113
|
+
actionpack (>= 4.0)
|
|
114
|
+
activesupport (>= 4.0)
|
|
115
|
+
sprockets (>= 3.0.0)
|
|
116
|
+
thor (0.20.0)
|
|
117
|
+
thread_safe (0.3.6)
|
|
118
|
+
tzinfo (1.2.3)
|
|
119
|
+
thread_safe (~> 0.1)
|
|
120
|
+
|
|
121
|
+
PLATFORMS
|
|
122
|
+
ruby
|
|
123
|
+
|
|
124
|
+
DEPENDENCIES
|
|
125
|
+
bundler (~> 1.12)
|
|
126
|
+
rake (~> 10.0)
|
|
127
|
+
rspec (~> 3.0)
|
|
128
|
+
utf8mb4rails!
|
|
129
|
+
|
|
130
|
+
BUNDLED WITH
|
|
131
|
+
1.12.5
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Jose Fernández
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Jose Fernandez (magec)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Utf8mb4rails
|
|
2
|
+
|
|
3
|
+
A simple gem that adds a rake task to deal with utf8 to utf8mb4 migrations for mysql.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'utf8mb4rails'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install utf8mb4rails
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
This gem will add in your rails project a new task called utf8mb4. This tast is aimed to easily convert tables in utf8 into
|
|
24
|
+
utf8mb4 without truncating column contents and maintaining its original schema (without changing max sizes).
|
|
25
|
+
|
|
26
|
+
**USE AT YOUR OWN RISK!!!**
|
|
27
|
+
|
|
28
|
+
$ rake -T
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
...
|
|
32
|
+
rake db:utf8mb4 # migrates a table[/column] (TABLE, COLUMN env vars) to utf8mb encoding
|
|
33
|
+
...
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
You can modify its behavior using env vars.
|
|
38
|
+
|
|
39
|
+
- **TABLE**: The table you want to migrate, if no column is specified every single column will be migrated, also the default charset
|
|
40
|
+
of the table is altered.
|
|
41
|
+
- **COLUMN**: The column to be migrated (needs TABLE defined). It will only migrate that column definition.
|
|
42
|
+
- **COLLATION**: The collation (utf8mb4_unicode_520_ci by default)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Contributing
|
|
46
|
+
|
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/magec/utf8mb4rails.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
53
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "utf8mb4rails"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Utf8mb4rails
|
|
2
|
+
module Migrator
|
|
3
|
+
|
|
4
|
+
# Abstraction for dealing with column information
|
|
5
|
+
# received from the database
|
|
6
|
+
class ColumnInfo
|
|
7
|
+
TEXT_TYPES = %w(CHAR VARCHAR TINYTEXT TEXT MEDIUMTEXT LONGTEXT).freeze
|
|
8
|
+
attr_accessor :info
|
|
9
|
+
|
|
10
|
+
# Receives a hash with (:type, :default, :max_length, :charset)
|
|
11
|
+
def initialize(info)
|
|
12
|
+
@info = info
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return Bool : True if the column is in utf8mb4
|
|
16
|
+
def utf8mb4?
|
|
17
|
+
info[:charset] =~ /utf8mb4/
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @return String : the sql part of the new type of the column definition
|
|
21
|
+
def new_type_for_sql
|
|
22
|
+
return "#{info[:type]}(#{info[:max_length]})" if info[:type] =~ /CHAR/
|
|
23
|
+
info[:type]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @return String : the sql part of the default value of the column definition
|
|
27
|
+
def default_value_for_sql
|
|
28
|
+
return nil unless info[:default]
|
|
29
|
+
"default '#{info[:default]}'"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @return Bool : True if the column is of a text type
|
|
33
|
+
def text_column?
|
|
34
|
+
TEXT_TYPES.include?(info[:type])
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Utf8mb4rails
|
|
2
|
+
module Migrator
|
|
3
|
+
class DBInspector
|
|
4
|
+
# Initializes AR
|
|
5
|
+
def initialize
|
|
6
|
+
ActiveRecord::Base.establish_connection(
|
|
7
|
+
ActiveRecord::Base.connection_config.merge(adapter: 'percona')
|
|
8
|
+
)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# @returns [Array<String>] An array with column names
|
|
13
|
+
def columns(table)
|
|
14
|
+
ActiveRecord::Base.connection.columns(table).map(&:name)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Returns a hash with information about the column
|
|
18
|
+
#
|
|
19
|
+
# @param [String] table
|
|
20
|
+
# @param [String] column
|
|
21
|
+
#
|
|
22
|
+
# @returns [Hash] { type: String, default: String or nil, charset: String or nil }
|
|
23
|
+
def column_info(table, column)
|
|
24
|
+
sql = "SELECT DATA_TYPE, COLUMN_DEFAULT, CHARACTER_SET_NAME, CHARACTER_MAXIMUM_LENGTH
|
|
25
|
+
FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '#{table}'
|
|
26
|
+
AND COLUMN_NAME = '#{column}'
|
|
27
|
+
AND TABLE_SCHEMA='#{database_name}'"
|
|
28
|
+
result = ActiveRecord::Base.connection.execute(sql).first
|
|
29
|
+
ColumnInfo.new(
|
|
30
|
+
type: result[0].upcase,
|
|
31
|
+
default: result[1],
|
|
32
|
+
charset: result[2],
|
|
33
|
+
max_length: result[3]
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def database_name
|
|
40
|
+
ActiveRecord::Base.connection.current_database
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Utf8mb4rails
|
|
2
|
+
module Migrator
|
|
3
|
+
class Runner
|
|
4
|
+
NEW_COLLATION = ENV.fetch('COLLATION', 'utf8mb4_unicode_520_ci').freeze
|
|
5
|
+
|
|
6
|
+
attr_accessor :inspector
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@inspector = DBInspector.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def migrate_column!(table, column)
|
|
13
|
+
column_info = inspector.column_info(table, column)
|
|
14
|
+
if column_info.utf8mb4?
|
|
15
|
+
puts " Skipping column #{column} (already in utf8mb4)'"
|
|
16
|
+
return
|
|
17
|
+
end
|
|
18
|
+
return unless column_info.text_column?
|
|
19
|
+
sql = "ALTER TABLE `#{table}` DROP COLUMN \`#{column}`\ ,
|
|
20
|
+
ADD COLUMN \`#{column}`\ #{column_info.new_type_for_sql} CHARACTER SET utf8mb4
|
|
21
|
+
COLLATE #{NEW_COLLATION} #{column_info.default_value_for_sql}"
|
|
22
|
+
ActiveRecord::Base.connection.execute(sql)
|
|
23
|
+
end
|
|
24
|
+
|
|
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
|
+
def migrate_table!(table)
|
|
31
|
+
inspector.columns(table).each do |column|
|
|
32
|
+
puts " migrating #{table}:#{column}"
|
|
33
|
+
migrate_column!(table, column)
|
|
34
|
+
end
|
|
35
|
+
migrate_table_schema!(table)
|
|
36
|
+
rescue
|
|
37
|
+
puts "Problems accesing the table #{table}"
|
|
38
|
+
puts $!
|
|
39
|
+
exit 1
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/utf8mb4rails.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'utf8mb4rails/version'
|
|
2
|
+
require 'utf8mb4rails/migrator'
|
|
3
|
+
require 'departure'
|
|
4
|
+
|
|
5
|
+
Departure.configure do |_config|; end
|
|
6
|
+
def usage
|
|
7
|
+
puts
|
|
8
|
+
puts 'Usage: '
|
|
9
|
+
puts
|
|
10
|
+
puts 'For migrating an entire table use:'
|
|
11
|
+
puts '$ TABLE=table_name rake db:utf8mb4'
|
|
12
|
+
puts
|
|
13
|
+
puts 'For migrating an specified column table:'
|
|
14
|
+
puts '$ TABLE=table_name COLUMN=column_name rake db:utf8mb4'
|
|
15
|
+
puts
|
|
16
|
+
puts 'You can also specify the COLLATION (utf8mb4_unicode_520_ci)'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module Utf8mb4rails
|
|
20
|
+
extend Rake::DSL
|
|
21
|
+
|
|
22
|
+
namespace :db do
|
|
23
|
+
desc 'migrates a table[/column] (TABLE, COLUMN env vars) to utf8mb encoding'
|
|
24
|
+
task utf8mb4: :environment do
|
|
25
|
+
table = ENV['TABLE']
|
|
26
|
+
unless table
|
|
27
|
+
puts 'Please specify a table with TABLE='
|
|
28
|
+
usage
|
|
29
|
+
exit 1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
column = ENV['COLUMN']
|
|
33
|
+
runner = Migrator::Runner.new
|
|
34
|
+
if column
|
|
35
|
+
puts 'Migrating #{table}.#{column}'
|
|
36
|
+
runner.migrate_column!(table, column)
|
|
37
|
+
else
|
|
38
|
+
puts 'No column specified, will migrate the entire table'
|
|
39
|
+
runner.migrate_table!(table)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'utf8mb4rails/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'utf8mb4rails'
|
|
8
|
+
spec.version = Utf8mb4rails::VERSION
|
|
9
|
+
spec.authors = ['Jose Fernandez (magec)']
|
|
10
|
+
spec.email = ['joseferper@gmail.com']
|
|
11
|
+
|
|
12
|
+
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.homepage = 'https://github.com/magec/utf8mb4rails'
|
|
15
|
+
spec.license = 'MIT'
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
spec.bindir = 'exe'
|
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ['lib']
|
|
21
|
+
|
|
22
|
+
spec.add_runtime_dependency 'departure', '~> 4.0', '>= 4.0.1'
|
|
23
|
+
spec.add_runtime_dependency 'mysql2', '~> 0.4.0'
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: utf8mb4rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jose Fernandez (magec)
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-09-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: departure
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '4.0'
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 4.0.1
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - "~>"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '4.0'
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 4.0.1
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: mysql2
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.4.0
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 0.4.0
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: bundler
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '1.12'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '1.12'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: rake
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '10.0'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '10.0'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: rspec
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '3.0'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '3.0'
|
|
89
|
+
description: Poetry is so XIX century, nowadays we express ourselves using emojis.
|
|
90
|
+
This gem adds a task to migrate mysql utf8 tables to utf8mb4 in rails projects.
|
|
91
|
+
email:
|
|
92
|
+
- joseferper@gmail.com
|
|
93
|
+
executables: []
|
|
94
|
+
extensions: []
|
|
95
|
+
extra_rdoc_files: []
|
|
96
|
+
files:
|
|
97
|
+
- ".gitignore"
|
|
98
|
+
- Gemfile
|
|
99
|
+
- Gemfile.lock
|
|
100
|
+
- LICENSE
|
|
101
|
+
- LICENSE.txt
|
|
102
|
+
- README.md
|
|
103
|
+
- Rakefile
|
|
104
|
+
- bin/console
|
|
105
|
+
- bin/setup
|
|
106
|
+
- lib/utf8mb4rails.rb
|
|
107
|
+
- lib/utf8mb4rails/migrator.rb
|
|
108
|
+
- lib/utf8mb4rails/migrator/column_info.rb
|
|
109
|
+
- lib/utf8mb4rails/migrator/db_inspector.rb
|
|
110
|
+
- lib/utf8mb4rails/migrator/runner.rb
|
|
111
|
+
- lib/utf8mb4rails/version.rb
|
|
112
|
+
- utf8mb4rails.gemspec
|
|
113
|
+
homepage: https://github.com/magec/utf8mb4rails
|
|
114
|
+
licenses:
|
|
115
|
+
- MIT
|
|
116
|
+
metadata: {}
|
|
117
|
+
post_install_message:
|
|
118
|
+
rdoc_options: []
|
|
119
|
+
require_paths:
|
|
120
|
+
- lib
|
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - ">="
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '0'
|
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
requirements: []
|
|
132
|
+
rubyforge_project:
|
|
133
|
+
rubygems_version: 2.4.5.1
|
|
134
|
+
signing_key:
|
|
135
|
+
specification_version: 4
|
|
136
|
+
summary: Adds a task to migrate mysql utf8 tables to utf8mb4 (emojis)
|
|
137
|
+
test_files: []
|