pgdice 0.3.3 → 0.4.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/CHANGELOG.md +8 -0
- data/README.md +26 -0
- data/lib/pgdice/validation.rb +15 -4
- data/lib/pgdice/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12fa7e75440961dbabdca09146b652c0b849f4d0e92f7c6e66c5e95d932f7449
|
4
|
+
data.tar.gz: 6c9df08948a598ae17ddfe76ceb9c594c5566a479dce26bf2dd698f9eb54969d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a54b4dcdc2e9bed2798f5ccee31c1189036b0b37123e23b29c949d53bfbfe3fe7af1f288d4077ff66f3ce04374c113a91746e583bca3404aa221408afa05ceda
|
7
|
+
data.tar.gz: a418c411de0d82e221a1c7de358b1eb9dfd18a0bafd4207c84441852e87adfa1eb674063a194b50b1472e783f21842635dbc2c381958d1d0fc792a788c0914d3
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [v0.4.0] : 2018-12-06
|
6
|
+
### Changes
|
7
|
+
- Add `only:` option to `assert_tables` so users can assert on only `past`
|
8
|
+
or `future` tables if they wish.
|
9
|
+
- Fix #21 by adding documentation on how to migrate existing data from
|
10
|
+
unpartitioned tables
|
11
|
+
|
12
|
+
|
5
13
|
## [v0.3.3] : 2018-11-30
|
6
14
|
### Changes
|
7
15
|
- Do not eagerly initialize the `pg_connection` as this can cause some normal
|
data/README.md
CHANGED
@@ -153,6 +153,15 @@ For more information on what's going on in the background see
|
|
153
153
|
PgDice.partition_table('comments')
|
154
154
|
```
|
155
155
|
|
156
|
+
### Copying existing data into new partitions
|
157
|
+
|
158
|
+
If you have a table with existing data and you want that data to be split up and copied to your new partitions
|
159
|
+
you can use:
|
160
|
+
```ruby
|
161
|
+
PgDice.partition_table('comments', fill: true)
|
162
|
+
```
|
163
|
+
|
164
|
+
This will create the partitions and then insert data from the old table into the newly partitioned tables.
|
156
165
|
|
157
166
|
### Notes on partition_table
|
158
167
|
|
@@ -243,6 +252,12 @@ An [InsufficientTablesError](lib/pgdice.rb) will be raised if any conditions are
|
|
243
252
|
This will check that there are 7 future tables from now and that there are 90 past tables
|
244
253
|
per our configuration above.
|
245
254
|
|
255
|
+
|
256
|
+
If you want to only assert on `past` tables you could use the example below. The same goes for `future`
|
257
|
+
```ruby
|
258
|
+
PgDice.assert_tables('comments', only: :past)
|
259
|
+
```
|
260
|
+
|
246
261
|
## Listing approved tables
|
247
262
|
|
248
263
|
Sometimes you might need to know the tables configured for `PgDice`. To list the configured tables
|
@@ -254,6 +269,17 @@ PgDice.approved_tables
|
|
254
269
|
The [ApprovedTables](lib/pgdice/approved_tables.rb) object responds to the most common enumerable methods.
|
255
270
|
|
256
271
|
|
272
|
+
# Miscellaneous Notes
|
273
|
+
|
274
|
+
All methods for `PgDice` take a hash which will override whatever values would have been automatically supplied.
|
275
|
+
|
276
|
+
An example of this would be like so:
|
277
|
+
```ruby
|
278
|
+
PgDice.list_droppable_partitions('comments', past: 60)
|
279
|
+
```
|
280
|
+
This example would use `60` instead of the configured value of `90` from the `comments` table we configured above.
|
281
|
+
|
282
|
+
|
257
283
|
# FAQ
|
258
284
|
|
259
285
|
1. How do I get a postgres url if I'm running in Rails?
|
data/lib/pgdice/validation.rb
CHANGED
@@ -38,18 +38,29 @@ module PgDice
|
|
38
38
|
|
39
39
|
def filter_parameters(table, params)
|
40
40
|
if params.nil?
|
41
|
-
params =
|
42
|
-
params[:future] = table.future
|
43
|
-
params[:past] = table.past
|
44
|
-
period = table.period
|
41
|
+
params, period = handle_nil_params(table)
|
45
42
|
else
|
43
|
+
handle_only_param(table, params) if params[:only]
|
46
44
|
period = resolve_period(schema: table.schema, table_name: table.name, **params)
|
47
45
|
end
|
46
|
+
|
48
47
|
all_params = table.smash(params.merge!(period: period))
|
49
48
|
|
50
49
|
[table, period, all_params, params]
|
51
50
|
end
|
52
51
|
|
52
|
+
def handle_nil_params(table)
|
53
|
+
params = {}
|
54
|
+
params[:future] = table.future
|
55
|
+
params[:past] = table.past
|
56
|
+
[params, table.period]
|
57
|
+
end
|
58
|
+
|
59
|
+
def handle_only_param(table, params)
|
60
|
+
params[:future] = params[:only] == :future ? params[:future] || table.future : nil
|
61
|
+
params[:past] = params[:only] == :past ? params[:past] || table.past : nil
|
62
|
+
end
|
63
|
+
|
53
64
|
def assert_future_tables(table_name, partitions, period, expected)
|
54
65
|
newer_tables = tables_newer_than(partitions, @current_date_provider.call, period).size
|
55
66
|
if newer_tables < expected
|
data/lib/pgdice/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgdice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Newell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|