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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/table_saw/create_dump_file.rb +4 -2
- data/lib/table_saw/queries/serial_sequences.rb +29 -0
- data/lib/table_saw/queries.rb +1 -0
- data/lib/table_saw/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb4c657ec087524b5db0ab9619be50b819d5b65ba1f410bfcc20b04cebc55123
|
4
|
+
data.tar.gz: a82d41d12074742fa1a120322dca716d378d8ee1a5e78ca30820176f2e44b37a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1069f4020c08827258a12e14433e6782c2824c5e58917251433636f6e8b5ca5a951d0f67edc582cc893a36b6f3642dce484bd76649f01bdab2e4d750496c4607
|
7
|
+
data.tar.gz: 4c7ff84820fdd86ebd72ceee70d22707bc39efe05264d7ee46888f2459b0433c769125e1d9142623265b02e300438d09d9ff53a92109b44e57e1ee55b7c0d81b
|
data/Gemfile.lock
CHANGED
@@ -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.
|
72
|
+
TableSaw::Queries::SerialSequences.new.call.slice(*records.keys).each do |table, sequence|
|
71
73
|
write_to_file <<~SQL
|
72
|
-
select setval(
|
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
|
data/lib/table_saw/queries.rb
CHANGED
data/lib/table_saw/version.rb
CHANGED
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
|
+
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-
|
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
|