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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9eefefd9392371161169e66ec7c6ecfc9e855dd
4
- data.tar.gz: e1b1b8b2cd5be52ca74dfad670e833176f41ac16
3
+ metadata.gz: b7f6c737f72e0f2069beade77ada0e12a8fcc27c
4
+ data.tar.gz: 1cfcbfe2d33e0962ae52d45093f37722aee588eb
5
5
  SHA512:
6
- metadata.gz: 86a0ddd76729246d2e3e81043d1e47af8fefd760ba358f2a11b716870bb68468dbd1d1765f516275fbd0746df99ebf9188ee9aff9c9b22f478ae2fecc4ca3a31
7
- data.tar.gz: bf10d81863eded6472abbb34f16b5284a5a99acbcf19142278d1852e8083b700dd7e7a565ecba94dfe69620762003e8fd426580d932db2eff2d9981644d0432e
6
+ metadata.gz: eeea42b422fdde212fcc28ff3231828a8193a3da60e04d462e6a4d8d306e6ca2f28a82dc67f304c6b663289d735e2c359a250a3c12d41bd406d4be5738d5f4b9
7
+ data.tar.gz: 272b24bb7655d230860f7037012cc88760813576e40a636fe5841c1dbc820cd586f6e042bbf268664bfaafad2b4b3bc48ae4e6e0b7494916d83451593f746e33
data/bin/gadget CHANGED
@@ -11,6 +11,8 @@ result = nil
11
11
  case command
12
12
  when 'columns'
13
13
  result = Gadget.columns(conn, cmdargs.shift)
14
+ when 'constraints'
15
+ result = Gadget.columns(conn, cmdargs.shift)
14
16
  when 'dependencies'
15
17
  result = Gadget.dependencies(conn)
16
18
  when 'dependency-graph'
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)
@@ -1,3 +1,3 @@
1
1
  module Gadget
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.1
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-19 00:00:00.000000000 Z
11
+ date: 2014-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg