gadget 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/gadget +2 -0
- data/lib/gadget.rb +45 -0
- data/lib/gadget/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7f6c737f72e0f2069beade77ada0e12a8fcc27c
|
4
|
+
data.tar.gz: 1cfcbfe2d33e0962ae52d45093f37722aee588eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eeea42b422fdde212fcc28ff3231828a8193a3da60e04d462e6a4d8d306e6ca2f28a82dc67f304c6b663289d735e2c359a250a3c12d41bd406d4be5738d5f4b9
|
7
|
+
data.tar.gz: 272b24bb7655d230860f7037012cc88760813576e40a636fe5841c1dbc820cd586f6e042bbf268664bfaafad2b4b3bc48ae4e6e0b7494916d83451593f746e33
|
data/bin/gadget
CHANGED
data/lib/gadget.rb
CHANGED
@@ -79,6 +79,51 @@ AND pg_constraint.contype = 'f'
|
|
79
79
|
tuples
|
80
80
|
end
|
81
81
|
|
82
|
+
def self.constraints(conn, tablename = nil)
|
83
|
+
sql = <<-END_OF_SQL
|
84
|
+
SELECT pg_constraint.conname AS name,
|
85
|
+
pg_constraint.contype AS constrainttype,
|
86
|
+
t.tablename AS tablename
|
87
|
+
FROM pg_catalog.pg_constraint
|
88
|
+
INNER JOIN pg_catalog.pg_class c ON pg_constraint.conrelid = c.oid
|
89
|
+
INNER JOIN pg_catalog.pg_tables t ON c.relname = t.tablename
|
90
|
+
WHERE t.schemaname = 'public'
|
91
|
+
END_OF_SQL
|
92
|
+
if tablename.nil?
|
93
|
+
rs = conn.exec(sql)
|
94
|
+
else
|
95
|
+
sql += " AND t.tablename = $1"
|
96
|
+
rs = conn.exec_params(sql, [ tablename ])
|
97
|
+
end
|
98
|
+
tuples = rs.reduce({}) do | h, row |
|
99
|
+
name = row['tablename']
|
100
|
+
h[name] ||= { :refs => [] }
|
101
|
+
new_ref = {
|
102
|
+
:name => row['name'],
|
103
|
+
:kind => case row['constrainttype']
|
104
|
+
when 'c'
|
105
|
+
'check'
|
106
|
+
when 'f'
|
107
|
+
'foreign key'
|
108
|
+
when 'p'
|
109
|
+
'primary key'
|
110
|
+
when 't'
|
111
|
+
'trigger'
|
112
|
+
when 'u'
|
113
|
+
'unique'
|
114
|
+
when 'x'
|
115
|
+
'exclusion'
|
116
|
+
else
|
117
|
+
"*** unknown: '#{row['constrainttype']}'"
|
118
|
+
end,
|
119
|
+
}
|
120
|
+
h[name][:refs] << new_ref
|
121
|
+
h
|
122
|
+
end
|
123
|
+
rs.clear
|
124
|
+
tuples
|
125
|
+
end
|
126
|
+
|
82
127
|
def self.dependencies(conn)
|
83
128
|
tables = self.tables(conn)
|
84
129
|
foreign_keys = self.foreign_keys(conn)
|
data/lib/gadget/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gadget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig S. Cottingham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|