table_saw 0.4.0 → 0.5.0

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: 1339fbe2ad8b61d13d84595da082e4bd8886f9ecb56e1c8ce55ba9b5d9d33304
4
- data.tar.gz: 79e448b1ee7d8f77a019b491ed5cbe11e4b5ca353721643211543813a779b856
3
+ metadata.gz: fb4c657ec087524b5db0ab9619be50b819d5b65ba1f410bfcc20b04cebc55123
4
+ data.tar.gz: a82d41d12074742fa1a120322dca716d378d8ee1a5e78ca30820176f2e44b37a
5
5
  SHA512:
6
- metadata.gz: 49bf13e6be2584987b29755ca760fced988ff01f7f8ad362a2cb35122f83da8de7b1de37c0f02d32bee9dee733b0d9c517d515dc5134cb00a4e08c26f57af9c1
7
- data.tar.gz: 290706ba80434334c9d4af235e84972018bad3d2ef009eb85ee288ce6e7739fb669e1ba428e8060e6c1509910a0cdb0bffe05f26fdeee562772b69d41c1fe687
6
+ metadata.gz: 1069f4020c08827258a12e14433e6782c2824c5e58917251433636f6e8b5ca5a951d0f67edc582cc893a36b6f3642dce484bd76649f01bdab2e4d750496c4607
7
+ data.tar.gz: 4c7ff84820fdd86ebd72ceee70d22707bc39efe05264d7ee46888f2459b0433c769125e1d9142623265b02e300438d09d9ff53a92109b44e57e1ee55b7c0d81b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- table_saw (0.4.0)
4
+ table_saw (0.5.0)
5
5
  connection_pool
6
6
  pg
7
7
  thor
@@ -11,6 +11,8 @@ module TableSaw
11
11
 
12
12
  # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
13
13
  def call
14
+ File.delete(file) if File.exist?(file)
15
+
14
16
  write_to_file <<~SQL
15
17
  BEGIN;
16
18
 
@@ -67,9 +69,9 @@ module TableSaw
67
69
  end
68
70
 
69
71
  def restart_sequences
70
- records.each_key do |table|
72
+ TableSaw::Queries::SerialSequences.new.call.slice(*records.keys).each do |table, sequence|
71
73
  write_to_file <<~SQL
72
- select setval(pg_get_serial_sequence('#{table}', 'id'), (select max(id) from #{table}), true);
74
+ select setval('#{sequence.name}', (select max(#{sequence.column}) from #{table}), true);
73
75
  SQL
74
76
  end
75
77
 
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TableSaw
4
+ module Queries
5
+ class SerialSequences
6
+ QUERY = <<~SQL
7
+ select
8
+ pg_get_serial_sequence(kcu.table_name, kcu.column_name) as sequence,
9
+ kcu.table_name as table,
10
+ kcu.column_name as column
11
+ from information_schema.key_column_usage as kcu
12
+ inner join information_schema.table_constraints as tc
13
+ on tc.constraint_name = kcu.constraint_name
14
+ where tc.constraint_type = 'PRIMARY KEY'
15
+ and pg_get_serial_sequence(kcu.table_name, kcu.column_name) is not null
16
+ SQL
17
+
18
+ SerialSequence = Struct.new(:name, :table, :column)
19
+
20
+ def call
21
+ TableSaw::Connection.with do |conn|
22
+ conn.exec(QUERY).each_with_object({}) do |row, memo|
23
+ memo[row['table']] = SerialSequence.new(row['sequence'], row['table'], row['column'])
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -3,4 +3,5 @@
3
3
  require 'table_saw/queries/foreign_key_relationships'
4
4
  require 'table_saw/queries/materialized_views'
5
5
  require 'table_saw/queries/no_id_tables'
6
+ require 'table_saw/queries/serial_sequences'
6
7
  require 'table_saw/queries/table_columns'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TableSaw
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_saw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamed Asghari
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-14 00:00:00.000000000 Z
11
+ date: 2019-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -231,6 +231,7 @@ files:
231
231
  - lib/table_saw/queries/foreign_key_relationships.rb
232
232
  - lib/table_saw/queries/materialized_views.rb
233
233
  - lib/table_saw/queries/no_id_tables.rb
234
+ - lib/table_saw/queries/serial_sequences.rb
234
235
  - lib/table_saw/queries/table_columns.rb
235
236
  - lib/table_saw/version.rb
236
237
  - table_saw.gemspec