~launchpad-pqm/launchpad/devel

10637.3.7 by Guilherme Salgado
merge devel
1
#!/usr/bin/python -S
8687.15.9 by Karl Fogel
Add the copyright header block to more files (everything under database/).
2
#
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
3691.170.2 by Stuart Bishop
Add simple script to list empty tables
5
6
"""List empty database tables."""
7
8
__metaclass__ = type
9
10
import _pythonpath
11
from optparse import OptionParser
12
13
from canonical.database.sqlbase import connect
14
from canonical.launchpad.scripts import db_options
15
from fti import quote_identifier
16
17
def main(options):
18
    con = connect(options.dbuser)
19
    cur = con.cursor()
20
    cur.execute("""
21
        SELECT relname FROM pg_class,pg_namespace
22
        WHERE pg_class.relnamespace = pg_namespace.oid
23
            AND pg_namespace.nspname='public'
24
            AND pg_class.relkind = 'r'
25
        ORDER BY relname
26
        """)
27
    for table in (row[0] for row in cur.fetchall()):
28
        cur.execute(
29
                "SELECT TRUE FROM public.%s LIMIT 1" % quote_identifier(table)
30
                )
31
        if cur.fetchone() is None:
32
            print table
33
34
35
if __name__ == '__main__':
36
    parser = OptionParser()
37
    db_options(parser)
38
    (options, args) = parser.parse_args()
39
40
    main(options)