percona_ar 0.1.4 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74aa2892abe01b7bfdf7b2d76c7a2280988f0ce6
4
- data.tar.gz: 3a9d05ab76286e3b69efb064a924c15efc9541c0
3
+ metadata.gz: '08f2af03efb53e6609e056679802973a175aaf3b'
4
+ data.tar.gz: a53808c378db1b478664226f11ecb7f7bd11115c
5
5
  SHA512:
6
- metadata.gz: 7b60c5dd9df628354ed4301d8ccd08299e0543082fe58034fe61579d9262f09137b96c8502076a5531ece33a6ddaf27ca6ccc0705ebeea4426f1d9d04f3f8aee
7
- data.tar.gz: 719338d2f6eb607b66ceddea7c148f9a2e28c5411badcf962701336bc9d24e9e5295ca118a69f62be2c0d2eda0aba7d13222ce5bc8c8724df9419981c4b54a7f
6
+ metadata.gz: b59b29776cbefbe1a4320ee011f1f6ffc7ddf25871fbeab81a56cd4a3eeff09696a62ce783d50337e49fb13b3db819de46e4fdcd7c3ac030567ff34aab58356e
7
+ data.tar.gz: b54a20272536118359e67cc537f4d848e0a932310d1192539082a89a61008f53f90ba2f77a822292a1b2ffc33e66c7448958b1610a1942775d746ae07ad353f3
@@ -0,0 +1,27 @@
1
+ * Generate valid MySQL syntax when executing ALTER statements for NOT NULL columns that have string default values
2
+
3
+ *Brian Cheung*
4
+
5
+ * enable to override connection
6
+
7
+ *Bonty Shushusha*
8
+
9
+ * add compatibility for rails 5
10
+
11
+ *James Mac William*
12
+
13
+ * Added Documentation for Alternate Connections
14
+
15
+ *Kaid Shajrah*
16
+
17
+ * Added support for DROP INDEX
18
+
19
+ *Roderick Monje*
20
+
21
+ * Ensure that alter statements without backticks work
22
+
23
+ *James Mac William*
24
+
25
+ * Added support for CREATE INDEX
26
+
27
+ *Roderick Monje*
data/README.md CHANGED
@@ -3,12 +3,6 @@
3
3
  [![Build
4
4
  Status](https://travis-ci.org/jamesmacwilliam/percona_ar.svg?branch=master)](https://travis-ci.org/jamesmacwilliam/percona_ar)
5
5
 
6
- [![Code
7
- Climate](https://codeclimate.com/github/jamesmacwilliam/percona_ar/badges/gpa.svg)](https://codeclimate.com/github/jamesmacwilliam/percona_ar)
8
-
9
- [![Test
10
- Coverage](https://codeclimate.com/github/jamesmacwilliam/percona_ar/badges/coverage.svg)](https://codeclimate.com/github/jamesmacwilliam/percona_ar/coverage)
11
-
12
6
  This gem adds another tool in your belt for rails migrations. You can
13
7
  stil generate migrations, and they will function just as they always
14
8
  have, but there is also the option of generating percona_ar migrations,
@@ -52,6 +46,22 @@ https://www.percona.com/doc/percona-toolkit/2.1/pt-online-schema-change.html
52
46
  version gets added to schema_migrations, and rails yells at you if you
53
47
  haven't yet migrated.
54
48
 
49
+ - Example:
50
+ ```Ruby
51
+ class SomeMigration < PerconaAr::Migration
52
+ def change
53
+ # ALTER commands will get run by the Percona tool,
54
+ # all other commands will get run by ActiveRecord
55
+ add_column :users, :foo, :string
56
+ end
57
+
58
+ # Optional uses ActiveRecord by default
59
+ def connection
60
+ @percona_connection ||= PerconaAr::Connection.new(SomeModel.connection)
61
+ end
62
+ end
63
+ ```
64
+
55
65
  ## Development
56
66
 
57
67
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -66,4 +76,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jamesm
66
76
  ## License
67
77
 
68
78
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
69
-
@@ -1,11 +1,17 @@
1
- class PerconaAr::Migration < ActiveRecord::Migration
1
+ if ActiveRecord.gem_version >= Gem::Version.new('5.0')
2
+ class PerconaAr::Migration < ActiveRecord::Migration[4.2]; end
3
+ else
4
+ class PerconaAr::Migration < ActiveRecord::Migration; end
5
+ end
6
+
7
+ PerconaAr::Migration.class_eval do
2
8
  def connection
3
9
  @percona_connection ||=
4
10
  PerconaAr::Connection.new(ActiveRecord::Base.connection)
5
11
  end
6
12
 
7
13
  def migrate(*args)
8
- $query_builder = PerconaAr::QueryBuilder.new
14
+ $query_builder = PerconaAr::QueryBuilder.new connection
9
15
  super
10
16
  $query_builder.execute
11
17
  end
@@ -4,11 +4,12 @@ require 'rake/file_utils'
4
4
  class PerconaAr::PtOnlineSchemaChangeExecutor
5
5
  include FileUtils
6
6
 
7
- attr_accessor :sql, :table
7
+ attr_accessor :sql, :table, :conn
8
8
 
9
- def initialize(table, sql)
9
+ def initialize(table, sql, conn = ActiveRecord::Base.connection)
10
10
  @table = table
11
11
  @sql = sql
12
+ @conn = conn
12
13
  end
13
14
 
14
15
  def call
@@ -18,7 +19,7 @@ class PerconaAr::PtOnlineSchemaChangeExecutor
18
19
  private
19
20
 
20
21
  def suffix(table, cmd)
21
- %Q('#{cmd.gsub("'","\"")}' --recursion-method none --no-check-alter --execute D=#{config[:database]},t=#{table})
22
+ %Q('#{cmd.gsub("'","\"")}' --recursion-method none --no-check-alter --alter-foreign-keys-method 'auto' --execute D=#{config[:database]},t=#{table})
22
23
  end
23
24
 
24
25
  def boilerplate
@@ -26,6 +27,6 @@ class PerconaAr::PtOnlineSchemaChangeExecutor
26
27
  end
27
28
 
28
29
  def config
29
- ActiveRecord::Base.connection_config
30
+ conn.instance_variable_get(:@config)
30
31
  end
31
32
  end
@@ -1,17 +1,23 @@
1
1
  class PerconaAr::QueryBuilder
2
- def initialize
2
+ def initialize(conn = ActiveRecord::Base.connection)
3
3
  @tables = Hash.new {|h, k| h[k] = [] }
4
+ @conn = conn
4
5
  end
5
6
 
6
7
  def execute
7
8
  @tables.each do |table, snippets|
8
- PerconaAr::PtOnlineSchemaChangeExecutor.new(table, snippets.join(", ")).call
9
+ PerconaAr::PtOnlineSchemaChangeExecutor.new(table, snippets.join(", "), @conn).call
9
10
  end
10
11
  end
11
12
 
12
13
  def add(sql)
13
- if sql =~ /^ALTER TABLE `([^`]*)` (.*)/i
14
+ if sql =~ /^ALTER TABLE `?([^ `]*)`? (.*)/i
14
15
  @tables[$1.to_s] << get_sql_for($2)
16
+ elsif sql =~ /DROP INDEX/i
17
+ drop_clause, table = sql.split(/ ON /i)
18
+ @tables[table.delete('`')] << get_sql_for(drop_clause)
19
+ elsif sql =~ /CREATE INDEX (`?[^ ]*) ON `?([^ `]*)`? (.*)/i
20
+ @tables[$2] << get_sql_for("ADD INDEX #{$1} #{$3}")
15
21
  end
16
22
  self
17
23
  end
@@ -20,6 +26,7 @@ class PerconaAr::QueryBuilder
20
26
 
21
27
  def get_sql_for(cmd)
22
28
  return cmd unless cmd =~ /DROP/i && !(cmd =~ /COLUMN/i)
29
+ return cmd if cmd =~ /DROP INDEX/i
23
30
  cmd.gsub(/DROP/i, "DROP COLUMN")
24
31
  end
25
32
 
@@ -1,3 +1,3 @@
1
1
  module PerconaAr
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -18,11 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.10"
22
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rails", ">= 4.0.0"
24
24
  spec.add_development_dependency "mysql2", ">= 0.3.0"
25
- spec.add_development_dependency "codeclimate-test-reporter"
26
- spec.add_development_dependency "coveralls"
27
25
  spec.add_development_dependency "rspec"
28
26
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percona_ar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mac William
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-06 00:00:00.000000000 Z
11
+ date: 2017-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,34 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.3.0
69
- - !ruby/object:Gem::Dependency
70
- name: codeclimate-test-reporter
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: coveralls
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
70
  name: rspec
99
71
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +90,7 @@ files:
118
90
  - ".gitignore"
119
91
  - ".rspec"
120
92
  - ".travis.yml"
93
+ - CHANGELOG.md
121
94
  - CODE_OF_CONDUCT.md
122
95
  - Gemfile
123
96
  - LICENSE.txt
@@ -153,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
126
  version: '0'
154
127
  requirements: []
155
128
  rubyforge_project:
156
- rubygems_version: 2.4.5.1
129
+ rubygems_version: 2.6.11
157
130
  signing_key:
158
131
  specification_version: 4
159
132
  summary: Use Percona (pt-online-schema-change) for migrations generated with this