pgslice 0.4.6 → 0.4.7

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: 30d1c5d3ed842d1250761b64f3da34a6e25e0ea17d7689d1eca9f1f0d4db1b8f
4
- data.tar.gz: 82cbeccebcbdc6edeff9808d9013635d880aa8af20cb462722bdfe0fca5732a1
3
+ metadata.gz: 73d406b68757fa95efcc58a98249f9a8394cab3408a9ae14ef642983720f44b3
4
+ data.tar.gz: 7952c9aaa1734c76260b76a59822a4065e6184ac01bf3b1916bd217f7b368403
5
5
  SHA512:
6
- metadata.gz: 1db66bb9409d26d39952230c127d5edc900cf6070915d8a58ef4bec94a460d2db4588991fc2ed46e3c9205e904c424c6a379711c0ffc985e1723623f2eed3835
7
- data.tar.gz: 60612ea69df38bcc43f27e492f93ca96f17dc9528236f3e107ea1e7990b5df372dd7d799ea1bdebd6ae3064903a63e9d086668208ba6d3e5958b6247d237df43
6
+ metadata.gz: 057aeaddcf952f2bb99f657f290e03f2ec3bac2deffce0d7701a7549418d7d8211b2454cbc71039226b369fc5b355d7ad426df0c4ce032d660e8ce09ebe15eab
7
+ data.tar.gz: a36f9db976f72cc656e289ff5af6ebb89657eb739fb6ca1bc4ccba652fdfa8b93894bc2e3fde5a9fdcd63d53a24574347a280af60157d124445a565810b9839c
@@ -1,3 +1,8 @@
1
+ ## 0.4.7 (2020-08-14)
2
+
3
+ - Added `--tablespace` option to `add_partitions`
4
+ - Fixed sequence query if sequence in different schema than table
5
+
1
6
  ## 0.4.6 (2020-05-29)
2
7
 
3
8
  - Ensure correct order with multi-column primary keys
data/README.md CHANGED
@@ -171,7 +171,7 @@ ALTER TABLE "public"."visits" RENAME TO "visits_retired";
171
171
 
172
172
  ALTER TABLE "public"."visits_intermediate" RENAME TO "visits";
173
173
 
174
- ALTER SEQUENCE "visits_id_seq" OWNED BY "public"."visits"."id";
174
+ ALTER SEQUENCE "public"."visits_id_seq" OWNED BY "public"."visits"."id";
175
175
 
176
176
  COMMIT;
177
177
  ```
@@ -383,14 +383,14 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
383
383
  - Write, clarify, or fix documentation
384
384
  - Suggest or add new features
385
385
 
386
- To get started with development and testing:
386
+ To get started with development:
387
387
 
388
388
  ```sh
389
389
  git clone https://github.com/ankane/pgslice.git
390
390
  cd pgslice
391
391
  bundle install
392
392
  createdb pgslice_test
393
- bundle exec rake
393
+ bundle exec rake test
394
394
  ```
395
395
 
396
396
  To test against different versions of Postgres with Docker, use:
@@ -4,6 +4,7 @@ module PgSlice
4
4
  option :intermediate, type: :boolean, default: false, desc: "Add to intermediate table"
5
5
  option :past, type: :numeric, default: 0, desc: "Number of past partitions to add"
6
6
  option :future, type: :numeric, default: 0, desc: "Number of future partitions to add"
7
+ option :tablespace, type: :string, default: "", desc: "Tablespace to use"
7
8
  def add_partitions(table)
8
9
  original_table = create_table(table)
9
10
  table = options[:intermediate] ? original_table.intermediate_table : original_table
@@ -13,6 +14,7 @@ module PgSlice
13
14
 
14
15
  future = options[:future]
15
16
  past = options[:past]
17
+ tablespace = options[:tablespace]
16
18
  range = (-1 * past)..future
17
19
 
18
20
  period, field, cast, needs_comment, declarative, version = table.fetch_settings(original_table.trigger_name)
@@ -50,6 +52,7 @@ module PgSlice
50
52
  end
51
53
 
52
54
  primary_key = schema_table.primary_key
55
+ tablespace_str = tablespace.empty? ? "" : " TABLESPACE #{quote_ident(tablespace)}"
53
56
 
54
57
  added_partitions = []
55
58
  range.each do |n|
@@ -61,13 +64,13 @@ module PgSlice
61
64
 
62
65
  if declarative
63
66
  queries << <<-SQL
64
- CREATE TABLE #{quote_table(partition)} PARTITION OF #{quote_table(table)} FOR VALUES FROM (#{sql_date(day, cast, false)}) TO (#{sql_date(advance_date(day, period, 1), cast, false)});
67
+ CREATE TABLE #{quote_table(partition)} PARTITION OF #{quote_table(table)} FOR VALUES FROM (#{sql_date(day, cast, false)}) TO (#{sql_date(advance_date(day, period, 1), cast, false)})#{tablespace_str};
65
68
  SQL
66
69
  else
67
70
  queries << <<-SQL
68
71
  CREATE TABLE #{quote_table(partition)}
69
72
  (CHECK (#{quote_ident(field)} >= #{sql_date(day, cast)} AND #{quote_ident(field)} < #{sql_date(advance_date(day, period, 1), cast)}))
70
- INHERITS (#{quote_table(table)});
73
+ INHERITS (#{quote_table(table)})#{tablespace_str};
71
74
  SQL
72
75
  end
73
76
 
@@ -17,7 +17,7 @@ module PgSlice
17
17
  ]
18
18
 
19
19
  table.sequences.each do |sequence|
20
- queries << "ALTER SEQUENCE #{quote_ident(sequence["sequence_name"])} OWNED BY #{quote_table(table)}.#{quote_ident(sequence["related_column"])};"
20
+ queries << "ALTER SEQUENCE #{quote_ident(sequence["sequence_schema"])}.#{quote_ident(sequence["sequence_name"])} OWNED BY #{quote_table(table)}.#{quote_ident(sequence["related_column"])};"
21
21
  end
22
22
 
23
23
  queries.unshift("SET LOCAL lock_timeout = '#{options[:lock_timeout]}';") if server_version_num >= 90300
@@ -16,7 +16,7 @@ module PgSlice
16
16
  ]
17
17
 
18
18
  table.sequences.each do |sequence|
19
- queries << "ALTER SEQUENCE #{quote_ident(sequence["sequence_name"])} OWNED BY #{quote_table(table)}.#{quote_ident(sequence["related_column"])};"
19
+ queries << "ALTER SEQUENCE #{quote_ident(sequence["sequence_schema"])}.#{quote_ident(sequence["sequence_name"])} OWNED BY #{quote_table(table)}.#{quote_ident(sequence["related_column"])};"
20
20
  end
21
21
 
22
22
  run_queries(queries)
@@ -36,7 +36,11 @@ module PgSlice
36
36
  uri.query = URI.encode_www_form(params)
37
37
 
38
38
  ENV["PGCONNECT_TIMEOUT"] ||= "1"
39
- PG::Connection.new(uri.to_s)
39
+ conn = PG::Connection.new(uri.to_s)
40
+ conn.set_notice_processor do |message|
41
+ say message
42
+ end
43
+ conn
40
44
  end
41
45
  rescue PG::ConnectionBad => e
42
46
  abort e.message
@@ -23,15 +23,17 @@ module PgSlice
23
23
  def sequences
24
24
  query = <<-SQL
25
25
  SELECT
26
- a.attname as related_column,
27
- s.relname as sequence_name
26
+ a.attname AS related_column,
27
+ n.nspname AS sequence_schema,
28
+ s.relname AS sequence_name
28
29
  FROM pg_class s
29
- JOIN pg_depend d ON d.objid = s.oid
30
- JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid
31
- JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)
32
- JOIN pg_namespace n ON n.oid = s.relnamespace
30
+ INNER JOIN pg_depend d ON d.objid = s.oid
31
+ INNER JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid
32
+ INNER JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)
33
+ INNER JOIN pg_namespace n ON n.oid = s.relnamespace
34
+ INNER JOIN pg_namespace nt ON nt.oid = t.relnamespace
33
35
  WHERE s.relkind = 'S'
34
- AND n.nspname = $1
36
+ AND nt.nspname = $1
35
37
  AND t.relname = $2
36
38
  ORDER BY s.relname ASC
37
39
  SQL
@@ -109,6 +111,7 @@ module PgSlice
109
111
  (execute(query)[0]["min"] || 1).to_i
110
112
  end
111
113
 
114
+ # ensure this returns partitions in the correct order
112
115
  def partitions
113
116
  query = <<-SQL
114
117
  SELECT
@@ -1,3 +1,3 @@
1
1
  module PgSlice
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
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.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-29 00:00:00.000000000 Z
11
+ date: 2020-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor