table_saw 3.0.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +4 -2
- data/.rubocop.yml +1 -1
- data/.tool-versions +1 -1
- data/Appraisals +14 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +129 -84
- data/exe/table-saw +1 -0
- data/gemfiles/activerecord_6.1.0.gemfile +5 -2
- data/gemfiles/activerecord_6.1.0.gemfile.lock +89 -72
- data/gemfiles/activerecord_7.0.0.gemfile +5 -2
- data/gemfiles/activerecord_7.0.0.gemfile.lock +89 -72
- data/gemfiles/activerecord_7.1.0.gemfile +17 -0
- data/gemfiles/activerecord_7.1.0.gemfile.lock +206 -0
- data/gemfiles/activerecord_7.2.0.gemfile +17 -0
- data/gemfiles/activerecord_7.2.0.gemfile.lock +221 -0
- data/lib/table_saw/configuration.rb +1 -1
- data/lib/table_saw/create_dump_file.rb +3 -3
- data/lib/table_saw/dependency_graph/belongs_to_directives.rb +1 -1
- data/lib/table_saw/dependency_graph/build.rb +2 -2
- data/lib/table_saw/dependency_graph/dump_table.rb +1 -1
- data/lib/table_saw/dependency_graph/has_many_directives.rb +1 -1
- data/lib/table_saw/formats/copy.rb +1 -5
- data/lib/table_saw/formats/insert.rb +1 -1
- data/lib/table_saw/manifest.rb +1 -1
- data/lib/table_saw/queries/execute_insert_statement.rb +2 -6
- data/lib/table_saw/queries/foreign_key_relationships.rb +1 -1
- data/lib/table_saw/queries/materialized_views.rb +1 -1
- data/lib/table_saw/queries/prepared_insert_statement.rb +1 -1
- data/lib/table_saw/queries/serial_sequences.rb +1 -1
- data/lib/table_saw/queries/serialize_sql_in_clause.rb +1 -5
- data/lib/table_saw/version.rb +1 -1
- data/lib/table_saw.rb +18 -2
- data/table_saw.gemspec +2 -2
- metadata +10 -7
- data/lib/table_saw/connection.rb +0 -30
@@ -6,7 +6,7 @@ module TableSaw
|
|
6
6
|
attr_accessor :dbname, :host, :port, :user, :password, :manifest, :output, :format
|
7
7
|
|
8
8
|
def connection
|
9
|
-
{
|
9
|
+
{ adapter: 'postgresql', database: dbname, host:, port:, username: user, password: }
|
10
10
|
end
|
11
11
|
|
12
12
|
def url=(value)
|
@@ -51,9 +51,9 @@ module TableSaw
|
|
51
51
|
|
52
52
|
Array(formatter.header).each { |line| write_to_file(line) }
|
53
53
|
|
54
|
-
TableSaw
|
55
|
-
conn.copy_data "COPY (#{table.copy_statement}) TO STDOUT", formatter.coder do
|
56
|
-
while (row = conn.get_copy_data)
|
54
|
+
TableSaw.connection_pool.with_connection do |conn|
|
55
|
+
conn.raw_connection.copy_data "COPY (#{table.copy_statement}) TO STDOUT", formatter.coder do
|
56
|
+
while (row = conn.raw_connection.get_copy_data)
|
57
57
|
write_to_file formatter.dump_row(row)
|
58
58
|
end
|
59
59
|
end
|
@@ -37,7 +37,7 @@ module TableSaw
|
|
37
37
|
def query_result(foreign_key)
|
38
38
|
return [] unless directive.selectable?
|
39
39
|
|
40
|
-
TableSaw
|
40
|
+
TableSaw.connection.exec_query(
|
41
41
|
format(QUERY, column: foreign_key.column.primary_key, table_name: directive.table_name,
|
42
42
|
clause: TableSaw::Queries::SerializeSqlInClause.new(directive.table_name,
|
43
43
|
directive.primary_key,
|
@@ -33,7 +33,7 @@ module TableSaw
|
|
33
33
|
if record
|
34
34
|
dir.partial? ? record.fetch_associations(dir) : []
|
35
35
|
else
|
36
|
-
TableSaw::DependencyGraph::DumpTable.new(manifest
|
36
|
+
TableSaw::DependencyGraph::DumpTable.new(manifest:, name: dir.table_name, partial: dir.partial?)
|
37
37
|
.tap { |table| records[dir.table_name] = table }.fetch_associations(dir)
|
38
38
|
end
|
39
39
|
end
|
@@ -41,7 +41,7 @@ module TableSaw
|
|
41
41
|
def select_ids(table)
|
42
42
|
return [] unless table.partial?
|
43
43
|
|
44
|
-
TableSaw
|
44
|
+
TableSaw.connection.exec_query(table.query).map { |row| row[TableSaw.schema_cache.primary_keys(table.name)] }
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -15,7 +15,7 @@ module TableSaw
|
|
15
15
|
def copy_statement
|
16
16
|
if partial
|
17
17
|
format 'select * from %{name} where %{clause}',
|
18
|
-
name
|
18
|
+
name:, clause: TableSaw::Queries::SerializeSqlInClause.new(name, primary_key, ids.to_a).call
|
19
19
|
|
20
20
|
else
|
21
21
|
"select * from #{name}"
|
@@ -40,7 +40,7 @@ module TableSaw
|
|
40
40
|
def query_result(foreign_key)
|
41
41
|
return [] unless directive.selectable?
|
42
42
|
|
43
|
-
TableSaw
|
43
|
+
TableSaw.connection.exec_query(
|
44
44
|
TableSaw::DependencyGraph::BuildHasManyQuery.new(manifest, directive, foreign_key).call
|
45
45
|
)
|
46
46
|
end
|
@@ -20,13 +20,9 @@ module TableSaw
|
|
20
20
|
def quoted_columns
|
21
21
|
TableSaw.schema_cache.columns_hash(table_name)
|
22
22
|
.each_key
|
23
|
-
.map { |name| connection.quote_column_name(name) }
|
23
|
+
.map { |name| TableSaw.connection.quote_column_name(name) }
|
24
24
|
.join(', ')
|
25
25
|
end
|
26
|
-
|
27
|
-
def connection
|
28
|
-
TableSaw.schema_cache.connection
|
29
|
-
end
|
30
26
|
end
|
31
27
|
end
|
32
28
|
end
|
@@ -22,7 +22,7 @@ module TableSaw
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def prepared_statement
|
25
|
-
@prepared_statement ||= TableSaw::Queries::PreparedInsertStatement.new(table_name, options:
|
25
|
+
@prepared_statement ||= TableSaw::Queries::PreparedInsertStatement.new(table_name, options:).call
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/lib/table_saw/manifest.rb
CHANGED
@@ -66,7 +66,7 @@ module TableSaw
|
|
66
66
|
def self.instance
|
67
67
|
raise ArgumentError, 'Could not find manifest file' unless File.exist?(TableSaw.configuration.manifest)
|
68
68
|
|
69
|
-
new(YAML.
|
69
|
+
new(YAML.safe_load_file(TableSaw.configuration.manifest))
|
70
70
|
end
|
71
71
|
|
72
72
|
attr_reader :config
|
@@ -22,13 +22,9 @@ module TableSaw
|
|
22
22
|
.join(', ')
|
23
23
|
end
|
24
24
|
|
25
|
-
def connection
|
26
|
-
TableSaw.schema_cache.connection
|
27
|
-
end
|
28
|
-
|
29
25
|
def quote_value(column, value)
|
30
|
-
type = connection.lookup_cast_type_from_column(column)
|
31
|
-
connection.quote(type.serialize(type.deserialize(value)))
|
26
|
+
type = TableSaw.connection.lookup_cast_type_from_column(column)
|
27
|
+
TableSaw.connection.quote(type.serialize(type.deserialize(value)))
|
32
28
|
end
|
33
29
|
end
|
34
30
|
end
|
@@ -32,7 +32,7 @@ module TableSaw
|
|
32
32
|
|
33
33
|
def column_names
|
34
34
|
TableSaw.schema_cache.columns(table_name)
|
35
|
-
.map { |column| TableSaw.
|
35
|
+
.map { |column| TableSaw.connection.quote_column_name(column.name) }
|
36
36
|
.join(', ')
|
37
37
|
end
|
38
38
|
|
@@ -18,7 +18,7 @@ module TableSaw
|
|
18
18
|
SerialSequence = Struct.new(:name, :table, :column)
|
19
19
|
|
20
20
|
def call
|
21
|
-
TableSaw
|
21
|
+
TableSaw.connection.exec_query(QUERY).each_with_object({}) do |row, memo|
|
22
22
|
memo[row['table']] = SerialSequence.new(row['sequence'], row['table'], row['column'])
|
23
23
|
end
|
24
24
|
end
|
@@ -23,13 +23,9 @@ module TableSaw
|
|
23
23
|
|
24
24
|
def serialized_values
|
25
25
|
values.map do |value|
|
26
|
-
connection.quote_default_expression(value, db_column)
|
26
|
+
TableSaw.connection.quote_default_expression(value, db_column)
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
30
|
-
def connection
|
31
|
-
TableSaw::Connection.adapter
|
32
|
-
end
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
data/lib/table_saw/version.rb
CHANGED
data/lib/table_saw.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_record'
|
4
|
+
require 'active_support/core_ext/string'
|
5
|
+
|
3
6
|
require 'table_saw/configuration'
|
4
|
-
require 'table_saw/connection'
|
5
7
|
require 'table_saw/dependency_graph'
|
6
8
|
require 'table_saw/information_schema'
|
7
9
|
require 'table_saw/manifest'
|
@@ -29,6 +31,20 @@ module TableSaw
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def self.schema_cache
|
32
|
-
|
34
|
+
connection.schema_cache
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.connection_pool
|
38
|
+
ActiveRecord::Base.connection_pool
|
39
|
+
end
|
40
|
+
|
41
|
+
# :nocov:
|
42
|
+
def self.connection
|
43
|
+
if ActiveRecord.gem_version < Gem::Version.new('7.2.0')
|
44
|
+
connection_pool.connection
|
45
|
+
else
|
46
|
+
connection_pool.lease_connection
|
47
|
+
end
|
33
48
|
end
|
49
|
+
# :nocov:
|
34
50
|
end
|
data/table_saw.gemspec
CHANGED
@@ -23,10 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = ['table-saw']
|
24
24
|
spec.require_paths = ['lib']
|
25
25
|
|
26
|
-
spec.required_ruby_version = '>= 3.
|
26
|
+
spec.required_ruby_version = '>= 3.1'
|
27
27
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
28
28
|
|
29
|
-
spec.add_dependency 'activerecord', '>=
|
29
|
+
spec.add_dependency 'activerecord', '>= 6.1'
|
30
30
|
spec.add_dependency 'pg'
|
31
31
|
spec.add_dependency 'thor'
|
32
32
|
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: 3.
|
4
|
+
version: 3.2.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:
|
11
|
+
date: 2024-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pg
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,10 +79,13 @@ files:
|
|
79
79
|
- gemfiles/activerecord_6.1.0.gemfile.lock
|
80
80
|
- gemfiles/activerecord_7.0.0.gemfile
|
81
81
|
- gemfiles/activerecord_7.0.0.gemfile.lock
|
82
|
+
- gemfiles/activerecord_7.1.0.gemfile
|
83
|
+
- gemfiles/activerecord_7.1.0.gemfile.lock
|
84
|
+
- gemfiles/activerecord_7.2.0.gemfile
|
85
|
+
- gemfiles/activerecord_7.2.0.gemfile.lock
|
82
86
|
- lib/table_saw.rb
|
83
87
|
- lib/table_saw/associations.rb
|
84
88
|
- lib/table_saw/configuration.rb
|
85
|
-
- lib/table_saw/connection.rb
|
86
89
|
- lib/table_saw/create_dump_file.rb
|
87
90
|
- lib/table_saw/dependency_graph.rb
|
88
91
|
- lib/table_saw/dependency_graph/add_directive.rb
|
@@ -121,14 +124,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
124
|
requirements:
|
122
125
|
- - ">="
|
123
126
|
- !ruby/object:Gem::Version
|
124
|
-
version: '3.
|
127
|
+
version: '3.1'
|
125
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
129
|
requirements:
|
127
130
|
- - ">="
|
128
131
|
- !ruby/object:Gem::Version
|
129
132
|
version: '0'
|
130
133
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
134
|
+
rubygems_version: 3.5.11
|
132
135
|
signing_key:
|
133
136
|
specification_version: 4
|
134
137
|
summary: Create a postgres dump file from a subset of tables
|
data/lib/table_saw/connection.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_record'
|
4
|
-
|
5
|
-
require 'active_record/connection_adapters/abstract/connection_pool'
|
6
|
-
require 'active_record/connection_adapters/postgresql_adapter'
|
7
|
-
|
8
|
-
module TableSaw
|
9
|
-
module Connection
|
10
|
-
def self.with
|
11
|
-
raise ArgumentError, 'requires a block' unless block_given?
|
12
|
-
|
13
|
-
yield adapter.raw_connection
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.exec(sql)
|
17
|
-
TableSaw::Connection.with do |conn|
|
18
|
-
conn.exec(sql)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.adapter
|
23
|
-
@adapter ||= begin
|
24
|
-
config = TableSaw.configuration.connection
|
25
|
-
conn = ::PG::Connection.new(config)
|
26
|
-
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.new(conn, nil, config, {})
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|