~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).
5
2976.2.1 by Stuart Bishop
Add small script to rebuild data in indexes on an online database
6
"""
7
Rebuild the full text indexes in a more friendly fashion, enabling this to
8
be done without downtime.
9
"""
3367.1.5 by Stuart Bishop
Make scripts executable and add #! lines and copywrites
10
__metaclass__ = type
2976.2.1 by Stuart Bishop
Add small script to rebuild data in indexes on an online database
11
8677.1.3 by Stuart Bishop
All scripts need to import _pythonpath to function correctly with buildout
12
# pylint: disable-msg=W0403
13
import _pythonpath
14
15
from fti import ALL_FTI
2976.2.1 by Stuart Bishop
Add small script to rebuild data in indexes on an online database
16
import psycopg
17
18
def main():
19
    con = psycopg.connect("dbname=launchpad_prod user=postgres")
20
    con.set_isolation_level(0) # autocommit
21
    cur = con.cursor()
22
23
    for table, ignored in ALL_FTI:
24
        print 'Doing %(table)s' % vars(),
25
        cur.execute("SELECT id FROM %(table)s" % vars())
26
        ids = [row[0] for row in cur.fetchall()]
27
        for id in ids:
28
            cur.execute(
29
                    "UPDATE %(table)s SET fti=NULL WHERE id=%(id)s" % vars()
30
                    )
31
            if id % 100 == 0:
32
                print '.',
33
        print
34
35
if __name__ == '__main__':
36
    main()