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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '00404860fae8f92d17c1be36fb44f6b8fea7413644bf3f184a2431589c750abc'
4
- data.tar.gz: db1520df2c4bd9097927cf73900785c42bebeb67f747a12a857c48fdc6ca64a9
3
+ metadata.gz: '08f3d08e8d7f2f60615587f8c842b8a80e59f10d4f00d299422ca44caef031d7'
4
+ data.tar.gz: 889bcd29c7b381ffdcdc0a32150a512243950dc106dec9d34d791f50794a3bb1
5
5
  SHA512:
6
- metadata.gz: accd820d05e151745c26cf7138394ded42f0b50f3272f051b8a154cf6dbc51271a8f810f41602138ed003bfba72a3279129638d7eb312cff4a967d6ef05bfe2e
7
- data.tar.gz: 1b52fc649ff7f7a6832ad69236c3de3343b00cf762bfe9d935dc2be96552dfcee69e55d2ece4926e1d3b0d8a9123c970db31f706250c3d19501796c0a9a38874
6
+ metadata.gz: 91319129faa191528b4808ade4138310969cd95c256b7beaba307947f5b962027cde2965a90122bceb84bcc5c4eafcca65d3aa27638b6cce4383963f5e5c1d10
7
+ data.tar.gz: 9b270632d217dc19e74d479bf15ef9378aae34b813c56904fa8d7ccd10f8cdfc8d8db1a049826b1bb0a03539929de551510a1520a1df9c6ccb4cfbf6fb71cb56
@@ -1,3 +1,8 @@
1
+ ## 0.4.2
2
+
3
+ - Added support for Postgres 11 index improvements
4
+ - Added support for all connection options
5
+
1
6
  ## 0.4.1
2
7
 
3
8
  - Better support for schemas
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016-2017 Andrew Kane
3
+ Copyright (c) 2016-2018 Andrew Kane
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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.
@@ -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
- index_defs = execute("SELECT pg_get_indexdef(indexrelid) FROM pg_index WHERE indrelid = #{regclass(schema_table)} AND indisprimary = 'f'").map { |r| r["pg_get_indexdef"] }
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 = max_id(source_table, primary_key)
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
- uri_parser = URI::Parser.new
459
- config = {
460
- host: uri.host,
461
- port: uri.port,
462
- dbname: uri.path.sub(/\A\//, ""),
463
- user: uri.user,
464
- password: uri.password,
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
@@ -1,3 +1,3 @@
1
1
  module PgSlice
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
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.1
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-05-01 00:00:00.000000000 Z
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: '0'
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.6
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
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
@@ -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
@@ -1,3 +0,0 @@
1
- FROM ruby:latest
2
- RUN gem install pgslice
3
- ENTRYPOINT ["pgslice"]
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in pgslice.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- t.warning = false
9
- end
10
-
11
- task default: :test
@@ -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