-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmysql_change_database_encoding.rb
33 lines (24 loc) · 1.29 KB
/
mysql_change_database_encoding.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Copyright 2018, David Berube. All rights reserved.
# See LICENSE for license details.
require 'bundler'
Bundler.require
require 'optparse'
require 'active_record'
require 'pry'
require 'pp'
require_relative 'lib/database_encoding_changer.rb'
require_relative 'lib/database_encoding_changer_table.rb'
require_relative 'lib/mcde_options_parser.rb'
options = McdeOptionsParser.parse! # This method returns an options hash from options passed via the command line;
# note that if invalid or insufficient options are passed, execution will terminate inside of this method.
puts "Connecting to #{options[:database]}"
ActiveRecord::Base.establish_connection( adapter: 'mysql2',
host: options[:host],
port: options[:port],
database: options[:database],
username: options[:user],
password: options[:password])
dec = DatabaseEncodingChanger.new(options)
dec.run! # This set the default encoding and/or collation for the database;
# it will then will loop through all of the tables in the database and, likewise,
# set the default encoding and/or collation.