pt-osc 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +6 -0
- data/LICENSE +19 -0
- data/README.md +1 -15
- data/lib/active_record/pt_osc_migration.rb +16 -0
- data/lib/pt-osc/version.rb +1 -1
- data/pt-osc.gemspec +4 -3
- data/test/functional/pt_osc_migration_functional_test.rb +40 -0
- metadata +37 -63
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 99c1ea4748db0541d8a8b7498d46dade6872599c
|
4
|
+
data.tar.gz: ce1bf7394309e17f504a34f39a75bf588c43502e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 628180e46c7e0d2965aa8942429c6a9cf041f8b1fcb0926bc5295ff5f8b3865c47c6cca83af4635144b82d51189da6eb14811cd2f47a689751e0b0b09defceec
|
7
|
+
data.tar.gz: d7fe01bebb0fca9247c6d9dd51966bb19c3bd59f0ff074a78443e9b474b3066f2cd4b752c06f415ef5dac6eda29929df067a411e3ad833d1b6597616430f6c80
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.2.5
|
2
|
+
|
3
|
+
- added version requirement to mysql2 gem to keep things from breaking (thanks @taavi!) [#15]
|
4
|
+
- prevent potentially dangerous usage of `execute` within a pt-osc (thanks @taavi!) [#16]
|
5
|
+
- reconnect to MySQL if connection timed out during pt-osc execution (thanks @jongrieman!) [#17]
|
6
|
+
|
1
7
|
## 0.2.4
|
2
8
|
|
3
9
|
- relaxed version requirements for bundler and activerecord-import
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2015 Steve Rice
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ Additional/modified options for the `percona` hash include:
|
|
42
42
|
- `check-alter`: When set to `false`, `ALTER` commands will not be checked when executing (same as [`--no-check-alter`](http://www.percona.com/doc/percona-toolkit/2.1/pt-online-schema-change.html#cmdoption-pt-online-schema-change--%5Bno%5Dcheck-alter))
|
43
43
|
- `run_mode`: Specify `'execute'` to actually run `pt-online-schema-change` when the migration runs. Specify `'print'` to output the commands to run to STDOUT instead. Default is `'print'`.
|
44
44
|
- `log`: Specify the file used for logging activity. Can be a relative or absolute path.
|
45
|
-
- `
|
45
|
+
- `user`: By default, the command will use the username given in your standard database config. Specify a username here to override. Specify `false` to omit username (such as when using a `defaults-file`.
|
46
46
|
- `password`: By default, the command will use the password given in your standard database config. Specify a password here to override. Specify `false` to omit password (such as when using a `defaults-file`.
|
47
47
|
|
48
48
|
#### Migrations
|
@@ -82,17 +82,3 @@ Support for other versions of these tools is unknown and not guaranteed.
|
|
82
82
|
`pt-osc` requires the use of `pt-online-schema-change` 2.0 or later. Some options may not work with all versions.
|
83
83
|
|
84
84
|
`pt-osc` is compatible with versions 0.5.0 and later of [zdennis/activerecord-import](https://github.com/zdennis/activerecord-import). It will not work with earlier versions.
|
85
|
-
|
86
|
-
#License and Copyright
|
87
|
-
Copyright (c) 2014, PagerDuty
|
88
|
-
All rights reserved.
|
89
|
-
|
90
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
91
|
-
|
92
|
-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
93
|
-
|
94
|
-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
95
|
-
|
96
|
-
* Neither the name of [project] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
97
|
-
|
98
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -3,6 +3,18 @@ require 'active_record/connection_adapters/mysql_pt_osc_adapter'
|
|
3
3
|
require 'shellwords'
|
4
4
|
|
5
5
|
module ActiveRecord
|
6
|
+
class Migrator
|
7
|
+
alias_method :record_version_state_after_migrating_without_reconnect, :record_version_state_after_migrating
|
8
|
+
|
9
|
+
def record_version_state_after_migrating(version)
|
10
|
+
ActiveRecord::Base.logger.debug 'Verifying active connections prior to recording version' if ActiveRecord::Base.logger
|
11
|
+
ActiveRecord::Base.verify_active_connections! # Reconnect to DB if it's gone away while we were migrating.
|
12
|
+
record_version_state_after_migrating_without_reconnect(version)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class UnsupportedMigrationError < ActiveRecordError; end
|
17
|
+
|
6
18
|
class PtOscMigration < Migration
|
7
19
|
# @TODO whitelist all valid pt-osc flags
|
8
20
|
PERCONA_FLAGS = {
|
@@ -263,5 +275,9 @@ module ActiveRecord
|
|
263
275
|
flag
|
264
276
|
end
|
265
277
|
end
|
278
|
+
|
279
|
+
def execute(sql)
|
280
|
+
raise ActiveRecord::UnsupportedMigrationError.new("Raw `execute` isn't supported by the pt-osc gem.")
|
281
|
+
end
|
266
282
|
end
|
267
283
|
end
|
data/lib/pt-osc/version.rb
CHANGED
data/pt-osc.gemspec
CHANGED
@@ -7,7 +7,8 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'pt-osc'
|
8
8
|
spec.version = Pt::Osc::VERSION
|
9
9
|
spec.authors = ['Steve Rice']
|
10
|
-
spec.email = ['steve@
|
10
|
+
spec.email = ['steve@steverice.org']
|
11
|
+
spec.license = 'MIT'
|
11
12
|
spec.summary = 'Rails migrations via pt-online-schema-change'
|
12
13
|
spec.description = 'Runs regular Rails/ActiveRecord migrations via the Percona Toolkit pt-online-schema-change tool.'
|
13
14
|
spec.homepage = 'https://github.com/steverice/pt-osc'
|
@@ -17,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
17
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
19
|
spec.require_paths = ['lib']
|
19
20
|
|
20
|
-
spec.add_development_dependency 'bundler', '>= 1.
|
21
|
+
spec.add_development_dependency 'bundler', '>= 1.10'
|
21
22
|
spec.add_development_dependency 'rake'
|
22
23
|
spec.add_development_dependency 'shoulda'
|
23
24
|
spec.add_development_dependency 'faker'
|
@@ -29,5 +30,5 @@ Gem::Specification.new do |spec|
|
|
29
30
|
spec.add_development_dependency 'activerecord-import', '>= 0.5.0'
|
30
31
|
|
31
32
|
spec.add_runtime_dependency 'activerecord', '~> 3.2'
|
32
|
-
spec.add_runtime_dependency 'mysql2'
|
33
|
+
spec.add_runtime_dependency 'mysql2', '~> 0.3.10'
|
33
34
|
end
|
@@ -38,6 +38,31 @@ class PtOscMigrationFunctionalTest < ActiveRecord::TestCase
|
|
38
38
|
ActiveRecord::Base.connection.execute "DROP TABLE IF EXISTS `#{@table_name}`;"
|
39
39
|
end
|
40
40
|
|
41
|
+
context 'a raw SQL execute migration' do
|
42
|
+
setup do
|
43
|
+
TestMigration.class_eval <<-EVAL
|
44
|
+
def up
|
45
|
+
execute 'SELECT 1'
|
46
|
+
end
|
47
|
+
EVAL
|
48
|
+
@migration.expects(:print_pt_osc).never
|
49
|
+
@migration.expects(:execute_pt_osc).never
|
50
|
+
@migration.connection.expects(:execute).never
|
51
|
+
end
|
52
|
+
|
53
|
+
teardown do
|
54
|
+
@migration.unstub(:print_pt_osc)
|
55
|
+
@migration.unstub(:execute_pt_osc)
|
56
|
+
@migration.connection.unstub(:execute)
|
57
|
+
end
|
58
|
+
|
59
|
+
should 'throw an exception' do
|
60
|
+
assert_raise ActiveRecord::UnsupportedMigrationError do
|
61
|
+
@migration.migrate(:up)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
41
66
|
context 'a migration with only ALTER statements' do
|
42
67
|
setup do
|
43
68
|
@renamed_column_name = 'foobar'
|
@@ -154,3 +179,18 @@ class PtOscMigrationFunctionalTest < ActiveRecord::TestCase
|
|
154
179
|
end
|
155
180
|
end
|
156
181
|
end
|
182
|
+
|
183
|
+
class PtOscMigrationMigratorFunctionalTest < ActiveRecord::TestCase
|
184
|
+
class TestMigrator < ActiveRecord::Migrator; end
|
185
|
+
|
186
|
+
context 'updating version post migration' do
|
187
|
+
setup do
|
188
|
+
@migrator = TestMigrator.new(nil, nil)
|
189
|
+
end
|
190
|
+
|
191
|
+
should 'verify connections before recording version' do
|
192
|
+
ActiveRecord::Base.connection.raw_connection.close
|
193
|
+
@migrator.send(:record_version_state_after_migrating, 0)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
metadata
CHANGED
@@ -1,188 +1,168 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pt-osc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Steve Rice
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '1.
|
19
|
+
version: '1.10'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1.
|
26
|
+
version: '1.10'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: shoulda
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: faker
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: mocha
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: 0.9.0
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: 0.9.0
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: rails
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- - ~>
|
87
|
+
- - "~>"
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '3.2'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- - ~>
|
94
|
+
- - "~>"
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '3.2'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: sqlite3
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - ">="
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
|
-
- -
|
108
|
+
- - ">="
|
124
109
|
- !ruby/object:Gem::Version
|
125
110
|
version: '0'
|
126
111
|
- !ruby/object:Gem::Dependency
|
127
112
|
name: activerecord-import
|
128
113
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
114
|
requirements:
|
131
|
-
- -
|
115
|
+
- - ">="
|
132
116
|
- !ruby/object:Gem::Version
|
133
117
|
version: 0.5.0
|
134
118
|
type: :development
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
121
|
requirements:
|
139
|
-
- -
|
122
|
+
- - ">="
|
140
123
|
- !ruby/object:Gem::Version
|
141
124
|
version: 0.5.0
|
142
125
|
- !ruby/object:Gem::Dependency
|
143
126
|
name: activerecord
|
144
127
|
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
128
|
requirements:
|
147
|
-
- - ~>
|
129
|
+
- - "~>"
|
148
130
|
- !ruby/object:Gem::Version
|
149
131
|
version: '3.2'
|
150
132
|
type: :runtime
|
151
133
|
prerelease: false
|
152
134
|
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
135
|
requirements:
|
155
|
-
- - ~>
|
136
|
+
- - "~>"
|
156
137
|
- !ruby/object:Gem::Version
|
157
138
|
version: '3.2'
|
158
139
|
- !ruby/object:Gem::Dependency
|
159
140
|
name: mysql2
|
160
141
|
requirement: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
142
|
requirements:
|
163
|
-
- -
|
143
|
+
- - "~>"
|
164
144
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
145
|
+
version: 0.3.10
|
166
146
|
type: :runtime
|
167
147
|
prerelease: false
|
168
148
|
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
149
|
requirements:
|
171
|
-
- -
|
150
|
+
- - "~>"
|
172
151
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
152
|
+
version: 0.3.10
|
174
153
|
description: Runs regular Rails/ActiveRecord migrations via the Percona Toolkit pt-online-schema-change
|
175
154
|
tool.
|
176
155
|
email:
|
177
|
-
- steve@
|
156
|
+
- steve@steverice.org
|
178
157
|
executables: []
|
179
158
|
extensions: []
|
180
159
|
extra_rdoc_files: []
|
181
160
|
files:
|
182
|
-
- .gitignore
|
183
|
-
- .travis.yml
|
161
|
+
- ".gitignore"
|
162
|
+
- ".travis.yml"
|
184
163
|
- CHANGELOG.md
|
185
164
|
- Gemfile
|
165
|
+
- LICENSE
|
186
166
|
- README.md
|
187
167
|
- Rakefile
|
188
168
|
- lib/active_record/connection_adapters/mysql_pt_osc_adapter.rb
|
@@ -235,34 +215,28 @@ files:
|
|
235
215
|
- test/unit/mysql_pt_osc_adapter_test.rb
|
236
216
|
- test/unit/pt_osc_migration_unit_test.rb
|
237
217
|
homepage: https://github.com/steverice/pt-osc
|
238
|
-
licenses:
|
218
|
+
licenses:
|
219
|
+
- MIT
|
220
|
+
metadata: {}
|
239
221
|
post_install_message:
|
240
222
|
rdoc_options: []
|
241
223
|
require_paths:
|
242
224
|
- lib
|
243
225
|
required_ruby_version: !ruby/object:Gem::Requirement
|
244
|
-
none: false
|
245
226
|
requirements:
|
246
|
-
- -
|
227
|
+
- - ">="
|
247
228
|
- !ruby/object:Gem::Version
|
248
229
|
version: '0'
|
249
|
-
segments:
|
250
|
-
- 0
|
251
|
-
hash: 3289951028780613662
|
252
230
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
253
|
-
none: false
|
254
231
|
requirements:
|
255
|
-
- -
|
232
|
+
- - ">="
|
256
233
|
- !ruby/object:Gem::Version
|
257
234
|
version: '0'
|
258
|
-
segments:
|
259
|
-
- 0
|
260
|
-
hash: 3289951028780613662
|
261
235
|
requirements: []
|
262
236
|
rubyforge_project:
|
263
|
-
rubygems_version:
|
237
|
+
rubygems_version: 2.2.2
|
264
238
|
signing_key:
|
265
|
-
specification_version:
|
239
|
+
specification_version: 4
|
266
240
|
summary: Rails migrations via pt-online-schema-change
|
267
241
|
test_files:
|
268
242
|
- test/config/database.yml
|