pg_graph 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/exe/pg_graph +31 -14
- data/lib/pg_graph/inflector.rb +3 -2
- data/lib/pg_graph/version.rb +1 -1
- data/pg_graph.gemspec +4 -4
- metadata +21 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28f5cb17edb384621612f29426084e14f15db45572e5ba80482776b4ca04b3ce
|
4
|
+
data.tar.gz: e2b1cf4db09e79d2a2d726dbd4ecdaa22fc82ddc4fbd94e9b10cb15220712096
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27ab8c10fbf8717e6086983cab0ce5cc32908c41c4d66402031a5bbac12b9ea623f095a4d9a9b6ac02018b34eac6dc2718be50c7c6449698008ea2b348baa4be
|
7
|
+
data.tar.gz: 8eca990262bb1e8fde6e5dcab49a40a2677ce368528d9485e4742c924cab1225994ac68d9e8f507f18e671ca413998cb73819b2a671cc2476dd850444754979e
|
data/Gemfile
CHANGED
data/exe/pg_graph
CHANGED
@@ -6,8 +6,21 @@ require "pg_graph/timer.rb"
|
|
6
6
|
|
7
7
|
include ShellOpts
|
8
8
|
|
9
|
-
PROGRAM = File.basename($PROGRAM_NAME)
|
10
9
|
SPEC = %(
|
10
|
+
@ Load, dump, and clean databases
|
11
|
+
|
12
|
+
pg_graph is a utility that uses the PgGraph module to load, dump, or clean a
|
13
|
+
database. It uses a variety of formats that can be executed by psql(1)
|
14
|
+
('psql') or by the Postgres library exec() call ('exec', 'sql'). It can also
|
15
|
+
read and write Yaml data ('yaml'). The dump command can also write the meta
|
16
|
+
data and type of the database in yaml format which is useful for debugging.
|
17
|
+
|
18
|
+
The default is to dump the type in yaml format, this is also the typical use
|
19
|
+
of pg_graph because dump of data is better done using 'pg_dump -a <database>'
|
20
|
+
except in the special case when the data contains circular foreign-key
|
21
|
+
constraints and the load command is run by an ordinary user. The load command
|
22
|
+
is useful when you want to read Yaml data from other programs into the database
|
23
|
+
|
11
24
|
-m,meta=EFILE @ Load meta data from YAML file
|
12
25
|
Make pg_graph loads its meta data in YAML format from FILE instead of
|
13
26
|
querying the database
|
@@ -22,15 +35,25 @@ SPEC = %(
|
|
22
35
|
-f,format=FORMAT:sql,exec,psql,yaml
|
23
36
|
Input/output format. Can be one of 'sql', 'exec', 'psql', or 'yaml' (default)
|
24
37
|
|
38
|
+
The 'psql' format is meant to be fed to the psql(1) command and contains
|
39
|
+
psql(1) meta-commands to silence the output and to terminate on any error.
|
40
|
+
The 'sql' format expects the database triggers to have been disabled
|
41
|
+
beforehand while the 'exec' format includes statements to disble triggers.
|
42
|
+
The 'exec' format also resets serials
|
43
|
+
|
44
|
+
The yaml format only contains the data and can be loaded by pg_graph.
|
45
|
+
Triggers will be disabled while loading and ID's restored afterwards
|
46
|
+
|
25
47
|
-k,kind=KIND:meta,type,data
|
26
48
|
Output kind. Can be one of 'meta', 'type' (the default), or 'data'
|
27
49
|
|
28
50
|
-t,time
|
29
|
-
|
51
|
+
Emit timings for process
|
30
52
|
|
31
|
-
load! -- [FILE]
|
53
|
+
load! -- DATABASE [FILE]
|
32
54
|
Loads data into the database. The file format is determined by the file's
|
33
|
-
extension but can also be set explicitly using the --format option.
|
55
|
+
extension but can also be set explicitly using the --format option. Reads
|
56
|
+
from standard input if FILE is missing
|
34
57
|
|
35
58
|
dump! -- DATABASE
|
36
59
|
Dumps data on standard output. Default is to dump the type system in yaml
|
@@ -61,20 +84,14 @@ def load_type(timer, opts, database)
|
|
61
84
|
[connection, type]
|
62
85
|
end
|
63
86
|
|
64
|
-
opts, args = ShellOpts::ShellOpts.process(SPEC, ARGV)
|
87
|
+
opts, args = ShellOpts::ShellOpts.process(SPEC, ARGV, :version => PgGraph::VERSION)
|
65
88
|
|
66
89
|
timing = opts.time?
|
67
90
|
timer = Timer::Timer.new
|
68
91
|
|
69
|
-
# Process options
|
70
|
-
meta = opts.meta
|
71
|
-
reflections = opts.reflections
|
72
|
-
kind = opts.kind || "type"
|
73
|
-
format = opts.format || "yaml"
|
74
|
-
|
75
92
|
case opts.subcommand || :dump!
|
76
93
|
when :load!
|
77
|
-
database = args.
|
94
|
+
database = args.extract(1)
|
78
95
|
file = args.expect(0..1) || "/dev/stdin"
|
79
96
|
|
80
97
|
if opts.format?
|
@@ -112,7 +129,7 @@ case opts.subcommand || :dump!
|
|
112
129
|
when :dump!
|
113
130
|
database = args.expect(1)
|
114
131
|
|
115
|
-
case kind
|
132
|
+
case opts.kind || "type"
|
116
133
|
when "meta"
|
117
134
|
connection = timer.time("connect") { PgConn.new(database) if !opts.meta? }
|
118
135
|
meta = timer.time("meta") { opts.meta? ? PgMeta.load_file(opts.meta) : PgMeta.new(connection) }
|
@@ -124,7 +141,7 @@ case opts.subcommand || :dump!
|
|
124
141
|
connection, type = load_type(timer, opts, database)
|
125
142
|
data = timer.time("instantiate") { type.instantiate(connection) }
|
126
143
|
timer.time("dump") {
|
127
|
-
case format
|
144
|
+
case opts.format || "yaml"
|
128
145
|
when "sql"; puts data.to_sql
|
129
146
|
when "exec"; puts data.to_exec_sql
|
130
147
|
when "psql"; puts data.to_psql_sql
|
data/lib/pg_graph/inflector.rb
CHANGED
@@ -86,7 +86,8 @@ module PgGraph
|
|
86
86
|
case name
|
87
87
|
when "character varying", "varchar", "text", "uuid"; String
|
88
88
|
when "smallint", "integer", "int4", "int2"; Integer
|
89
|
-
when "double precision", "
|
89
|
+
when "double precision", "real"; Float
|
90
|
+
when "numeric", "decimal"; BigDecimal
|
90
91
|
when "bool", "boolean"; Boolean
|
91
92
|
when "json"; Hash
|
92
93
|
when "bytea"; String
|
@@ -97,7 +98,7 @@ module PgGraph
|
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
100
|
-
SUPPORTED_RUBY_CLASSES = [String, Integer, Float, Boolean, Hash, Time, NilClass, Array]
|
101
|
+
SUPPORTED_RUBY_CLASSES = [String, Integer, Float, BigDecimal, Boolean, Hash, Time, NilClass, Array]
|
101
102
|
end
|
102
103
|
|
103
104
|
def self.inflector() @inflector ||= Inflector.new end
|
data/lib/pg_graph/version.rb
CHANGED
data/pg_graph.gemspec
CHANGED
@@ -28,12 +28,12 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_dependency "constrain"
|
29
29
|
spec.add_dependency "developer_exceptions"
|
30
30
|
spec.add_dependency "dry-inflector"
|
31
|
-
spec.add_dependency "hash_tree", "= 0.1.1"
|
32
31
|
spec.add_dependency "indented_io"
|
33
|
-
spec.add_dependency "shellopts", "2.0.6"
|
34
32
|
|
35
|
-
spec.add_dependency "
|
36
|
-
spec.add_dependency "
|
33
|
+
spec.add_dependency "hash_tree"
|
34
|
+
spec.add_dependency "shellopts", "~> 2.0.9"
|
35
|
+
spec.add_dependency "pg_conn"
|
36
|
+
spec.add_dependency "pg_meta"
|
37
37
|
|
38
38
|
# Also un-comment in spec/spec_helper to use simplecov
|
39
39
|
# spec.add_development_dependency "simplecov"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: boolean
|
@@ -67,21 +67,21 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: indented_io
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
75
|
+
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: hash_tree
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -98,44 +98,44 @@ dependencies:
|
|
98
98
|
name: shellopts
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 2.0.
|
103
|
+
version: 2.0.9
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 2.0.
|
110
|
+
version: 2.0.9
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: pg_conn
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0
|
117
|
+
version: '0'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0
|
124
|
+
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: pg_meta
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0
|
131
|
+
version: '0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0
|
138
|
+
version: '0'
|
139
139
|
description: dwpg_graph gem
|
140
140
|
email:
|
141
141
|
- claus.l.rasmussen@gmail.com
|
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
198
|
- !ruby/object:Gem::Version
|
199
199
|
version: '0'
|
200
200
|
requirements: []
|
201
|
-
rubygems_version: 3.
|
201
|
+
rubygems_version: 3.1.4
|
202
202
|
signing_key:
|
203
203
|
specification_version: 4
|
204
204
|
summary: Create graph type model of database
|