percona_ar 0.1.2 → 0.1.3

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: 28c1a24ca584e4a4a1dfeba924dad60cf31142c6
4
- data.tar.gz: ef25b39557b377cfc5516f1d04477db9ae3eb446
3
+ metadata.gz: 346cb4b9523c0748011df09c3b62811a47a05049
4
+ data.tar.gz: cee3ce9670f95fa150451c208ce6d2d5be58129f
5
5
  SHA512:
6
- metadata.gz: aaff99016bfc92169d1cc36d55c0b57d46e3d5434f8124df55626ca33b8feec495b0079f081f5bbc0e2daef7312df0b3d381515fbe69b6d921f7b4462fc43245
7
- data.tar.gz: 92102722a4bc59ca238c9eb55695de937a1302d5a1687dd12ff793e4a015dab909b169217f8c92a1d8b3f31de981ff691f2676d66f806e27ae1777e2c8d87027
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/[USERNAME]/percona_ar_migration. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
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
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "percona_ar_migration"
4
+ require "percona_ar"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -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
- PerconaAr::PtOnlineSchemaChangeExecutor.new(sql).call
13
+ $query_builder.add sql
14
14
  end
15
15
 
16
16
  def not_implemented(*)
@@ -3,4 +3,10 @@ class PerconaAr::Migration < ActiveRecord::Migration
3
3
  @percona_connection ||=
4
4
  PerconaAr::Connection.new(ActiveRecord::Base.connection)
5
5
  end
6
+
7
+ def migrate(*args)
8
+ $query_builder = PerconaAr::QueryBuilder.new
9
+ super
10
+ $query_builder.execute
11
+ end
6
12
  end
@@ -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
- if sql =~ /^ALTER TABLE `([^`]*)` (.*)/i
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
- "'#{get_sql_for(cmd)}' --recursion-method none --no-check-alter --execute D=#{config[:database]},t=#{table}"
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
@@ -1,3 +1,3 @@
1
1
  module PerconaAr
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-03-30 00:00:00.000000000 Z
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