arrival 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +3 -0
- data/Dockerfile +13 -11
- data/Dockerfile2.2 +39 -0
- data/Rakefile +3 -4
- data/arrival.gemspec +3 -4
- data/bin/console +1 -1
- data/config.yml +4 -0
- data/configuration.rb +1 -4
- data/db/config.yml +15 -0
- data/departure_error.log +80 -0
- data/docker-compose.yml +9 -7
- data/lib/active_record/connection_adapters/{percona_adapter.rb → arrival_adapter.rb} +14 -19
- data/lib/arrival.rb +28 -22
- data/lib/arrival/cli_generator.rb +27 -22
- data/lib/arrival/command.rb +20 -16
- data/lib/arrival/configuration.rb +3 -3
- data/lib/arrival/railtie.rb +14 -23
- data/lib/arrival/version.rb +1 -1
- data/replica/mysql_replica.env +2 -2
- data/setup_replication.sh +46 -0
- data/test_database.rb +20 -17
- metadata +13 -47
- data/.codeclimate.yml +0 -8
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- data/config.yml.erb +0 -4
- data/lib/arrival/dsn.rb +0 -24
- data/lib/arrival/log_sanitizers/password_sanitizer.rb +0 -22
- data/lib/arrival/logger_factory.rb +0 -16
- data/lib/arrival/null_logger.rb +0 -15
- data/lib/lhm.rb +0 -23
- data/lib/lhm/adapter.rb +0 -107
- data/lib/lhm/column_with_sql.rb +0 -96
- data/lib/lhm/column_with_type.rb +0 -29
data/.codeclimate.yml
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
---
|
2
|
-
name: Bug report
|
3
|
-
about: Create a report to help us improve
|
4
|
-
title: "[BUG] "
|
5
|
-
labels: ''
|
6
|
-
assignees: ''
|
7
|
-
|
8
|
-
---
|
9
|
-
|
10
|
-
**Describe the bug**
|
11
|
-
<!-- A clear and concise description of what the bug is. -->
|
12
|
-
|
13
|
-
**To Reproduce**
|
14
|
-
Steps to reproduce the behavior:
|
15
|
-
1. Configure like '...'
|
16
|
-
2. Run '...'
|
17
|
-
3. See error
|
18
|
-
|
19
|
-
**Expected behavior**
|
20
|
-
A clear and concise description of what you expected to happen.
|
21
|
-
|
22
|
-
**Back traces, screenshots, errors **
|
23
|
-
If applicable, add anything that helps explaining your problem.
|
24
|
-
|
25
|
-
**Setup**
|
26
|
-
- OS: name, version
|
27
|
-
- gh-ost version:
|
28
|
-
- arrival version:
|
29
|
-
|
30
|
-
**Additional context**
|
31
|
-
Add any other context about the problem here.
|
@@ -1,20 +0,0 @@
|
|
1
|
-
---
|
2
|
-
name: Feature request
|
3
|
-
about: Suggest an idea for this project
|
4
|
-
title: "[IMPROVEMENT]"
|
5
|
-
labels: ''
|
6
|
-
assignees: ''
|
7
|
-
|
8
|
-
---
|
9
|
-
|
10
|
-
**Is your feature request related to a problem? Please describe.**
|
11
|
-
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
12
|
-
|
13
|
-
**Describe the solution you'd like**
|
14
|
-
A clear and concise description of what you want to happen.
|
15
|
-
|
16
|
-
**Describe alternatives you've considered**
|
17
|
-
A clear and concise description of any alternative solutions or features you've considered.
|
18
|
-
|
19
|
-
**Additional context**
|
20
|
-
Add any other context or screenshots about the feature request here.
|
data/config.yml.erb
DELETED
data/lib/arrival/dsn.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Arrival
|
2
|
-
# Represents the 'DSN' argument of Percona's pt-online-schema-change
|
3
|
-
# See https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html#dsn-options
|
4
|
-
class DSN
|
5
|
-
# Constructor
|
6
|
-
#
|
7
|
-
# @param database [String, Symbol]
|
8
|
-
# @param table_name [String, Symbol]
|
9
|
-
def initialize(database, table_name)
|
10
|
-
@database = database
|
11
|
-
@table_name = table_name
|
12
|
-
end
|
13
|
-
|
14
|
-
# Returns the pt-online-schema-change DSN string. See
|
15
|
-
# https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html#dsn-options
|
16
|
-
def to_s
|
17
|
-
"D=#{database},t=#{table_name}"
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
attr_reader :table_name, :database
|
23
|
-
end
|
24
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Arrival
|
2
|
-
module LogSanitizers
|
3
|
-
class PasswordSanitizer
|
4
|
-
PASSWORD_REPLACEMENT = '[filtered_password]'.freeze
|
5
|
-
|
6
|
-
delegate :password_argument, to: :connection_details
|
7
|
-
|
8
|
-
def initialize(connection_details)
|
9
|
-
@connection_details = connection_details
|
10
|
-
end
|
11
|
-
|
12
|
-
def execute(log_statement)
|
13
|
-
return log_statement if password_argument.blank?
|
14
|
-
log_statement.gsub(password_argument, PASSWORD_REPLACEMENT)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
attr_accessor :connection_details
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Arrival
|
2
|
-
module LoggerFactory
|
3
|
-
# Returns the appropriate logger instance for the given configuration. Use
|
4
|
-
# :verbose option to log to the stdout
|
5
|
-
#
|
6
|
-
# @param verbose [Boolean]
|
7
|
-
# @return [#say, #write]
|
8
|
-
def self.build(sanitizers: [], verbose: true)
|
9
|
-
if verbose
|
10
|
-
Arrival::Logger.new(sanitizers)
|
11
|
-
else
|
12
|
-
Arrival::NullLogger.new
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/arrival/null_logger.rb
DELETED
data/lib/lhm.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'lhm/adapter'
|
2
|
-
|
3
|
-
# Defines the same global namespace as LHM's gem does to mimic its API
|
4
|
-
# while providing a different behaviour. We delegate all LHM's methods to
|
5
|
-
# ActiveRecord so that you don't need to modify your old LHM migrations
|
6
|
-
module Lhm
|
7
|
-
# Yields an adapter instance so that Lhm migration Dsl methods get
|
8
|
-
# delegated to ActiveRecord::Migration ones instead
|
9
|
-
#
|
10
|
-
# @param table_name [String]
|
11
|
-
# @param _options [Hash]
|
12
|
-
# @param block [Block]
|
13
|
-
def self.change_table(table_name, _options = {}, &block) # rubocop:disable Lint/UnusedMethodArgument
|
14
|
-
yield Adapter.new(@migration, table_name)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Sets the migration to apply the adapter to
|
18
|
-
#
|
19
|
-
# @param migration [ActiveRecord::Migration]
|
20
|
-
def self.migration=(migration)
|
21
|
-
@migration = migration
|
22
|
-
end
|
23
|
-
end
|
data/lib/lhm/adapter.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'lhm/column_with_sql'
|
2
|
-
require 'lhm/column_with_type'
|
3
|
-
|
4
|
-
module Lhm
|
5
|
-
# Translates Lhm DSL to ActiveRecord's one, so Lhm migrations will now go
|
6
|
-
# through Percona as well, without any modification on the migration's
|
7
|
-
# code
|
8
|
-
class Adapter
|
9
|
-
# Constructor
|
10
|
-
#
|
11
|
-
# @param migration [ActiveRecord::Migtration]
|
12
|
-
# @param table_name [String, Symbol]
|
13
|
-
def initialize(migration, table_name)
|
14
|
-
@migration = migration
|
15
|
-
@table_name = table_name
|
16
|
-
end
|
17
|
-
|
18
|
-
# Adds the specified column through ActiveRecord
|
19
|
-
#
|
20
|
-
# @param column_name [String, Symbol]
|
21
|
-
# @param definition [String, Symbol]
|
22
|
-
def add_column(column_name, definition)
|
23
|
-
attributes = column_attributes(column_name, definition)
|
24
|
-
migration.add_column(*attributes)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Removes the specified column through ActiveRecord
|
28
|
-
#
|
29
|
-
# @param column_name [String, Symbol]
|
30
|
-
def remove_column(column_name)
|
31
|
-
migration.remove_column(table_name, column_name)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Adds an index in the specified columns through ActiveRecord. Note you
|
35
|
-
# can provide a name as well
|
36
|
-
#
|
37
|
-
# @param columns [Array<String>, Array<Symbol>, String, Symbol]
|
38
|
-
# @param index_name [String]
|
39
|
-
def add_index(columns, index_name = nil)
|
40
|
-
options = { name: index_name } if index_name
|
41
|
-
migration.add_index(table_name, columns, options || {})
|
42
|
-
end
|
43
|
-
|
44
|
-
# Removes the index in the given columns or by its name
|
45
|
-
#
|
46
|
-
# @param columns [Array<String>, Array<Symbol>, String, Symbol]
|
47
|
-
# @param index_name [String]
|
48
|
-
def remove_index(columns, index_name = nil)
|
49
|
-
options = if index_name
|
50
|
-
{ name: index_name }
|
51
|
-
else
|
52
|
-
{ column: columns }
|
53
|
-
end
|
54
|
-
migration.remove_index(table_name, options)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Change the column to use the provided definition, through ActiveRecord
|
58
|
-
#
|
59
|
-
# @param column_name [String, Symbol]
|
60
|
-
# @param definition [String, Symbol]
|
61
|
-
def change_column(column_name, definition)
|
62
|
-
attributes = column_attributes(column_name, definition)
|
63
|
-
migration.change_column(*attributes)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Renames the old_name column to new_name by using ActiveRecord
|
67
|
-
#
|
68
|
-
# @param old_name [String, Symbol]
|
69
|
-
# @param new_name [String, Symbol]
|
70
|
-
def rename_column(old_name, new_name)
|
71
|
-
migration.rename_column(table_name, old_name, new_name)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Adds a unique index on the given columns, with the provided name if passed
|
75
|
-
#
|
76
|
-
# @param columns [Array<String>, Array<Symbol>, String, Symbol]
|
77
|
-
# @param index_name [String]
|
78
|
-
def add_unique_index(columns, index_name = nil)
|
79
|
-
options = { unique: true }
|
80
|
-
options.merge!(name: index_name) if index_name # rubocop:disable Performance/RedundantMerge
|
81
|
-
|
82
|
-
migration.add_index(table_name, columns, options)
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
attr_reader :migration, :table_name
|
88
|
-
|
89
|
-
# Returns the instance of ActiveRecord column with the given name and
|
90
|
-
# definition
|
91
|
-
#
|
92
|
-
# @param name [String, Symbol]
|
93
|
-
# @param definition [String]
|
94
|
-
def column(name, definition)
|
95
|
-
@column ||= if definition.is_a?(Symbol)
|
96
|
-
ColumnWithType.new(name, definition)
|
97
|
-
else
|
98
|
-
ColumnWithSql.new(name, definition)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def column_attributes(name, definition)
|
103
|
-
attributes = column(name, definition).attributes
|
104
|
-
[table_name, name].concat(attributes)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
data/lib/lhm/column_with_sql.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
module Lhm
|
4
|
-
# Abstracts the details of a table column definition when specified with a MySQL
|
5
|
-
# column definition string
|
6
|
-
class ColumnWithSql
|
7
|
-
extend Forwardable
|
8
|
-
|
9
|
-
# Returns the column's class to be used
|
10
|
-
#
|
11
|
-
# @return [Constant]
|
12
|
-
def self.column_factory
|
13
|
-
::ActiveRecord::ConnectionAdapters::ArrivalAdapter::Column
|
14
|
-
end
|
15
|
-
|
16
|
-
# Constructor
|
17
|
-
#
|
18
|
-
# @param name [String, Symbol]
|
19
|
-
# @param definition [String]
|
20
|
-
def initialize(name, definition)
|
21
|
-
@name = name
|
22
|
-
@definition = definition
|
23
|
-
end
|
24
|
-
|
25
|
-
# Returns the column data as an Array to be used with the splat operator.
|
26
|
-
# See Lhm::Adaper#add_column
|
27
|
-
#
|
28
|
-
# @return [Array]
|
29
|
-
def attributes
|
30
|
-
[type, column_options]
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def_delegators :column, :limit, :type, :default, :null
|
36
|
-
|
37
|
-
attr_reader :name, :definition
|
38
|
-
|
39
|
-
# TODO: investigate
|
40
|
-
#
|
41
|
-
# Rails doesn't take into account lenght argument of INT in the
|
42
|
-
# definition, as an integer it will default it to 4 not an integer
|
43
|
-
#
|
44
|
-
# Returns the columns data as a Hash
|
45
|
-
#
|
46
|
-
# @return [Hash]
|
47
|
-
def column_options
|
48
|
-
{ limit: column.limit, default: column.default, null: column.null }
|
49
|
-
end
|
50
|
-
|
51
|
-
# Returns the column instance with the provided data
|
52
|
-
#
|
53
|
-
# @return [column_factory]
|
54
|
-
def column
|
55
|
-
cast_type = ActiveRecord::Base.connection.send(:lookup_cast_type, definition)
|
56
|
-
metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(
|
57
|
-
type: cast_type.type,
|
58
|
-
sql_type: definition,
|
59
|
-
limit: cast_type.limit
|
60
|
-
)
|
61
|
-
mysql_metadata = ActiveRecord::ConnectionAdapters::MySQL::TypeMetadata.new(metadata)
|
62
|
-
@column ||= self.class.column_factory.new(
|
63
|
-
name,
|
64
|
-
default_value,
|
65
|
-
mysql_metadata,
|
66
|
-
null_value
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Gets the DEFAULT value the column takes as specified in the
|
71
|
-
# definition, if any
|
72
|
-
#
|
73
|
-
# @return [String, NilClass]
|
74
|
-
def default_value
|
75
|
-
match = if definition =~ /timestamp|datetime/i
|
76
|
-
/default '?(.+[^'])'?/i.match(definition)
|
77
|
-
else
|
78
|
-
/default '?(\w+)'?/i.match(definition)
|
79
|
-
end
|
80
|
-
|
81
|
-
return unless match
|
82
|
-
|
83
|
-
match[1].downcase != 'null' ? match[1] : nil
|
84
|
-
end
|
85
|
-
|
86
|
-
# Checks whether the column accepts NULL as specified in the definition
|
87
|
-
#
|
88
|
-
# @return [Boolean]
|
89
|
-
def null_value
|
90
|
-
match = /((\w*) NULL)/i.match(definition)
|
91
|
-
return true unless match
|
92
|
-
|
93
|
-
match[2].downcase == 'not' ? false : true
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
data/lib/lhm/column_with_type.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Lhm
|
2
|
-
# Abstracts the details of a table column definition when specified with a type
|
3
|
-
# as a symbol. This is the regular ActiveRecord's #add_column syntax:
|
4
|
-
#
|
5
|
-
# add_column :tablenames, :field, :string
|
6
|
-
#
|
7
|
-
class ColumnWithType
|
8
|
-
# Constructor
|
9
|
-
#
|
10
|
-
# @param name [String, Symbol]
|
11
|
-
# @param definition [Symbol]
|
12
|
-
def initialize(name, definition)
|
13
|
-
@name = name
|
14
|
-
@definition = definition
|
15
|
-
end
|
16
|
-
|
17
|
-
# Returns the column data as an Array to be used with the splat operator.
|
18
|
-
# See Lhm::Adaper#add_column
|
19
|
-
#
|
20
|
-
# @return [Array]
|
21
|
-
def attributes
|
22
|
-
[definition]
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
attr_reader :definition
|
28
|
-
end
|
29
|
-
end
|