pgdice 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +66 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +6 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Guardfile +31 -0
- data/LICENSE +21 -0
- data/README.md +262 -0
- data/Rakefile +12 -0
- data/bin/_guard-core +29 -0
- data/bin/console +15 -0
- data/bin/guard +29 -0
- data/bin/setup +8 -0
- data/lib/pgdice/configuration.rb +122 -0
- data/lib/pgdice/database_connection.rb +30 -0
- data/lib/pgdice/partition_helper.rb +69 -0
- data/lib/pgdice/partition_manager.rb +86 -0
- data/lib/pgdice/pg_slice_manager.rb +119 -0
- data/lib/pgdice/table_dropper.rb +26 -0
- data/lib/pgdice/validation.rb +132 -0
- data/lib/pgdice/version.rb +5 -0
- data/lib/pgdice.rb +109 -0
- data/pgdice.gemspec +44 -0
- metadata +358 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 63a62f8196d2f0299a6e181001c2f1c34020683360d01347a24288a9da0bc16a
|
4
|
+
data.tar.gz: 2a6edd7716f95f215a222b9d47bfdae2897852c70cfff516767ab4669c167872
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 190c116e139dce2e6e009703be2b38eea7a7d51efb0ebf01266abf63005e1122d55569b49d65a56dc5ce1173392e2fe24fa5cc77c93355a1497f9cf169ac1d1e
|
7
|
+
data.tar.gz: d81d5625a0b145b259507067c7214b3003937523965444f32631968049a3ddb686f4de6b1b711466ff76596ccbefb7dff1466d2fcf47e563e4185a170dee822d
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
defaults: &defaults
|
7
|
+
working_directory: ~/repo
|
8
|
+
docker:
|
9
|
+
- image: circleci/ruby:2.5.1
|
10
|
+
environment:
|
11
|
+
DATABASE_HOST: 127.0.0.1
|
12
|
+
DATABASE_USERNAME: pgdice
|
13
|
+
PGDICE_LOG_TARGET: STDOUT
|
14
|
+
|
15
|
+
- image: circleci/postgres:10.4-alpine-ram
|
16
|
+
environment:
|
17
|
+
POSTGRES_USER: pgdice
|
18
|
+
POSTGRES_DB: pgdice_test
|
19
|
+
|
20
|
+
jobs:
|
21
|
+
test:
|
22
|
+
<<: *defaults
|
23
|
+
environment:
|
24
|
+
- CC_TEST_REPORTER_ID: b39c211d102df8869887e0f5764fbb06114fd2430cdf6689868dec7a1261fd05
|
25
|
+
steps:
|
26
|
+
- checkout
|
27
|
+
- run:
|
28
|
+
name: Download cc-test-reporter
|
29
|
+
command: |
|
30
|
+
mkdir -p tmp/
|
31
|
+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
|
32
|
+
chmod +x ./tmp/cc-test-reporter
|
33
|
+
|
34
|
+
- run:
|
35
|
+
name: Setup dependencies
|
36
|
+
command: |
|
37
|
+
bundle install --jobs 4 --retry 3
|
38
|
+
|
39
|
+
- run:
|
40
|
+
name: Run tests
|
41
|
+
command: |
|
42
|
+
mkdir -p /tmp/test-results
|
43
|
+
TEST_FILES="$(circleci tests glob "test/**/*_test.rb" | circleci tests split --split-by=timings)"
|
44
|
+
|
45
|
+
bundle exec rake test
|
46
|
+
./tmp/cc-test-reporter format-coverage -t simplecov -o tmp/coverage/codeclimate.pgdice.json tmp/coverage/pgdice/.resultset.json
|
47
|
+
|
48
|
+
- store_test_results:
|
49
|
+
path: ~/repo/tmp/test-results
|
50
|
+
|
51
|
+
- store_artifacts:
|
52
|
+
path: ~/repo/tmp/test-results
|
53
|
+
destination: test-results
|
54
|
+
|
55
|
+
- run:
|
56
|
+
name: Upload coverage results to Code Climate
|
57
|
+
command: |
|
58
|
+
./tmp/cc-test-reporter sum-coverage tmp/coverage/codeclimate.*.json -p 1 -o tmp/coverage/codeclimate.total.json
|
59
|
+
./tmp/cc-test-reporter upload-coverage -i tmp/coverage/codeclimate.total.json
|
60
|
+
|
61
|
+
|
62
|
+
workflows:
|
63
|
+
version: 2
|
64
|
+
commit:
|
65
|
+
jobs:
|
66
|
+
- test
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: GfF90mydWLT1YZj5hFzFy9l2xyVNjMkBV
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pgdice
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.5.1
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at scytherswings@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A sample Guardfile
|
4
|
+
# More info at https://github.com/guard/guard#readme
|
5
|
+
|
6
|
+
## Uncomment and set this to only include directories you want to watch
|
7
|
+
# directories %w(app lib config test spec features) \
|
8
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
9
|
+
|
10
|
+
## Note: if you are using the `directories` clause above and you are not
|
11
|
+
## watching the project directory ('.'), then you will want to move
|
12
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
13
|
+
#
|
14
|
+
# $ mkdir config
|
15
|
+
# $ mv Guardfile config/
|
16
|
+
# $ ln -s config/Guardfile .
|
17
|
+
#
|
18
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
19
|
+
|
20
|
+
guard :minitest, all_after_pass: true do
|
21
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
22
|
+
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
23
|
+
watch(%r{^test/.+_test\.rb$})
|
24
|
+
end
|
25
|
+
|
26
|
+
guard :rubocop, cli: %w[-D -S -a] do
|
27
|
+
watch(/.rubocop.yml/)
|
28
|
+
watch(/.+\.rb$/)
|
29
|
+
watch(/Rakefile/)
|
30
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
31
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Illuminus Limited Liability Company
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
[![CircleCI](https://circleci.com/gh/IlluminusLimited/pgdice.svg?style=shield)](https://circleci.com/gh/IlluminusLimited/pgdice)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/github/IlluminusLimited/pgdice/badge.svg?branch=master)](https://coveralls.io/github/IlluminusLimited/pgdice?branch=master)
|
3
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/311e005a14749bf2f826/maintainability)](https://codeclimate.com/github/IlluminusLimited/pgdice/maintainability)
|
4
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/311e005a14749bf2f826/test_coverage)](https://codeclimate.com/github/IlluminusLimited/pgdice/test_coverage)
|
5
|
+
|
6
|
+
# PgDice
|
7
|
+
|
8
|
+
PgDice is a utility that builds on top of the excellent gem
|
9
|
+
[https://github.com/ankane/pgslice](https://github.com/ankane/pgslice)
|
10
|
+
|
11
|
+
PgDice is intended to be used by scheduled background jobs in frameworks like [Sidekiq](https://github.com/mperham/sidekiq)
|
12
|
+
where logging and clear exception messages are crucial.
|
13
|
+
|
14
|
+
|
15
|
+
## Disclaimer
|
16
|
+
|
17
|
+
There are some features in this gem which allow you to drop database tables.
|
18
|
+
|
19
|
+
If you choose to use this software without a __tested and working__ backup and restore strategy in place then you
|
20
|
+
are a fool and will pay the price for your negligence. This software comes with no warranty
|
21
|
+
or any guarantees, implied or otherwise. By using this software you agree that the creator,
|
22
|
+
maintainers and any affiliated parties CANNOT BE HELD LIABLE FOR DATA LOSS OR LOSSES OF ANY KIND.
|
23
|
+
|
24
|
+
See the [LICENSE](LICENSE) for more information.
|
25
|
+
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
Add this line to your application's Gemfile:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
gem 'pgdice'
|
33
|
+
```
|
34
|
+
|
35
|
+
And then execute:
|
36
|
+
|
37
|
+
$ bundle
|
38
|
+
|
39
|
+
Or install it yourself as:
|
40
|
+
|
41
|
+
$ gem install pgdice
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
### Configuration
|
46
|
+
|
47
|
+
You must configure `PgDice` before you can use it, otherwise you won't be able to perform any manipulation actions
|
48
|
+
on tables.
|
49
|
+
|
50
|
+
This is an example config from a project using `Sidekiq`
|
51
|
+
```ruby
|
52
|
+
require 'pgdice'
|
53
|
+
PgDice.configure do |config|
|
54
|
+
config.logger = Sidekiq.logger # This defaults to STDOUT if you don't specify a logger
|
55
|
+
config.database_url = ENV['PGDICE_DATABASE_URL'] # postgresql://[user[:password]@][host][:port][/dbname][?param1=value1&...]
|
56
|
+
config.approved_tables = ENV['PGDICE_APPROVED_TABLES'] # Comma separated values: 'comments,posts'
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
|
61
|
+
#### Configuration Parameters
|
62
|
+
|
63
|
+
`logger` Optional: The logger to use. If you don't set this it defaults to STDOUT.
|
64
|
+
|
65
|
+
`database_url` The postgres database url to connect to. This is required since `pgslice` is used to accomplish some tasks
|
66
|
+
and it only takes a `url` currently.
|
67
|
+
|
68
|
+
`approved_tables` This one is important. If you want to manipulate database tables with this gem you're going to
|
69
|
+
need to add the base table name to this string of comma-separated values.
|
70
|
+
|
71
|
+
`additional_validators` Optional: This can accept an array of `proc` or `lambda` type predicates.
|
72
|
+
Each predicate will be passed the `params` hash and a `logger`. These predicates are called before doing things like
|
73
|
+
dropping tables and adding tables.
|
74
|
+
|
75
|
+
`dry_run` Optional: You can set it to either `true` or `false`. This will make PgDice print the commands but not
|
76
|
+
execute them.
|
77
|
+
|
78
|
+
`older_than` Optional: Time object used to scope the queries on droppable tables. Defaults to 90 days ago.
|
79
|
+
|
80
|
+
`table_drop_batch_size` Optional: Maximum number of tables you can drop in one query. Defaults to 7.
|
81
|
+
|
82
|
+
|
83
|
+
#### Advanced Configuration Parameters
|
84
|
+
|
85
|
+
`table_dropper` This defaults to [TableDropper](lib/pgdice/table_dropper.rb) which has a `lambda`-like interface.
|
86
|
+
An example use-case would be calling out to your backup system to confirm the table is backed up.
|
87
|
+
This mechanism will be passed the `table_to_drop` and a `logger`.
|
88
|
+
|
89
|
+
`pg_connection` This is a `PG::Connection` object used for the database queries made from `pgdice`.
|
90
|
+
By default it will be initialized from the `database_url` if left `nil`. Keep in mind the dependency
|
91
|
+
`pgslice` will still establish its own connection using the `database_url` so this feature may not be very
|
92
|
+
useful if you are trying to only use one connection for this utility.
|
93
|
+
|
94
|
+
`database_connection` You can supply your own [DatabaseConnection](lib/pgdice/database_connection.rb) if you like.
|
95
|
+
I'm not sure why you would do this.
|
96
|
+
|
97
|
+
`pg_slice_manager` This is an internal wrapper around `pgslice`. [PgSliceManager](lib/pgdice/pg_slice_manager.rb)
|
98
|
+
This configuration lets you provide your own if you wish. I'm not sure why you would do this.
|
99
|
+
|
100
|
+
`partition_manager` You can supply your own [PartitionManager](lib/pgdice/partition_manager.rb) if you like.
|
101
|
+
I'm not sure why you would do this.
|
102
|
+
|
103
|
+
`partition_helper` You can supply your own [PartitionHelper](lib/pgdice/partition_helper.rb) if you like.
|
104
|
+
I'm not sure why you would do this.
|
105
|
+
|
106
|
+
|
107
|
+
### Converting existing tables to partitioned tables
|
108
|
+
|
109
|
+
__This should only be used on smallish tables and ONLY after you have tested it on a non-production copy of your
|
110
|
+
production database.__
|
111
|
+
In fact, you should just not do this in production. Schedule downtime or something and run it a few times on
|
112
|
+
a copy of your database. Then practice restoring your database some more.
|
113
|
+
|
114
|
+
|
115
|
+
This command will convert an existing table into 61 partitioned tables (30 past, 30 future, and one for today).
|
116
|
+
|
117
|
+
For more information on what's going on in the background see
|
118
|
+
[https://github.com/ankane/pgslice](https://github.com/ankane/pgslice)
|
119
|
+
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
PgDice.partition_helper.partition_table!(table_name: 'comments',
|
123
|
+
past: 30,
|
124
|
+
future: 30,
|
125
|
+
column_name: 'created_at',
|
126
|
+
period: :day)
|
127
|
+
```
|
128
|
+
|
129
|
+
If you mess up (again you shouldn't use this in production). These two methods are useful for writing tests
|
130
|
+
that work with partitions.
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
PgDice.partition_helper.undo_partitioning!(table_name: 'comments')
|
134
|
+
```
|
135
|
+
|
136
|
+
In `partition_helper` there are versions of the methods that will throw exceptions (ending in `!`) and others
|
137
|
+
that will return a truthy value or `false` if there is a failure.
|
138
|
+
|
139
|
+
`period` can be set to one of these values: `:day`, `:month`, `:year`
|
140
|
+
|
141
|
+
|
142
|
+
### Maintaining partitioned tables
|
143
|
+
|
144
|
+
#### Adding more tables
|
145
|
+
|
146
|
+
If you have existing tables that need to periodically have more tables added you can run:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
PgDice.partition_manager.add_new_partitions(table_name: 'comments', future: 30)
|
150
|
+
```
|
151
|
+
|
152
|
+
The above command would add 30 new tables and their associated indexes all based on the `period` that the
|
153
|
+
partitioned table was defined with.
|
154
|
+
|
155
|
+
|
156
|
+
#### Listing old tables
|
157
|
+
|
158
|
+
Sometimes you just want to know what's out there and if there are tables ready to be dropped.
|
159
|
+
|
160
|
+
To list all eligible tables for dropping you can run:
|
161
|
+
```ruby
|
162
|
+
PgDice.partition_manager.list_old_partitions(table_name: 'comments', older_than: Time.now.utc - 90*24*60*60)
|
163
|
+
```
|
164
|
+
|
165
|
+
If you have `active_support` you could do:
|
166
|
+
```ruby
|
167
|
+
PgDice.partition_manager.list_old_partitions(table_name: 'comments', older_than: 90.days.ago)
|
168
|
+
```
|
169
|
+
|
170
|
+
Technically `older_than` is optional and defaults to `90 days` (see the configuration section).
|
171
|
+
It is recommended that you pass it in to be explicit, but you can rely on the configuration
|
172
|
+
mechanism if you so choose.
|
173
|
+
|
174
|
+
|
175
|
+
#### Dropping old tables
|
176
|
+
|
177
|
+
_Dropping tables is irreversible! Do this at your own risk!!_
|
178
|
+
|
179
|
+
If you want to drop old tables (after backing them up of course) you can run:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
PgDice.partition_manager.drop_old_partitions(table_name: 'comments', older_than: Time.now.utc - 90*24*60*60)
|
183
|
+
```
|
184
|
+
|
185
|
+
If you have `active_support` you could do:
|
186
|
+
```ruby
|
187
|
+
PgDice.partition_manager.drop_old_partitions(table_name: 'comments', older_than: 90.days.ago)
|
188
|
+
```
|
189
|
+
|
190
|
+
This command would drop old partitions that are older than `90` days.
|
191
|
+
|
192
|
+
Technically `older_than` is optional and defaults to `90 days` (see the configuration section).
|
193
|
+
It is recommended that you pass it in to be explicit, but you can rely on the configuration
|
194
|
+
mechanism if you so choose.
|
195
|
+
|
196
|
+
Another good reason to pass in the `older_than` parameter is if you are managing tables that
|
197
|
+
are partiioned by different schemes or have different use-cases
|
198
|
+
e.g. daily vs yearly partitioned tables.
|
199
|
+
|
200
|
+
|
201
|
+
#### Validating everything is still working
|
202
|
+
|
203
|
+
If you've got background jobs creating and dropping tables you're going to want to
|
204
|
+
ensure they are actually working correctly.
|
205
|
+
|
206
|
+
To validate that your expected number of tables exist, you can run:
|
207
|
+
```ruby
|
208
|
+
PgDice.validation.assert_tables(table_name: 'comments', future: 30, past: 90)
|
209
|
+
```
|
210
|
+
|
211
|
+
An [InsufficientTablesError](lib/pgdice.rb) will be raised if any conditions are not met.
|
212
|
+
|
213
|
+
This will check that the table 30 days from now exists and that there is
|
214
|
+
still a table from 90 days ago. The above example assumes the table was partitioned
|
215
|
+
by day.
|
216
|
+
|
217
|
+
|
218
|
+
## Planned Features
|
219
|
+
|
220
|
+
1. Full `PG::Connection` support (no more database URLs).
|
221
|
+
1. Custom schema support for all operations. Defaults to `public` currently.
|
222
|
+
1. Non time-range based partitioning.
|
223
|
+
|
224
|
+
|
225
|
+
## Development
|
226
|
+
|
227
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
|
228
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
229
|
+
|
230
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
231
|
+
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
232
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
233
|
+
|
234
|
+
|
235
|
+
### Running tests
|
236
|
+
|
237
|
+
You're going to need to have postgres 10 or greater installed.
|
238
|
+
|
239
|
+
Run the following commands from your terminal. Don't run these on anything but a development machine.
|
240
|
+
|
241
|
+
1. `psql postgres -c "create role pgdice with createdb superuser login password 'password';"`
|
242
|
+
1. `createdb pgdice_test`
|
243
|
+
1. Now you can run the tests via `guard` or `rake test`
|
244
|
+
|
245
|
+
|
246
|
+
## Contributing
|
247
|
+
|
248
|
+
Bug reports and pull requests are welcome on GitHub at
|
249
|
+
[https://github.com/IlluminusLimited/pgdice](https://github.com/IlluminusLimited/pgdice). This project is intended
|
250
|
+
to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
|
251
|
+
the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
252
|
+
|
253
|
+
|
254
|
+
## License
|
255
|
+
|
256
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
257
|
+
|
258
|
+
|
259
|
+
## Code of Conduct
|
260
|
+
|
261
|
+
Everyone interacting in the Pgdice project’s codebases, issue trackers, chat rooms and mailing lists is expected
|
262
|
+
to follow the [code of conduct](https://github.com/IlluminusLimited/pgdice/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/_guard-core
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application '_guard-core' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'pathname'
|
12
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path('bundle', __dir__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rubygems'
|
27
|
+
require 'bundler/setup'
|
28
|
+
|
29
|
+
load Gem.bin_path('guard', '_guard-core')
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'pgdice'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/guard
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'guard' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'pathname'
|
12
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path('bundle', __dir__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rubygems'
|
27
|
+
require 'bundler/setup'
|
28
|
+
|
29
|
+
load Gem.bin_path('guard', 'guard')
|