simple_mysql_partitioning 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ce8903c7a2ba6be5858bf48135d131c5ee96d82
4
+ data.tar.gz: 97d3191402d133f1ab1ab8923f6900a8c5828ab5
5
+ SHA512:
6
+ metadata.gz: 177079c777b527d3ac276ce04acba578404413ec9bfd27a9d2b4cf107a19ec44681a7b256351f9257f950558a6fbfbf53db7f1a7da0860696a3945993e7d2f7b
7
+ data.tar.gz: 831a79beb7d786bdc061cc467b3fb9092a80fbf6b82a37b7dba597c05349f9955a2b54a9165dcdb3151a90de6ead3cfe3004d8386527872af2c8ca077ac4b148
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.3
7
+ before_install: gem install bundler -v 1.16.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in simple_mysql_partitioning.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # SimpleMysqlParitioning
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/simple_mysql_partitioning`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'simple_mysql_partitioning'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install simple_mysql_partitioning
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/simple_mysql_partitioning.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'simple_mysql_partitioning'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ version: '2'
2
+ services:
3
+ datastore:
4
+ image: busybox
5
+ volumes:
6
+ - bundle:/bundle
7
+ mysql:
8
+ image: mysql:5.7
9
+ ports:
10
+ - "3306:3306"
11
+ environment:
12
+ - MYSQL_ALLOW_EMPTY_PASSWORD=yes
13
+ volumes:
14
+ bundle:
15
+ driver: local
@@ -0,0 +1,9 @@
1
+ require 'simple_mysql_partitioning/version'
2
+ require 'active_record'
3
+ require 'mysql2'
4
+ require 'simple_mysql_partitioning/sql'
5
+ require 'simple_mysql_partitioning/executor'
6
+
7
+ module SimpleMysqlParitioning
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,37 @@
1
+ require 'active_record'
2
+ require 'simple_mysql_partitioning/sql'
3
+
4
+ module SimpleMySQLPartitioning
5
+ class Executor
6
+ def initialize(klass, partition_name)
7
+ @klass = klass
8
+ @table_name = @klass.table_name
9
+ @partition_name = partition_name
10
+ end
11
+
12
+ def add(less_than_value)
13
+ add_partition_sql = SQL.add_sql(@table_name, @partition_name, less_than_value)
14
+ @klass.connection.execute(add_partition_sql)
15
+ end
16
+
17
+ def reorganize(less_than_value, reorganize_partition_name)
18
+ @klass.connection.execute(
19
+ SQL.reorganize_sql(
20
+ @table_name,
21
+ @partition_name, less_than_value,
22
+ reorganize_partition_name
23
+ )
24
+ )
25
+ end
26
+
27
+ def exist?
28
+ @klass.connection.select_all(
29
+ SQL.exist_sql(@table_name, @partition_name)
30
+ ).to_hash.present?
31
+ end
32
+
33
+ def drop
34
+ @klass.connection.execute(SQL.parge_sql(@table_name, @partition_name))
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ module SimpleMySQLPartitioning
2
+ class SQL
3
+ class << self
4
+ def exist_sql(table_name, partition_name)
5
+ "SELECT
6
+ table_schema,
7
+ table_name,
8
+ partition_name,
9
+ partition_ordinal_position,
10
+ table_rows
11
+ FROM information_schema.partitions
12
+ WHERE table_name='#{table_name}'
13
+ AND partition_name='#{partition_name}'
14
+ LIMIT 1;"
15
+ end
16
+
17
+ def add_sql(table_name, partition_name, value)
18
+ "ALTER TABLE #{table_name}
19
+ ADD PARTITION ( PARTITION #{partition_name}
20
+ VALUES LESS THAN ('#{value}'));"
21
+ end
22
+
23
+ def reorganize_sql(table_name, partition_name, value, reorganize_partition_name, max_value = 'MAXVALUE')
24
+ "ALTER TABLE #{table_name}
25
+ REORGANIZE PARTITION #{reorganize_partition_name} INTO (
26
+ PARTITION #{partition_name} VALUES LESS THAN ('#{value}'),
27
+ PARTITION #{reorganize_partition_name} VALUES LESS THAN #{max_value});"
28
+ end
29
+
30
+ def parge_sql(table_name, partition_name)
31
+ "ALTER TABLE #{table_name} DROP PARTITION #{partition_name};"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleMysqlParitioning
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'simple_mysql_partitioning/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'simple_mysql_partitioning'
7
+ spec.version = SimpleMysqlParitioning::VERSION
8
+ spec.authors = ['Shunsuke Andoh']
9
+ spec.email = ['shunsuke.andoh@gmail.com']
10
+
11
+ spec.summary = ' Generate partitioning sql for mysql'
12
+ spec.description = ' simple generate partition sql'
13
+ spec.homepage = 'https://github.com/Andryu/simple_mysql_partitioning'
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'activerecord', ['> 3.0', '< 5.0']
25
+ spec.add_development_dependency 'bundler', '~> 1.16'
26
+ spec.add_development_dependency 'mysql2', '~> 0.3.21'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_mysql_partitioning
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shunsuke Andoh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.16'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.16'
47
+ - !ruby/object:Gem::Dependency
48
+ name: mysql2
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.3.21
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.3.21
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ description: " simple generate partition sql"
90
+ email:
91
+ - shunsuke.andoh@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".rspec"
98
+ - ".travis.yml"
99
+ - Gemfile
100
+ - README.md
101
+ - Rakefile
102
+ - bin/console
103
+ - bin/setup
104
+ - docker/docker-compose.yml
105
+ - lib/simple_mysql_partitioning.rb
106
+ - lib/simple_mysql_partitioning/executor.rb
107
+ - lib/simple_mysql_partitioning/sql.rb
108
+ - lib/simple_mysql_partitioning/version.rb
109
+ - simple_mysql_partitioning.gemspec
110
+ homepage: https://github.com/Andryu/simple_mysql_partitioning
111
+ licenses: []
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.5.2
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Generate partitioning sql for mysql
133
+ test_files: []