pgslice 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +10 -7
- data/lib/pgslice.rb +31 -14
- data/lib/pgslice/version.rb +1 -1
- metadata +5 -12
- data/.gitignore +0 -9
- data/.travis.yml +0 -13
- data/Dockerfile +0 -3
- data/Gemfile +0 -4
- data/Rakefile +0 -11
- data/pgslice.gemspec +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz: '
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08f3d08e8d7f2f60615587f8c842b8a80e59f10d4f00d299422ca44caef031d7'
|
4
|
+
data.tar.gz: 889bcd29c7b381ffdcdc0a32150a512243950dc106dec9d34d791f50794a3bb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91319129faa191528b4808ade4138310969cd95c256b7beaba307947f5b962027cde2965a90122bceb84bcc5c4eafcca65d3aa27638b6cce4383963f5e5c1d10
|
7
|
+
data.tar.gz: 9b270632d217dc19e74d479bf15ef9378aae34b813c56904fa8d7ccd10f8cdfc8d8db1a049826b1bb0a03539929de551510a1520a1df9c6ccb4cfbf6fb71cb56
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -359,7 +359,7 @@ pgslice swap <table>
|
|
359
359
|
Once a table is partitioned, here’s how to change the schema:
|
360
360
|
|
361
361
|
- To add, remove, or modify a column, make the update on the master table only
|
362
|
-
- To add or remove an index, make the update on the master table and all partitions
|
362
|
+
- To add or remove an index, make the update on the master table and all partitions (for Postgres 11, make the update on the master table only)
|
363
363
|
|
364
364
|
## Declarative Partitioning
|
365
365
|
|
@@ -394,12 +394,6 @@ This will give you the `pgslice` command.
|
|
394
394
|
- [PostgreSQL Manual](https://www.postgresql.org/docs/current/static/ddl-partitioning.html)
|
395
395
|
- [PostgreSQL Wiki](https://wiki.postgresql.org/wiki/Table_partitioning)
|
396
396
|
|
397
|
-
## TODO
|
398
|
-
|
399
|
-
- Command to sync index changes with partitions
|
400
|
-
- Disable indexing for faster `fill`
|
401
|
-
- ETA for `fill`
|
402
|
-
|
403
397
|
## Related Projects
|
404
398
|
|
405
399
|
Also check out:
|
@@ -425,3 +419,12 @@ bundle install
|
|
425
419
|
createdb pgslice_test
|
426
420
|
bundle exec rake
|
427
421
|
```
|
422
|
+
|
423
|
+
To test against different versions of Postgres with Docker, use:
|
424
|
+
|
425
|
+
```sh
|
426
|
+
docker run -p=8000:5432 postgres:10
|
427
|
+
TZ=Etc/UTC PGSLICE_URL=postgres://postgres@localhost:8000/postgres bundle exec rake
|
428
|
+
```
|
429
|
+
|
430
|
+
On Mac, you must use [Docker for Mac](https://www.docker.com/docker-mac) for the port mapping to localhost to work.
|
data/lib/pgslice.rb
CHANGED
@@ -82,6 +82,13 @@ module PgSlice
|
|
82
82
|
CREATE TABLE #{quote_table(intermediate_table)} (LIKE #{quote_table(table)} INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING STORAGE INCLUDING COMMENTS) PARTITION BY RANGE (#{quote_table(column)});
|
83
83
|
SQL
|
84
84
|
|
85
|
+
if server_version_num >= 110000
|
86
|
+
index_defs = execute("SELECT pg_get_indexdef(indexrelid) FROM pg_index WHERE indrelid = #{regclass(table)} AND indisprimary = 'f'").map { |r| r["pg_get_indexdef"] }
|
87
|
+
index_defs.each do |index_def|
|
88
|
+
queries << index_def.sub(/ ON \S+ USING /, " ON #{quote_table(intermediate_table)} USING ").sub(/ INDEX .+ ON /, " INDEX ON ") + ";"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
85
92
|
# add comment
|
86
93
|
cast = column_cast(table, column)
|
87
94
|
queries << <<-SQL
|
@@ -175,7 +182,14 @@ COMMENT ON TRIGGER #{quote_ident(trigger_name)} ON #{quote_table(intermediate_ta
|
|
175
182
|
existing_partitions(original_table, period).last
|
176
183
|
end
|
177
184
|
|
178
|
-
|
185
|
+
# indexes automatically propagate in Postgres 11+
|
186
|
+
index_defs =
|
187
|
+
if !declarative || server_version_num < 110000
|
188
|
+
execute("SELECT pg_get_indexdef(indexrelid) FROM pg_index WHERE indrelid = #{regclass(schema_table)} AND indisprimary = 'f'").map { |r| r["pg_get_indexdef"] }
|
189
|
+
else
|
190
|
+
[]
|
191
|
+
end
|
192
|
+
|
179
193
|
fk_defs = foreign_keys(schema_table)
|
180
194
|
primary_key = self.primary_key(schema_table)
|
181
195
|
|
@@ -293,7 +307,12 @@ CREATE OR REPLACE FUNCTION #{quote_ident(trigger_name)}()
|
|
293
307
|
primary_key = self.primary_key(schema_table)[0]
|
294
308
|
abort "No primary key" unless primary_key
|
295
309
|
|
296
|
-
max_source_id =
|
310
|
+
max_source_id = nil
|
311
|
+
begin
|
312
|
+
max_source_id = max_id(source_table, primary_key)
|
313
|
+
rescue PG::UndefinedFunction
|
314
|
+
abort "Only numeric primary keys are supported"
|
315
|
+
end
|
297
316
|
|
298
317
|
max_dest_id =
|
299
318
|
if options[:start]
|
@@ -454,22 +473,20 @@ INSERT INTO #{quote_table(dest_table)} (#{fields})
|
|
454
473
|
@connection ||= begin
|
455
474
|
url = options[:url] || ENV["PGSLICE_URL"]
|
456
475
|
abort "Set PGSLICE_URL or use the --url option" unless url
|
476
|
+
|
457
477
|
uri = URI.parse(url)
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
connect_timeout: 1
|
466
|
-
}.reject { |_, value| value.to_s.empty? }
|
467
|
-
config.map { |key, value| config[key] = uri_parser.unescape(value) if value.is_a?(String) }
|
468
|
-
@schema = CGI.parse(uri.query.to_s)["schema"][0] || "public"
|
469
|
-
PG::Connection.new(config)
|
478
|
+
params = CGI.parse(uri.query.to_s)
|
479
|
+
# remove schema
|
480
|
+
@schema = Array(params.delete("schema") || "public")[0]
|
481
|
+
uri.query = URI.encode_www_form(params)
|
482
|
+
|
483
|
+
ENV["PGCONNECT_TIMEOUT"] ||= "1"
|
484
|
+
PG::Connection.new(uri.to_s)
|
470
485
|
end
|
471
486
|
rescue PG::ConnectionBad => e
|
472
487
|
abort e.message
|
488
|
+
rescue URI::InvalidURIError
|
489
|
+
abort "Invalid url"
|
473
490
|
end
|
474
491
|
|
475
492
|
def schema
|
data/lib/pgslice/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgslice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|
@@ -81,25 +81,18 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description:
|
84
|
-
email:
|
85
|
-
- andrew@chartkick.com
|
84
|
+
email: andrew@chartkick.com
|
86
85
|
executables:
|
87
86
|
- pgslice
|
88
87
|
extensions: []
|
89
88
|
extra_rdoc_files: []
|
90
89
|
files:
|
91
|
-
- ".gitignore"
|
92
|
-
- ".travis.yml"
|
93
90
|
- CHANGELOG.md
|
94
|
-
- Dockerfile
|
95
|
-
- Gemfile
|
96
91
|
- LICENSE.txt
|
97
92
|
- README.md
|
98
|
-
- Rakefile
|
99
93
|
- exe/pgslice
|
100
94
|
- lib/pgslice.rb
|
101
95
|
- lib/pgslice/version.rb
|
102
|
-
- pgslice.gemspec
|
103
96
|
homepage: https://github.com/ankane/pgslice
|
104
97
|
licenses:
|
105
98
|
- MIT
|
@@ -112,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
105
|
requirements:
|
113
106
|
- - ">="
|
114
107
|
- !ruby/object:Gem::Version
|
115
|
-
version: '
|
108
|
+
version: '2.2'
|
116
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
110
|
requirements:
|
118
111
|
- - ">="
|
@@ -120,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
113
|
version: '0'
|
121
114
|
requirements: []
|
122
115
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.7.
|
116
|
+
rubygems_version: 2.7.7
|
124
117
|
signing_key:
|
125
118
|
specification_version: 4
|
126
119
|
summary: Postgres partitioning as easy as pie
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm: 2.4.1
|
3
|
-
cache: bundler
|
4
|
-
sudo: false
|
5
|
-
script: bundle exec rake test
|
6
|
-
addons:
|
7
|
-
postgresql: "9.4"
|
8
|
-
before_script:
|
9
|
-
- psql -c 'create database pgslice_test;' -U postgres
|
10
|
-
notifications:
|
11
|
-
email:
|
12
|
-
on_success: never
|
13
|
-
on_failure: change
|
data/Dockerfile
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/pgslice.gemspec
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "pgslice/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "pgslice"
|
8
|
-
spec.version = PgSlice::VERSION
|
9
|
-
spec.authors = ["Andrew Kane"]
|
10
|
-
spec.email = ["andrew@chartkick.com"]
|
11
|
-
|
12
|
-
spec.summary = "Postgres partitioning as easy as pie"
|
13
|
-
spec.homepage = "https://github.com/ankane/pgslice"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir = "exe"
|
18
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency "slop", ">= 4.2.0"
|
22
|
-
spec.add_dependency "pg"
|
23
|
-
|
24
|
-
spec.add_development_dependency "bundler"
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "minitest"
|
27
|
-
end
|