~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python -S
#
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""
Rebuild the full text indexes in a more friendly fashion, enabling this to
be done without downtime.
"""
__metaclass__ = type

# pylint: disable-msg=W0403
import _pythonpath

from fti import ALL_FTI
import psycopg

def main():
    con = psycopg.connect("dbname=launchpad_prod user=postgres")
    con.set_isolation_level(0) # autocommit
    cur = con.cursor()

    for table, ignored in ALL_FTI:
        print 'Doing %(table)s' % vars(),
        cur.execute("SELECT id FROM %(table)s" % vars())
        ids = [row[0] for row in cur.fetchall()]
        for id in ids:
            cur.execute(
                    "UPDATE %(table)s SET fti=NULL WHERE id=%(id)s" % vars()
                    )
            if id % 100 == 0:
                print '.',
        print

if __name__ == '__main__':
    main()