"Fossies" - the Fresh Open Source Software Archive

Member "PURELIB/trac/upgrades/db23.py" (27 Aug 2019, 2803 Bytes) of package /windows/misc/Trac-1.4.win32.exe:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "db23.py": 1.3.5_vs_1.3.6.

    1 # -*- coding: utf-8 -*-
    2 #
    3 # Copyright (C) 2009-2019 Edgewall Software
    4 # All rights reserved.
    5 #
    6 # This software is licensed as described in the file COPYING, which
    7 # you should have received as part of this distribution. The terms
    8 # are also available at https://trac.edgewall.org/wiki/TracLicense.
    9 #
   10 # This software consists of voluntary contributions made by many
   11 # individuals. For the exact contribution history, see the revision
   12 # history and logs, available at https://trac.edgewall.org/.
   13 
   14 from trac.db import Table, Column, Index, DatabaseManager
   15 
   16 def do_upgrade(env, ver, cursor):
   17     # Make changeset cache multi-repository aware
   18     cursor.execute("CREATE TEMPORARY TABLE rev_old "
   19                    "AS SELECT * FROM revision")
   20     cursor.execute("DROP TABLE revision")
   21     cursor.execute("CREATE TEMPORARY TABLE nc_old "
   22                    "AS SELECT * FROM node_change")
   23     cursor.execute("DROP TABLE node_change")
   24 
   25     tables = [Table('repository', key=('id', 'name'))[
   26                 Column('id'),
   27                 Column('name'),
   28                 Column('value')],
   29               Table('revision', key=('repos', 'rev'))[
   30                 Column('repos'),
   31                 Column('rev', key_size=20),
   32                 Column('time', type='int'),
   33                 Column('author'),
   34                 Column('message'),
   35                 Index(['repos', 'time'])],
   36               Table('node_change', key=('repos', 'rev', 'path', 'change_type'))[
   37                 Column('repos', key_size=56),
   38                 Column('rev', key_size=20),
   39                 Column('path', key_size=255),
   40                 Column('node_type', size=1),
   41                 Column('change_type', size=1, key_size=2),
   42                 Column('base_path'),
   43                 Column('base_rev'),
   44                 Index(['repos', 'rev'])]]
   45 
   46     db_connector, _ = DatabaseManager(env).get_connector()
   47     for table in tables:
   48         for stmt in db_connector.to_sql(table):
   49             cursor.execute(stmt)
   50 
   51     cursor.execute("INSERT INTO revision (repos,rev,time,author,message) "
   52                    "SELECT '',rev,time,author,message FROM rev_old")
   53     cursor.execute("DROP TABLE rev_old")
   54     cursor.execute("INSERT INTO node_change (repos,rev,path,node_type,"
   55                    "change_type,base_path,base_rev) "
   56                    "SELECT '',rev,path,node_type,change_type,base_path,"
   57                    "base_rev FROM nc_old")
   58     cursor.execute("DROP TABLE nc_old")
   59 
   60     cursor.execute("INSERT INTO repository (id,name,value) "
   61                    "SELECT '',name,value FROM system "
   62                    "WHERE name IN ('repository_dir', 'youngest_rev')")
   63     cursor.execute("DELETE FROM system "
   64                    "WHERE name IN ('repository_dir', 'youngest_rev')")