simple_mysql_partitioning 0.2.1 → 0.3.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 +4 -4
- data/.circleci/config.yml +15 -0
- data/.travis.yml +6 -2
- data/README.md +5 -2
- data/docker-compose.yml +23 -0
- data/docker/app/Dockerfile +8 -0
- data/lib/simple_mysql_partitioning/range.rb +10 -0
- data/lib/simple_mysql_partitioning/sql.rb +19 -2
- data/lib/simple_mysql_partitioning/version.rb +1 -1
- metadata +6 -5
- data/docker/docker-compose.yml +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 568bcd28359480d44c0ab7aa9edf67815dc8ac2fb863ee20707f7c85f4fbab78
|
4
|
+
data.tar.gz: e0294e4a4eb034af20641d227463a64081144d4910cfb56bf3e7d0a28e620795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# SimpleMysqlPartitioning
|
2
|
+
|
3
|
+
[](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
|
-
|
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')
|
data/docker-compose.yml
ADDED
@@ -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)});"
|
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.
|
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:
|
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
|
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
|
-
|
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
|
data/docker/docker-compose.yml
DELETED