percona_ar 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/console +1 -1
- data/lib/percona_ar/connection.rb +1 -1
- data/lib/percona_ar/migration.rb +6 -0
- data/lib/percona_ar/pt_online_schema_change_executor.rb +5 -11
- data/lib/percona_ar/query_builder.rb +26 -0
- data/lib/percona_ar/version.rb +1 -1
- data/lib/percona_ar.rb +1 -0
- metadata +3 -3
- data/percona_ar-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 346cb4b9523c0748011df09c3b62811a47a05049
|
4
|
+
data.tar.gz: cee3ce9670f95fa150451c208ce6d2d5be58129f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee6ac997a9128c010ed2fcd586ba8f08d92b81dc21ad9a585095a44911dd938509366d5b3791426bc48b16d71938bd2b2302adf93879630b16cfbe2e3fee29a9
|
7
|
+
data.tar.gz: b1656bbe29212bdacb414296541dfbf016a308b4274b221631bdbf3deaa11f49c82f4e5ee61766985ae15a90b44e56edef0037d8ce3e8b4cc6fc383f45b7a328
|
data/README.md
CHANGED
@@ -60,7 +60,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
60
60
|
|
61
61
|
## Contributing
|
62
62
|
|
63
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
63
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jamesmacwilliam/percona_ar. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](CODE_OF_CONDUCT.md) code of conduct.
|
64
64
|
|
65
65
|
|
66
66
|
## License
|
data/bin/console
CHANGED
@@ -10,7 +10,7 @@ class PerconaAr::Connection < ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
|
10
10
|
|
11
11
|
def execute(sql, name = nil)
|
12
12
|
return super unless sql =~ /^ALTER TABLE.*/
|
13
|
-
|
13
|
+
$query_builder.add sql
|
14
14
|
end
|
15
15
|
|
16
16
|
def not_implemented(*)
|
data/lib/percona_ar/migration.rb
CHANGED
@@ -4,27 +4,21 @@ require 'rake/file_utils'
|
|
4
4
|
class PerconaAr::PtOnlineSchemaChangeExecutor
|
5
5
|
include FileUtils
|
6
6
|
|
7
|
-
attr_accessor :sql
|
7
|
+
attr_accessor :sql, :table
|
8
8
|
|
9
|
-
def initialize(sql)
|
9
|
+
def initialize(table, sql)
|
10
|
+
@table = table
|
10
11
|
@sql = sql
|
11
12
|
end
|
12
13
|
|
13
14
|
def call
|
14
|
-
|
15
|
-
sh "#{boilerplate}#{suffix($1, $2)}"
|
16
|
-
end
|
15
|
+
sh "#{boilerplate}#{suffix(table, sql)}"
|
17
16
|
end
|
18
17
|
|
19
18
|
private
|
20
19
|
|
21
20
|
def suffix(table, cmd)
|
22
|
-
"'#{
|
23
|
-
end
|
24
|
-
|
25
|
-
def get_sql_for(cmd)
|
26
|
-
return cmd unless cmd =~ /DROP/i && !(cmd =~ /COLUMN/i)
|
27
|
-
cmd.gsub(/DROP/i, "DROP COLUMN")
|
21
|
+
"'#{cmd}' --recursion-method none --no-check-alter --execute D=#{config[:database]},t=#{table}"
|
28
22
|
end
|
29
23
|
|
30
24
|
def boilerplate
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class PerconaAr::QueryBuilder
|
2
|
+
def initialize
|
3
|
+
@tables = Hash.new {|h, k| h[k] = [] }
|
4
|
+
end
|
5
|
+
|
6
|
+
def execute
|
7
|
+
@tables.each do |table, snippets|
|
8
|
+
PerconaAr::PtOnlineSchemaChangeExecutor.new(table, snippets.join(", ")).call
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def add(sql)
|
13
|
+
if sql =~ /^ALTER TABLE `([^`]*)` (.*)/i
|
14
|
+
@tables[$1.to_s] << get_sql_for($2)
|
15
|
+
end
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def get_sql_for(cmd)
|
22
|
+
return cmd unless cmd =~ /DROP/i && !(cmd =~ /COLUMN/i)
|
23
|
+
cmd.gsub(/DROP/i, "DROP COLUMN")
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/percona_ar/version.rb
CHANGED
data/lib/percona_ar.rb
CHANGED
@@ -3,6 +3,7 @@ require "active_record"
|
|
3
3
|
require "active_record/connection_adapters/mysql2_adapter"
|
4
4
|
require "percona_ar/version"
|
5
5
|
require "percona_ar/pt_online_schema_change_executor"
|
6
|
+
require "percona_ar/query_builder"
|
6
7
|
require "percona_ar/connection"
|
7
8
|
require "percona_ar/migration"
|
8
9
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percona_ar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
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-
|
11
|
+
date: 2016-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,8 +130,8 @@ files:
|
|
130
130
|
- lib/percona_ar/connection.rb
|
131
131
|
- lib/percona_ar/migration.rb
|
132
132
|
- lib/percona_ar/pt_online_schema_change_executor.rb
|
133
|
+
- lib/percona_ar/query_builder.rb
|
133
134
|
- lib/percona_ar/version.rb
|
134
|
-
- percona_ar-0.1.0.gem
|
135
135
|
- percona_ar.gemspec
|
136
136
|
homepage: https://github.com/jamesmacwilliam/percona_ar
|
137
137
|
licenses:
|
data/percona_ar-0.1.0.gem
DELETED
Binary file
|