pgslice 0.3.5 → 0.3.6

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
  SHA1:
3
- metadata.gz: 43cc2dd89adcb7a9ab6967e5d87b28d24e7e8c26
4
- data.tar.gz: f9661b8e3cdf0239c0ba2174bc0c5694f95d834a
3
+ metadata.gz: 07d87eec1238827086898708a5b4e026746a0c11
4
+ data.tar.gz: 76024edd24065ec3e24b74d72563583e01cecc6e
5
5
  SHA512:
6
- metadata.gz: 41176b19e45fd47d89d50f45b4a4cf9ab5802ed63b68100852e776dc0c821745a85cb80b2f942e5a445fa5752b696c0dce5a6fe6528477f26ec3673d41cbe94f
7
- data.tar.gz: 04d50a9863351b4b97928e8dfb5f8a018c5723e5daa473a4430c5ed41ff9db355ebb4d1f749a48ebc5eb3ebc7e88e84a8ab795edd394fbd351219a09d30071b8
6
+ metadata.gz: 9c6042dc4fe0d093c3b38c05d91b445ad1882241f5c3b814f4fe7124ae3609b591ead4d70de39ebf496164e72221ffb409703173689a0daa6f37f884e73dce45
7
+ data.tar.gz: b79e389ab3529ad08eadb2e18b6c374d40436007e4fe788e2898888e5caf5592b3839326fee9c4d8d658bbfd284c0c953683171d8789de826b86fa79b7d3354c
@@ -1,6 +1,11 @@
1
+ ## 0.3.6
2
+
3
+ - Fixed drop trigger on `unprep` for non-lowercase tables
4
+ - Fixed index creation for non-lowercase tables
5
+
1
6
  ## 0.3.5
2
7
 
3
- - Quote identifiers
8
+ - Added support for non-lowercase tables and columns
4
9
 
5
10
  ## 0.3.4
6
11
 
@@ -112,7 +112,7 @@ SQL
112
112
 
113
113
  queries = [
114
114
  "DROP TABLE #{quote_ident(intermediate_table)} CASCADE;",
115
- "DROP FUNCTION IF EXISTS #{trigger_name}();"
115
+ "DROP FUNCTION IF EXISTS #{quote_ident(trigger_name)}();"
116
116
  ]
117
117
  run_queries(queries)
118
118
  end
@@ -132,7 +132,7 @@ SQL
132
132
  # ensure table has trigger
133
133
  abort "No trigger on table: #{table}\nDid you mean to use --intermediate?" unless has_trigger?(trigger_name, table)
134
134
 
135
- index_defs = execute("SELECT pg_get_indexdef(indexrelid) FROM pg_index INNER JOIN pg_stat_user_indexes USING (indexrelid) WHERE relname = $1 AND schemaname = $2 AND indisprimary = 'f'", [original_table, schema]).map { |r| r["pg_get_indexdef"] }
135
+ index_defs = execute("SELECT pg_get_indexdef(indexrelid) FROM pg_index WHERE indrelid = #{regclass(schema, original_table)} AND indisprimary = 'f'").map { |r| r["pg_get_indexdef"] }
136
136
  primary_key = self.primary_key(table)
137
137
 
138
138
  queries = []
@@ -163,7 +163,7 @@ CREATE TABLE #{quote_ident(partition_name)}
163
163
  queries << "ALTER TABLE #{quote_ident(partition_name)} ADD PRIMARY KEY (#{quote_ident(primary_key)});" if primary_key
164
164
 
165
165
  index_defs.each do |index_def|
166
- queries << index_def.sub(" ON #{original_table} USING ", " ON #{partition_name} USING ").sub(/ INDEX .+ ON /, " INDEX ON ") + ";"
166
+ queries << index_def.sub(/ ON \S+ USING /, " ON #{quote_ident(partition_name)} USING ").sub(/ INDEX .+ ON /, " INDEX ON ") + ";"
167
167
  end
168
168
  end
169
169
 
@@ -172,7 +172,7 @@ CREATE TABLE #{quote_ident(partition_name)}
172
172
  future_defs = []
173
173
  past_defs = []
174
174
  name_format = self.name_format(period)
175
- existing_tables = self.existing_tables(like: "#{original_table}_%").select { |t| /\A#{Regexp.escape("#{original_table}_")}\d{6,8}\z/.match(t) }
175
+ existing_tables = existing_partitions(original_table)
176
176
  existing_tables = (existing_tables + added_partitions).uniq.sort
177
177
 
178
178
  existing_tables.each do |table|
@@ -236,7 +236,7 @@ CREATE OR REPLACE FUNCTION #{quote_ident(trigger_name)}()
236
236
  if period
237
237
  name_format = self.name_format(period)
238
238
 
239
- existing_tables = self.existing_tables(like: "#{table}_%").select { |t| /\A#{Regexp.escape("#{table}_")}\d{6,8}\z/.match(t) }.sort
239
+ existing_tables = existing_partitions(table)
240
240
  if existing_tables.any?
241
241
  starting_time = DateTime.strptime(existing_tables.first.split("_").last, name_format)
242
242
  ending_time = advance_date(DateTime.strptime(existing_tables.last.split("_").last, name_format), period, 1)
@@ -315,7 +315,7 @@ INSERT INTO #{quote_ident(dest_table)} (#{fields})
315
315
  ]
316
316
 
317
317
  self.sequences(table).each do |sequence|
318
- queries << "ALTER SEQUENCE #{quote_ident(sequence["sequence_name"])} OWNED BY #{table}.#{sequence["related_column"]};"
318
+ queries << "ALTER SEQUENCE #{quote_ident(sequence["sequence_name"])} OWNED BY #{quote_ident(table)}.#{quote_ident(sequence["related_column"])};"
319
319
  end
320
320
 
321
321
  queries.unshift("SET LOCAL lock_timeout = '#{options[:lock_timeout]}';") if server_version_num >= 90300
@@ -339,7 +339,7 @@ INSERT INTO #{quote_ident(dest_table)} (#{fields})
339
339
  ]
340
340
 
341
341
  self.sequences(table).each do |sequence|
342
- queries << "ALTER SEQUENCE #{quote_ident(sequence["sequence_name"])} OWNED BY #{table}.#{sequence["related_column"]};"
342
+ queries << "ALTER SEQUENCE #{quote_ident(sequence["sequence_name"])} OWNED BY #{quote_ident(table)}.#{quote_ident(sequence["related_column"])};"
343
343
  end
344
344
 
345
345
  run_queries(queries)
@@ -351,7 +351,7 @@ INSERT INTO #{quote_ident(dest_table)} (#{fields})
351
351
 
352
352
  abort "Usage: pgslice analyze <table>" if arguments.length != 1
353
353
 
354
- existing_tables = self.existing_tables(like: "#{table}_%").select { |t| /\A#{Regexp.escape("#{table}_")}\d{6,8}\z/.match(t) }
354
+ existing_tables = existing_partitions(table)
355
355
  analyze_list = existing_tables + [parent_table]
356
356
  run_queries_without_transaction analyze_list.map { |t| "ANALYZE VERBOSE #{quote_ident(t)};" }
357
357
  end
@@ -464,6 +464,10 @@ INSERT INTO #{quote_ident(dest_table)} (#{fields})
464
464
  execute("SHOW server_version_num")[0]["server_version_num"].to_i
465
465
  end
466
466
 
467
+ def existing_partitions(table)
468
+ existing_tables(like: "#{table}_%").select { |t| /\A#{Regexp.escape("#{table}_")}\d{6,8}\z/.match(t) }
469
+ end
470
+
467
471
  def existing_tables(like:)
468
472
  query = "SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = $1 AND tablename LIKE $2"
469
473
  execute(query, [schema, like]).map { |r| r["tablename"] }.sort
@@ -599,8 +603,12 @@ INSERT INTO #{quote_ident(dest_table)} (#{fields})
599
603
  PG::Connection.quote_ident(value)
600
604
  end
601
605
 
606
+ def regclass(schema, table)
607
+ "'#{quote_ident(schema)}.#{quote_ident(table)}'::regclass"
608
+ end
609
+
602
610
  def fetch_trigger(trigger_name, table)
603
- execute("SELECT obj_description(oid, 'pg_trigger') AS comment FROM pg_trigger WHERE tgname = $1 AND EXISTS (SELECT 1 FROM pg_stat_user_tables WHERE relid = tgrelid AND relname = $2 AND schemaname = $3)", [trigger_name, table, schema])[0]
611
+ execute("SELECT obj_description(oid, 'pg_trigger') AS comment FROM pg_trigger WHERE tgname = $1 AND tgrelid = #{regclass(schema, table)}", [trigger_name])[0]
604
612
  end
605
613
 
606
614
  def settings_from_trigger(original_table, table)
@@ -1,3 +1,3 @@
1
1
  module PgSlice
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
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.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-07 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop