simple_mysql_partitioning 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0067c6333d5d6157c271f4e00d5c7480ac3e998b6ec81a3d3b49a0645f636a5b
4
- data.tar.gz: 2e60c8ca0fe8ba635363e0492b80d5ef6622f145ef97b987f23ecf4fe099b361
3
+ metadata.gz: 568bcd28359480d44c0ab7aa9edf67815dc8ac2fb863ee20707f7c85f4fbab78
4
+ data.tar.gz: e0294e4a4eb034af20641d227463a64081144d4910cfb56bf3e7d0a28e620795
5
5
  SHA512:
6
- metadata.gz: dba59fa8e74fc27264a8113cf67d9221bae38c8d5cf0a4b98442bea9c5a1733aa044a54085dd51b8d844ce9a130ab2e8cc87bf0879228bfb79c98adf0054820f
7
- data.tar.gz: 30b894f9f6480418384e2b5bc42b593d4fe3f85cb46ba6a779f43c31c96e78392e20c63a0f70c4abb71b6aa7cbcea90d2911ff68146ce2e398d3c1a28717b4df
6
+ metadata.gz: 5e7744b6146eb2562611cada8d3d021e253519aab97a146c8b12b699b09e69bcfe811eed704aaad020e870a31d751904eb051c05e95a21b4bd4d20cbfb35621d
7
+ data.tar.gz: fd4054e83bdb59985c40ec084b68a7243197d8046b7cbdba6d8381b6983b20be69978162a08f79122ffbfc38779f4ba76248a268e9727add553d2f2c450108c0
@@ -0,0 +1,15 @@
1
+ # Use the latest 2.1 version of CircleCI pipeline processing engine, see https://circleci.com/docs/2.0/configuration-reference/
2
+ version: 2.1
3
+
4
+ # Use a package of configuration called an orb, see https://circleci.com/docs/2.0/orb-intro/
5
+ orbs:
6
+ # Declare a dependency on the welcome-orb
7
+ welcome: circleci/welcome-orb@0.3.1
8
+
9
+ # Orchestrate or schedule a set of jobs, see https://circleci.com/docs/2.0/workflows/
10
+ workflows:
11
+ # Name the workflow "Welcome"
12
+ Welcome:
13
+ # Run the welcome/run job in its own container
14
+ jobs:
15
+ - welcome/run
@@ -1,7 +1,11 @@
1
1
  ---
2
2
  sudo: false
3
3
  language: ruby
4
- cache: bundler
4
+ service: docker
5
5
  rvm:
6
6
  - 2.5.0
7
- before_install: gem install bundler -v 1.16.3
7
+ before_install:
8
+ - docker-compose up -d
9
+ - gem install bundler -v 1.16.3
10
+ script:
11
+ - bundle exec rspec
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # SimpleMysqlParitioning
1
+ # SimpleMysqlPartitioning
2
+
3
+ [![Build Status](https://travis-ci.org/Andryu/simple_mysql_partitioning.svg?branch=master)](https://travis-ci.org/Andryu/simple_mysql_partitioning)
2
4
 
3
5
  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
6
 
@@ -42,7 +44,8 @@ DailyReport.partition.add(pairs_name_with_values)
42
44
 
43
45
  # reorganize partition
44
46
  # If you want to reorganize partition, use this method and set reorganize partition name to second arg.
45
- DailyReport.partition.reorganize(pairs_name_with_values, 'p999999')
47
+ # Reorganize partitiong default value is 'MAXVALUE'.
48
+ DailyReport.partition.reorganize(pairs_name_with_values, 'p999999', 'MAXVALUE')
46
49
 
47
50
  # drop
48
51
  DailyReport.partition.drop('p201808')
@@ -0,0 +1,23 @@
1
+ version: '3'
2
+ services:
3
+ mysql:
4
+ image: mysql:5.7
5
+ ports:
6
+ - "3306:3306"
7
+ environment:
8
+ - MYSQL_ALLOW_EMPTY_PASSWORD=yes
9
+ app:
10
+ environment:
11
+ BUNDLE_PATH: 'bundle'
12
+ MYSQL_DB_HOST: 'mysql'
13
+ build: docker/app
14
+ volumes:
15
+ - .:/app
16
+ - bundle-vol:/bundle:cached
17
+ command: irb
18
+ tty: true
19
+ stdin_open: true
20
+ depends_on:
21
+ - mysql
22
+ volumes:
23
+ bundle-vol:
@@ -0,0 +1,8 @@
1
+ FROM ruby:2.6.2-slim
2
+
3
+ RUN apt-get update -qq && apt-get install -y locales build-essential git default-libmysqlclient-dev
4
+ RUN sed -i 's/#.*ja_JP\.UTF/ja_JP\.UTF/' /etc/locale.gen
5
+ RUN locale-gen && update-locale LANG=ja_JP.UTF-8
6
+ RUN mkdir /app
7
+ WORKDIR /app
8
+ ADD . /app
@@ -4,6 +4,16 @@ require 'simple_mysql_partitioning/base_partitioning'
4
4
 
5
5
  module SimpleMySQLPartitioning
6
6
  class Range < BasePartitioning
7
+ def create(pairs_name_with_value)
8
+ sql = SQL.create_sql(
9
+ table_name,
10
+ klass.partition_config[:column],
11
+ pairs_name_with_value, true
12
+ )
13
+
14
+ klass.connection.execute(sql)
15
+ end
16
+
7
17
  def add(pairs_name_with_value)
8
18
  pairs_name_with_value.map do |pair|
9
19
  add_partition_sql = SQL.add_sql(table_name, pair.first, pair.last)
@@ -1,19 +1,36 @@
1
1
  module SimpleMySQLPartitioning
2
2
  class SQL
3
+
4
+ PARTITION_RANGE_LESS_VALUE =
5
+ 'PARTITION %{name} VALUES LESS THAN ("%{value}")'.freeze
6
+
3
7
  class << self
4
8
  def exists_sql(table_name, partition_name)
5
9
  "SELECT
6
10
  table_schema,
7
11
  table_name,
8
12
  partition_name,
9
- partition_ordinal_position,
10
- table_rows
13
+ partition_ordinal_position, table_rows
11
14
  FROM information_schema.partitions
12
15
  WHERE table_name='#{table_name}'
13
16
  AND partition_name='#{partition_name}'
14
17
  LIMIT 1;"
15
18
  end
16
19
 
20
+ def create_sql(table_name, column, pairs_name_with_value, max_value = true)
21
+ alter = "ALTER TABLE #{table_name} PARTITION BY RANGE COLUMNS(#{column})"
22
+
23
+ partitions = pairs_name_with_value.map do |pair|
24
+ format(
25
+ PARTITION_RANGE_LESS_VALUE,
26
+ name: pair.first,
27
+ value: pair.last
28
+ )
29
+ end
30
+
31
+ alter + ' ' + "(#{partitions.join(',')})"
32
+ end
33
+
17
34
  def add_sql(table_name, partition_name, value)
18
35
  "ALTER TABLE #{table_name}
19
36
  ADD PARTITION ( PARTITION #{partition_name} VALUES LESS THAN #{less_than(value)});"
@@ -1,3 +1,3 @@
1
1
  module SimpleMysqlParitioning
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_mysql_partitioning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shunsuke Andoh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-29 00:00:00.000000000 Z
11
+ date: 2019-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -93,6 +93,7 @@ executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
+ - ".circleci/config.yml"
96
97
  - ".gitignore"
97
98
  - ".rspec"
98
99
  - ".travis.yml"
@@ -101,7 +102,8 @@ files:
101
102
  - Rakefile
102
103
  - bin/console
103
104
  - bin/setup
104
- - docker/docker-compose.yml
105
+ - docker-compose.yml
106
+ - docker/app/Dockerfile
105
107
  - lib/simple_mysql_partitioning.rb
106
108
  - lib/simple_mysql_partitioning/adapter.rb
107
109
  - lib/simple_mysql_partitioning/base_partitioning.rb
@@ -127,8 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
129
  - !ruby/object:Gem::Version
128
130
  version: '0'
129
131
  requirements: []
130
- rubyforge_project:
131
- rubygems_version: 2.7.7
132
+ rubygems_version: 3.0.3
132
133
  signing_key:
133
134
  specification_version: 4
134
135
  summary: Generate partitioning sql for mysql
@@ -1,15 +0,0 @@
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