author | Radek Brich <radek.brich@devl.cz> |
Sat, 29 Sep 2012 14:01:47 +0200 | |
changeset 50 | f71d3abbb18f |
parent 40 | 922d7fb63384 |
child 52 | 26121a8fe78b |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
2 |
# |
|
3 |
# PgBrowser - browse database schema and metadata |
|
4 |
# |
|
5 |
# Some of the queries came from psql. |
|
6 |
# |
|
7 |
# Copyright (c) 2011 Radek Brich <radek.brich@devl.cz> |
|
8 |
# |
|
9 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
|
10 |
# of this software and associated documentation files (the "Software"), to deal |
|
11 |
# in the Software without restriction, including without limitation the rights |
|
12 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
13 |
# copies of the Software, and to permit persons to whom the Software is |
|
14 |
# furnished to do so, subject to the following conditions: |
|
15 |
# |
|
16 |
# The above copyright notice and this permission notice shall be included in |
|
17 |
# all copies or substantial portions of the Software. |
|
18 |
# |
|
19 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
20 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
21 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
22 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
23 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
24 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
25 |
# THE SOFTWARE. |
|
26 |
||
27 |
||
28 |
from collections import OrderedDict |
|
29 |
||
30 |
||
31 |
class Column: |
|
32 |
def __init__(self, browser, table, |
|
33 |
name, type, notnull, hasdefault, default, description): |
|
34 |
self.browser = browser # Browser instance |
|
35 |
self.table = table # Table instance |
|
36 |
self.name = name |
|
37 |
self.type = type |
|
38 |
self.notnull = notnull |
|
39 |
self.hasdefault = hasdefault |
|
40 |
self.default = default |
|
41 |
self.description = description |
|
42 |
||
43 |
||
44 |
class Constraint: |
|
40
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
45 |
def __init__(self, browser, table, name, type, fname, fschema, definition): |
0 | 46 |
self.browser = browser |
47 |
self.table = table |
|
48 |
self.name = name |
|
49 |
self.type = type |
|
40
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
50 |
self.fname = fname # foreign table name |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
51 |
self.fschema = fschema # foreign table schema |
0 | 52 |
self.definition = definition |
53 |
||
54 |
||
55 |
class Index: |
|
56 |
def __init__(self, browser, table, |
|
57 |
name, primary, unique, clustered, valid, definition): |
|
58 |
self.browser = browser |
|
59 |
self.table = table |
|
60 |
self.name = name |
|
61 |
self.primary = primary |
|
62 |
self.unique = unique |
|
63 |
self.clustered = clustered |
|
64 |
self.valid = valid |
|
65 |
self.definition = definition |
|
66 |
||
67 |
||
68 |
class Table: |
|
69 |
def __init__(self, browser, schema, name, owner, size, description): |
|
70 |
self._columns = None |
|
71 |
self._constraints = None |
|
72 |
self._indexes = None |
|
73 |
self.browser = browser # Browser instance |
|
74 |
self.schema = schema # Schema instance |
|
75 |
self.name = name # table name, str |
|
76 |
self.owner = owner |
|
77 |
self.size = size |
|
78 |
self.description = description |
|
79 |
||
80 |
def refresh(self): |
|
81 |
self.refresh_columns() |
|
82 |
self.refresh_constraints() |
|
83 |
self.refresh_indexes() |
|
84 |
||
85 |
def refresh_columns(self): |
|
86 |
rows = self.browser.list_columns(self.name, self.schema.name) |
|
87 |
self._columns = OrderedDict([(x['name'], Column(self.browser, self, **x)) for x in rows]) |
|
88 |
||
89 |
def refresh_constraints(self): |
|
90 |
rows = self.browser.list_constraints(self.name, self.schema.name) |
|
91 |
self._constraints = OrderedDict([(x['name'], Constraint(self.browser, self, **x)) for x in rows]) |
|
92 |
||
93 |
def refresh_indexes(self): |
|
94 |
rows = self.browser.list_indexes(self.name, self.schema.name) |
|
95 |
self._indexes = OrderedDict([(x['name'], Index(self.browser, self, **x)) for x in rows]) |
|
96 |
||
97 |
def getcolumns(self): |
|
98 |
if self._columns is None: |
|
99 |
self.refresh_columns() |
|
100 |
return self._columns |
|
101 |
columns = property(getcolumns) |
|
102 |
||
103 |
def getconstraints(self): |
|
104 |
if self._constraints is None: |
|
105 |
self.refresh_constraints() |
|
106 |
return self._constraints |
|
107 |
constraints = property(getconstraints) |
|
108 |
||
109 |
def getindexes(self): |
|
110 |
if self._indexes is None: |
|
111 |
self.refresh_indexes() |
|
112 |
return self._indexes |
|
113 |
indexes = property(getindexes) |
|
114 |
||
115 |
class Schema: |
|
116 |
def __init__(self, browser, name, owner, acl, description, system): |
|
117 |
self._tables = None |
|
118 |
self.browser = browser |
|
119 |
self.name = name |
|
120 |
self.owner = owner |
|
121 |
self.acl = acl |
|
122 |
self.description = description |
|
123 |
self.system = system |
|
124 |
||
125 |
def refresh(self): |
|
126 |
rows = self.browser.list_tables(self.name) |
|
127 |
self._tables = OrderedDict([(x['name'], Table(self.browser, self, **x)) for x in rows]) |
|
128 |
||
129 |
def gettables(self): |
|
130 |
if self._tables is None: |
|
131 |
self.refresh() |
|
132 |
return self._tables |
|
133 |
tables = property(gettables) |
|
134 |
||
135 |
||
136 |
class PgBrowser: |
|
137 |
def __init__(self, conn=None): |
|
138 |
self._schemas = None |
|
139 |
self.conn = conn |
|
140 |
||
141 |
def setconn(self, conn=None): |
|
142 |
self.conn = conn |
|
143 |
||
144 |
def refresh(self): |
|
145 |
rows = self.list_schemas() |
|
146 |
self._schemas = OrderedDict([(x['name'], Schema(self, **x)) for x in rows]) |
|
147 |
||
148 |
def getschemas(self): |
|
149 |
if self._schemas is None: |
|
150 |
self.refresh() |
|
151 |
return self._schemas |
|
152 |
schemas = property(getschemas) |
|
153 |
||
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
154 |
def _query(self, query, args): |
0 | 155 |
try: |
156 |
curs = self.conn.cursor() |
|
157 |
curs.execute(query, args) |
|
158 |
curs.connection.commit() |
|
159 |
rows = curs.fetchall() |
|
160 |
return [dict(zip([desc[0] for desc in curs.description], row)) for row in rows] |
|
161 |
finally: |
|
162 |
curs.close() |
|
163 |
||
164 |
def list_databases(self): |
|
165 |
return self._query(''' |
|
166 |
SELECT |
|
167 |
d.datname as "name", |
|
168 |
pg_catalog.pg_get_userbyid(d.datdba) as "owner", |
|
169 |
pg_catalog.pg_encoding_to_char(d.encoding) as "encoding", |
|
170 |
d.datcollate as "collation", |
|
171 |
d.datctype as "ctype", |
|
172 |
d.datacl AS "acl", |
|
173 |
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT') |
|
174 |
THEN pg_catalog.pg_database_size(d.datname) |
|
175 |
ELSE -1 -- No access |
|
176 |
END as "size", |
|
177 |
t.spcname as "tablespace", |
|
178 |
pg_catalog.shobj_description(d.oid, 'pg_database') as "description" |
|
179 |
FROM pg_catalog.pg_database d |
|
180 |
JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid |
|
181 |
ORDER BY 1; |
|
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
182 |
''', []) |
0 | 183 |
|
184 |
def list_schemas(self): |
|
185 |
return self._query(''' |
|
186 |
SELECT |
|
187 |
n.nspname AS "name", |
|
188 |
pg_catalog.pg_get_userbyid(n.nspowner) AS "owner", |
|
189 |
n.nspacl AS "acl", |
|
190 |
pg_catalog.obj_description(n.oid, 'pg_namespace') AS "description", |
|
191 |
CASE WHEN n.nspname IN ('information_schema', 'pg_catalog', 'pg_toast') |
|
192 |
OR n.nspname ~ '^pg_temp_' OR n.nspname ~ '^pg_toast_temp_' |
|
193 |
THEN TRUE |
|
194 |
ELSE FALSE |
|
195 |
END AS "system" |
|
196 |
FROM pg_catalog.pg_namespace n |
|
197 |
ORDER BY 1; |
|
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
198 |
''', []) |
0 | 199 |
|
200 |
def list_tables(self, schema='public'): |
|
201 |
return self._query(''' |
|
202 |
SELECT |
|
203 |
c.relname as "name", |
|
204 |
pg_catalog.pg_get_userbyid(c.relowner) as "owner", |
|
205 |
pg_catalog.pg_relation_size(c.oid) as "size", |
|
206 |
pg_catalog.obj_description(c.oid, 'pg_class') as "description" |
|
207 |
FROM pg_catalog.pg_class c |
|
208 |
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace |
|
209 |
WHERE n.nspname = %s AND c.relkind IN ('r','s','') |
|
210 |
ORDER BY 1; |
|
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
211 |
''', [schema]) |
0 | 212 |
|
12 | 213 |
def list_columns(self, table, schema='public', order=2): |
0 | 214 |
return self._query(''' |
215 |
SELECT |
|
40
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
216 |
--a.attrelid, |
0 | 217 |
a.attname as "name", |
218 |
format_type(a.atttypid, a.atttypmod) AS "type", |
|
219 |
a.attnotnull as "notnull", |
|
220 |
a.atthasdef as "hasdefault", |
|
221 |
d.adsrc as "default", |
|
222 |
pg_catalog.col_description(a.attrelid, a.attnum) AS "description" |
|
223 |
FROM pg_catalog.pg_attribute a |
|
224 |
LEFT JOIN pg_catalog.pg_class c ON a.attrelid = c.oid |
|
225 |
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace |
|
226 |
LEFT JOIN pg_catalog.pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum |
|
227 |
WHERE n.nspname = %s AND c.relname = %s AND a.attnum > 0 AND NOT a.attisdropped |
|
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
228 |
ORDER BY ''' + str(order), [schema, table]) |
0 | 229 |
|
230 |
def list_constraints(self, table, schema='public'): |
|
231 |
return self._query(''' |
|
232 |
SELECT |
|
35
e7f79c4a27ce
TableCopyTool: order tables with respect to references.
Radek Brich <radek.brich@devl.cz>
parents:
32
diff
changeset
|
233 |
r.conname AS "name", |
e7f79c4a27ce
TableCopyTool: order tables with respect to references.
Radek Brich <radek.brich@devl.cz>
parents:
32
diff
changeset
|
234 |
r.contype AS "type", |
e7f79c4a27ce
TableCopyTool: order tables with respect to references.
Radek Brich <radek.brich@devl.cz>
parents:
32
diff
changeset
|
235 |
cf.relname AS "fname", |
e7f79c4a27ce
TableCopyTool: order tables with respect to references.
Radek Brich <radek.brich@devl.cz>
parents:
32
diff
changeset
|
236 |
nf.nspname AS "fschema", |
0 | 237 |
pg_catalog.pg_get_constraintdef(r.oid, true) as "definition" |
238 |
FROM pg_catalog.pg_constraint r |
|
239 |
JOIN pg_catalog.pg_class c ON r.conrelid = c.oid |
|
240 |
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace |
|
35
e7f79c4a27ce
TableCopyTool: order tables with respect to references.
Radek Brich <radek.brich@devl.cz>
parents:
32
diff
changeset
|
241 |
LEFT JOIN pg_catalog.pg_class cf ON r.confrelid = cf.oid |
e7f79c4a27ce
TableCopyTool: order tables with respect to references.
Radek Brich <radek.brich@devl.cz>
parents:
32
diff
changeset
|
242 |
LEFT JOIN pg_catalog.pg_namespace nf ON nf.oid = cf.relnamespace |
0 | 243 |
WHERE n.nspname = %s AND c.relname = %s |
244 |
ORDER BY 1 |
|
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
245 |
''', [schema, table]) |
0 | 246 |
|
247 |
def list_indexes(self, table, schema='public'): |
|
248 |
return self._query(''' |
|
249 |
SELECT |
|
250 |
c2.relname as "name", |
|
251 |
i.indisprimary as "primary", |
|
252 |
i.indisunique as "unique", |
|
253 |
i.indisclustered as "clustered", |
|
254 |
i.indisvalid as "valid", |
|
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
255 |
pg_catalog.pg_get_indexdef(i.indexrelid, 0, true) as "definition", |
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
256 |
ARRAY(SELECT a.attname FROM pg_catalog.pg_attribute a WHERE a.attrelid = c2.oid ORDER BY attnum) AS "columns" |
0 | 257 |
--c2.reltablespace as "tablespace_oid" |
258 |
FROM pg_catalog.pg_class c |
|
259 |
JOIN pg_catalog.pg_index i ON c.oid = i.indrelid |
|
260 |
JOIN pg_catalog.pg_class c2 ON i.indexrelid = c2.oid |
|
261 |
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace |
|
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
262 |
WHERE n.nspname = %(schema)s AND c.relname = %(table)s |
0 | 263 |
ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname |
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
264 |
''', {'schema': schema, 'table': table}) |
0 | 265 |
|
40
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
266 |
def list_sequences(self, schema=None): |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
267 |
'''List sequences in schema.''' |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
268 |
return self._query(''' |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
269 |
SELECT |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
270 |
nc.nspname AS "sequence_schema", |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
271 |
c.relname AS "sequence_name", |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
272 |
t.relname AS "related_table", |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
273 |
a.attname AS "related_column", |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
274 |
format_type(a.atttypid, a.atttypmod) AS "related_column_type" |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
275 |
FROM pg_class c |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
276 |
JOIN pg_namespace nc ON nc.oid = c.relnamespace |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
277 |
JOIN pg_depend d ON d.objid = c.oid |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
278 |
JOIN pg_class t ON d.refobjid = t.oid |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
279 |
JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum) |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
280 |
WHERE c.relkind = 'S' AND NOT pg_is_other_temp_schema(nc.oid) |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
281 |
''' + (schema and ' AND nc.nspname = %(schema)s' or '') + ''' |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
282 |
''', {'schema': schema}) |
922d7fb63384
Add listserial tool. PgBrowser: Add list_sequences.
Radek Brich <radek.brich@devl.cz>
parents:
35
diff
changeset
|
283 |
|
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
284 |
def list_column_usage(self, table, column, schema='public'): |
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
285 |
'''List objects using the column. |
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
286 |
|
32
d59c473c9ad7
Add batchupdate tool. PgBrowser: add constraints to list_column_usage().
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
287 |
Currently shows views and constraints which use the column. |
d59c473c9ad7
Add batchupdate tool. PgBrowser: add constraints to list_column_usage().
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
288 |
|
d59c473c9ad7
Add batchupdate tool. PgBrowser: add constraints to list_column_usage().
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
289 |
This is useful to find which views block alteration of column type etc. |
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
290 |
|
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
291 |
''' |
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
292 |
return self._query(''' |
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
293 |
SELECT |
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
294 |
'view' AS type, view_schema AS schema, view_name AS name |
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
295 |
FROM information_schema.view_column_usage |
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
296 |
WHERE table_schema=%(schema)s AND table_name=%(table)s AND column_name=%(column)s |
32
d59c473c9ad7
Add batchupdate tool. PgBrowser: add constraints to list_column_usage().
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
297 |
|
d59c473c9ad7
Add batchupdate tool. PgBrowser: add constraints to list_column_usage().
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
298 |
UNION |
d59c473c9ad7
Add batchupdate tool. PgBrowser: add constraints to list_column_usage().
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
299 |
|
d59c473c9ad7
Add batchupdate tool. PgBrowser: add constraints to list_column_usage().
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
300 |
SELECT |
d59c473c9ad7
Add batchupdate tool. PgBrowser: add constraints to list_column_usage().
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
301 |
'constraint' AS type, constraint_schema AS schema, constraint_name AS name |
d59c473c9ad7
Add batchupdate tool. PgBrowser: add constraints to list_column_usage().
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
302 |
FROM information_schema.constraint_column_usage |
d59c473c9ad7
Add batchupdate tool. PgBrowser: add constraints to list_column_usage().
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
303 |
WHERE table_schema=%(schema)s AND table_name=%(table)s AND column_name=%(column)s |
31
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
304 |
''', {'schema':schema, 'table':table, 'column':column}) |
c2e6e24b83d9
Add browser - database schema browser using tuikit (curses UI). Add listdepends - tool which shows depending views for column. Update pgdatadiff - allow composite primary key. Update pgmanager - RowDict is now OrderedDict. Drop support for Python2.x.
Radek Brich <radek.brich@devl.cz>
parents:
12
diff
changeset
|
305 |