~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to database/schema/upgrade.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2012-01-06 12:11:50 UTC
  • mfrom: (14625.2.7 gina-dsc-binaries)
  • Revision ID: launchpad@pqm.canonical.com-20120106121150-e0bucmb5qeyytnn9
[r=wgrant][bug=911943] Fix SourcePackageReleaseDscBinariesUpdater:
        round chunk_size to int (and document this issue).

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
__metaclass__ = type
11
11
 
12
 
# pylint: disable-msg=W0403
13
 
import _pythonpath  # Sort PYTHONPATH
 
12
import _pythonpath
14
13
 
15
14
from cStringIO import StringIO
16
15
import glob
 
16
from optparse import OptionParser
17
17
import os.path
18
 
from optparse import OptionParser
19
18
import re
20
19
from tempfile import NamedTemporaryFile
21
20
from textwrap import dedent
23
22
from bzrlib.branch import Branch
24
23
from bzrlib.errors import NotBranchError
25
24
 
26
 
from lp.services.scripts import db_options, logger_options, logger
27
 
from canonical.database.sqlbase import (
 
25
from lp.services.database.postgresql import fqn
 
26
from lp.services.database.sqlbase import (
28
27
    connect,
29
28
    ISOLATION_LEVEL_AUTOCOMMIT,
30
29
    sqlvalues,
31
30
    )
32
 
from canonical.database.postgresql import fqn
 
31
from lp.services.scripts import (
 
32
    db_options,
 
33
    logger,
 
34
    logger_options,
 
35
    )
33
36
import replication.helpers
34
37
 
35
38
 
107
110
        LaunchpadDatabaseRevision.start_time
108
111
            = transaction_timestamp() AT TIME ZONE 'UTC';
109
112
    """)
110
 
START_UPDATE_LOG_SQL = dedent("""\
111
 
    INSERT INTO LaunchpadDatabaseUpdateLog (
112
 
        start_time, end_time, branch_nick, revno, revid)
113
 
    VALUES (transaction_timestamp() AT TIME ZONE 'UTC', NULL, %s, %s, %s);
114
 
    """)
115
 
FINISH_UPDATE_LOG_SQL = dedent("""\
116
 
    UPDATE LaunchpadDatabaseUpdateLog
117
 
    SET end_time = statement_timestamp() AT TIME ZONE 'UTC'
118
 
    WHERE start_time = transaction_timestamp() AT TIME ZONE 'UTC';
119
 
    """)
120
113
 
121
114
 
122
115
def to_seconds(td):
169
162
 
170
163
def apply_patches_normal(con):
171
164
    """Update a non replicated database."""
172
 
    # On dev environments, until we create a fresh database baseline the
173
 
    # LaunchpadDatabaseUpdateLog tables does not exist at this point (it
174
 
    # will be created later via database patch). Don't try to update
175
 
    # LaunchpadDatabaseUpdateLog if it does not exist.
176
 
    cur = con.cursor()
177
 
    cur.execute("""
178
 
        SELECT EXISTS (
179
 
            SELECT TRUE FROM information_schema.tables
180
 
            WHERE
181
 
                table_schema='public'
182
 
                AND table_name='launchpaddatabaseupdatelog')
183
 
            """)
184
 
    updatelog_exists = cur.fetchone()[0]
185
 
 
186
 
    # Add a record to LaunchpadDatabaseUpdateLog that we are starting
187
 
    # an update.
188
 
    if updatelog_exists:
189
 
        cur.execute(START_UPDATE_LOG_SQL % sqlvalues(*get_bzr_details()))
190
 
 
191
165
    # trusted.sql contains all our stored procedures, which may
192
166
    # be required for patches to apply correctly so must be run first.
193
167
    apply_other(con, 'trusted.sql')
194
168
 
195
169
    # Prepare to repair patch timestamps if necessary.
 
170
    cur = con.cursor()
196
171
    cur.execute(FIX_PATCH_TIMES_PRE_SQL)
197
172
 
198
173
    # Apply the patches
207
182
    # Update comments.
208
183
    apply_comments(con)
209
184
 
210
 
    # Update the LaunchpadDatabaseUpdateLog record, stating the
211
 
    # completion time.
212
 
    if updatelog_exists:
213
 
        cur.execute(FINISH_UPDATE_LOG_SQL)
214
 
 
215
185
 
216
186
def apply_patches_replicated():
217
187
    """Update a Slony-I cluster."""
245
215
            # Flush or we might lose statements from buffering.
246
216
            combined_sql.flush()
247
217
 
248
 
    # Add a LaunchpadDatabaseUpdateLog record that we are starting patch
249
 
    # application.
250
 
    add_sql(START_UPDATE_LOG_SQL % sqlvalues(*get_bzr_details()))
251
 
 
252
218
    # Apply trusted.sql
253
219
    add_sql(open(os.path.join(SCHEMA_DIR, 'trusted.sql'), 'r').read())
254
220