departure-76c9880 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +8 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +60 -0
  6. data/.travis.yml +30 -0
  7. data/CHANGELOG.md +192 -0
  8. data/CODE_OF_CONDUCT.md +50 -0
  9. data/Dockerfile +32 -0
  10. data/Gemfile +6 -0
  11. data/LICENSE.txt +22 -0
  12. data/README.md +227 -0
  13. data/RELEASING.md +17 -0
  14. data/Rakefile +17 -0
  15. data/bin/console +14 -0
  16. data/bin/rspec +16 -0
  17. data/bin/setup +7 -0
  18. data/config.yml.erb +4 -0
  19. data/configuration.rb +16 -0
  20. data/departure.gemspec +35 -0
  21. data/docker-compose.yml +23 -0
  22. data/lib/active_record/connection_adapters/for_alter.rb +91 -0
  23. data/lib/active_record/connection_adapters/percona_adapter.rb +168 -0
  24. data/lib/departure.rb +43 -0
  25. data/lib/departure/alter_argument.rb +49 -0
  26. data/lib/departure/cli_generator.rb +84 -0
  27. data/lib/departure/command.rb +96 -0
  28. data/lib/departure/configuration.rb +20 -0
  29. data/lib/departure/connection_base.rb +9 -0
  30. data/lib/departure/connection_details.rb +96 -0
  31. data/lib/departure/dsn.rb +24 -0
  32. data/lib/departure/errors.rb +39 -0
  33. data/lib/departure/log_sanitizers/password_sanitizer.rb +22 -0
  34. data/lib/departure/logger.rb +42 -0
  35. data/lib/departure/logger_factory.rb +16 -0
  36. data/lib/departure/migration.rb +96 -0
  37. data/lib/departure/null_logger.rb +15 -0
  38. data/lib/departure/option.rb +75 -0
  39. data/lib/departure/railtie.rb +21 -0
  40. data/lib/departure/runner.rb +62 -0
  41. data/lib/departure/user_options.rb +44 -0
  42. data/lib/departure/version.rb +3 -0
  43. data/lib/lhm.rb +23 -0
  44. data/lib/lhm/adapter.rb +107 -0
  45. data/lib/lhm/column_with_sql.rb +96 -0
  46. data/lib/lhm/column_with_type.rb +29 -0
  47. data/test_database.rb +80 -0
  48. metadata +245 -0
@@ -0,0 +1,96 @@
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::DepartureAdapter::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
@@ -0,0 +1,29 @@
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
@@ -0,0 +1,80 @@
1
+ require 'active_record'
2
+ require 'active_record/connection_adapters/mysql2_adapter'
3
+
4
+ # Setups the test database with the schema_migrations table that ActiveRecord
5
+ # requires for the migrations, plus a table for the Comment model used throught
6
+ # the tests.
7
+ #
8
+ class TestDatabase
9
+ # Constructor
10
+ #
11
+ # @param config [Hash]
12
+ def initialize(config)
13
+ @config = config
14
+ @database = config['database']
15
+ end
16
+
17
+ # Creates the test database, the schema_migrations and the comments tables.
18
+ # It drops any of them if they already exist
19
+ def setup
20
+ setup_test_database
21
+ drop_and_create_schema_migrations_table
22
+ end
23
+
24
+ # Creates the #{@database} database and the comments table in it.
25
+ # Before, it drops both if they already exist
26
+ def setup_test_database
27
+ drop_and_create_test_database
28
+ drop_and_create_comments_table
29
+ end
30
+
31
+ # Creates the ActiveRecord's schema_migrations table required for
32
+ # migrations to work. Before, it drops the table if it already exists
33
+ def drop_and_create_schema_migrations_table
34
+ sql = [
35
+ "USE #{@database}",
36
+ 'DROP TABLE IF EXISTS schema_migrations',
37
+ 'CREATE TABLE schema_migrations ( version varchar(255) COLLATE utf8_unicode_ci NOT NULL, UNIQUE KEY unique_schema_migrations (version)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci'
38
+ ]
39
+
40
+ run_commands(sql)
41
+ end
42
+
43
+ private
44
+
45
+ attr_reader :config, :database
46
+
47
+ def drop_and_create_test_database
48
+ sql = [
49
+ "DROP DATABASE IF EXISTS #{@database}",
50
+ "CREATE DATABASE #{@database} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci"
51
+ ]
52
+
53
+ run_commands(sql)
54
+ end
55
+
56
+ def drop_and_create_comments_table
57
+ sql = [
58
+ "USE #{@database}",
59
+ 'DROP TABLE IF EXISTS comments',
60
+ 'CREATE TABLE comments ( id bigint(20) NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci'
61
+ ]
62
+
63
+ run_commands(sql)
64
+ end
65
+
66
+ def run_commands(sql)
67
+ conn.execute('START TRANSACTION')
68
+ sql.each { |str| conn.execute(str) }
69
+ conn.execute('COMMIT')
70
+ end
71
+
72
+ def conn
73
+ @conn ||= ActiveRecord::Base.mysql2_connection(
74
+ host: @config['hostname'],
75
+ username: @config['username'],
76
+ password: @config['password'],
77
+ reconnect: true
78
+ )
79
+ end
80
+ end
metadata ADDED
@@ -0,0 +1,245 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: departure-76c9880
3
+ version: !ruby/object:Gem::Version
4
+ version: 6.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Ilya Zayats
8
+ - Pau Pérez
9
+ - Fran Casas
10
+ - Jorge Morante
11
+ - Enrico Stano
12
+ - Adrian Serafin
13
+ - Kirk Haines
14
+ - Guillermo Iguaran
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+ date: 2020-11-11 00:00:00.000000000 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: railties
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ - - "<"
28
+ - !ruby/object:Gem::Version
29
+ version: '6.1'
30
+ type: :runtime
31
+ prerelease: false
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 5.2.0
37
+ - - "<"
38
+ - !ruby/object:Gem::Version
39
+ version: '6.1'
40
+ - !ruby/object:Gem::Dependency
41
+ name: activerecord
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 5.2.0
47
+ - - "<"
48
+ - !ruby/object:Gem::Version
49
+ version: '6.1'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 5.2.0
57
+ - - "<"
58
+ - !ruby/object:Gem::Version
59
+ version: '6.1'
60
+ - !ruby/object:Gem::Dependency
61
+ name: mysql2
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.4.0
67
+ - - "<="
68
+ - !ruby/object:Gem::Version
69
+ version: 0.5.3
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 0.4.0
77
+ - - "<="
78
+ - !ruby/object:Gem::Version
79
+ version: 0.5.3
80
+ - !ruby/object:Gem::Dependency
81
+ name: rake
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '10.0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '10.0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '3.4'
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.4.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.4'
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 3.4.0
114
+ - !ruby/object:Gem::Dependency
115
+ name: rspec-its
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: '1.2'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '1.2'
128
+ - !ruby/object:Gem::Dependency
129
+ name: byebug
130
+ requirement: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: '8.2'
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: 8.2.1
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '8.2'
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: 8.2.1
148
+ - !ruby/object:Gem::Dependency
149
+ name: climate_control
150
+ requirement: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - "~>"
153
+ - !ruby/object:Gem::Version
154
+ version: 0.0.3
155
+ type: :development
156
+ prerelease: false
157
+ version_requirements: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: 0.0.3
162
+ description: Execute your ActiveRecord migrations with Percona's pt-online-schema-change.
163
+ Formerly known as Percona Migrator.
164
+ email:
165
+ - ilya.zayats@redbooth.com
166
+ - pau.perez@redbooth.com
167
+ - nflamel@gmail.com
168
+ - jorge.morante@redbooth.com
169
+ - adrian@softmad.pl
170
+ - wyhaines@gmail.com
171
+ - guilleiguaran@gmail.com
172
+ executables: []
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - ".codeclimate.yml"
177
+ - ".gitignore"
178
+ - ".rspec"
179
+ - ".rubocop.yml"
180
+ - ".travis.yml"
181
+ - CHANGELOG.md
182
+ - CODE_OF_CONDUCT.md
183
+ - Dockerfile
184
+ - Gemfile
185
+ - LICENSE.txt
186
+ - README.md
187
+ - RELEASING.md
188
+ - Rakefile
189
+ - bin/console
190
+ - bin/rspec
191
+ - bin/setup
192
+ - config.yml.erb
193
+ - configuration.rb
194
+ - departure.gemspec
195
+ - docker-compose.yml
196
+ - lib/active_record/connection_adapters/for_alter.rb
197
+ - lib/active_record/connection_adapters/percona_adapter.rb
198
+ - lib/departure.rb
199
+ - lib/departure/alter_argument.rb
200
+ - lib/departure/cli_generator.rb
201
+ - lib/departure/command.rb
202
+ - lib/departure/configuration.rb
203
+ - lib/departure/connection_base.rb
204
+ - lib/departure/connection_details.rb
205
+ - lib/departure/dsn.rb
206
+ - lib/departure/errors.rb
207
+ - lib/departure/log_sanitizers/password_sanitizer.rb
208
+ - lib/departure/logger.rb
209
+ - lib/departure/logger_factory.rb
210
+ - lib/departure/migration.rb
211
+ - lib/departure/null_logger.rb
212
+ - lib/departure/option.rb
213
+ - lib/departure/railtie.rb
214
+ - lib/departure/runner.rb
215
+ - lib/departure/user_options.rb
216
+ - lib/departure/version.rb
217
+ - lib/lhm.rb
218
+ - lib/lhm/adapter.rb
219
+ - lib/lhm/column_with_sql.rb
220
+ - lib/lhm/column_with_type.rb
221
+ - test_database.rb
222
+ homepage: https://github.com/departurerb/departure
223
+ licenses:
224
+ - MIT
225
+ metadata: {}
226
+ post_install_message:
227
+ rdoc_options: []
228
+ require_paths:
229
+ - lib
230
+ required_ruby_version: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - ">="
233
+ - !ruby/object:Gem::Version
234
+ version: '0'
235
+ required_rubygems_version: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - ">="
238
+ - !ruby/object:Gem::Version
239
+ version: '0'
240
+ requirements: []
241
+ rubygems_version: 3.1.4
242
+ signing_key:
243
+ specification_version: 4
244
+ summary: pt-online-schema-change runner for ActiveRecord migrations
245
+ test_files: []