Merge lp:~mars/launchpad/check-db-revision-target into lp:launchpad

Proposed by Māris Fogels
Status: Merged
Approved by: Aaron Bentley
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~mars/launchpad/check-db-revision-target
Merge into: lp:launchpad
Diff against target: 76 lines (+30/-5)
2 files modified
Makefile (+8/-5)
utilities/check-db-revision.py (+22/-0)
To merge this branch: bzr merge lp:~mars/launchpad/check-db-revision-target
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+23255@code.launchpad.net

Commit message

This branch adds a check to 'make run' that will abort server startup at the soonest possible point if the currently installed database schema does not match what your branch requires.

Description of the change

Hi,

This branch adds a new script and Makefile target for checking the current branch's required database schema. The Makefile target is a dependency of the 'make run' and 'make start' families. If the currently installed schema version does not match, then the script will exit with an error.

The idea is to save a few minutes of everyone's life by having the 'make run' process exit as soon as possible, rather than waiting for the app server to start and *then* watching it fail because a schema mismatch was not detected sooner.

This change was discussed with the LOSAs. They do not see a problem with me changing the 'run' and 'start' targets in this way, as they do not use them.

I manually tested the change by running 'make schema' in db-stable. It works. 'make check_schema' fails on the schema mismatch, as does 'make run'.

Maris

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2010-04-08 19:19:13 +0000
3+++ Makefile 2010-04-12 19:57:34 +0000
4@@ -78,6 +78,9 @@
5 check_config: build
6 bin/test -m canonical.config.tests -vvt test_config
7
8+check_schema: build
9+ ${PY} utilities/check-db-revision.py
10+
11 # Clean before running the test suite, since the build might fail depending
12 # what source changes happened. (e.g. apidoc depends on interfaces)
13 check: clean build
14@@ -210,17 +213,17 @@
15 # Handle merge proposal creations.
16 $(PY) cronscripts/mpcreationjobs.py
17
18-run: inplace stop
19+run: check_schema inplace stop
20 $(RM) thread*.request
21 bin/run -r librarian,google-webservice,memcached -i $(LPCONFIG)
22
23-start-gdb: inplace stop support_files
24+start-gdb: check_schema inplace stop support_files
25 $(RM) thread*.request
26 nohup gdb -x run.gdb --args bin/run -i $(LPCONFIG) \
27 -r librarian,google-webservice
28 > ${LPCONFIG}-nohup.out 2>&1 &
29
30-run_all: inplace stop hosted_branches
31+run_all: check_schema inplace stop hosted_branches
32 $(RM) thread*.request
33 bin/run -r librarian,buildsequencer,sftp,mailman,codebrowse,google-webservice,memcached \
34 -i $(LPCONFIG)
35@@ -234,7 +237,7 @@
36 stop_codebrowse:
37 $(PY) sourcecode/launchpad-loggerhead/stop-loggerhead.py
38
39-run_codehosting: inplace stop hosted_branches
40+run_codehosting: check_schema inplace stop hosted_branches
41 $(RM) thread*.request
42 bin/run -r librarian,sftp,codebrowse -i $(LPCONFIG)
43
44@@ -440,4 +443,4 @@
45 schema default launchpad.pot check_merge_ui pull scan sync_branches\
46 reload-apache hosted_branches check_db_merge check_mailman check_config\
47 jsbuild jsbuild_lazr clean_js buildonce_eggs \
48- sprite_css sprite_image css_combine compile
49+ sprite_css sprite_image css_combine compile check_schema
50
51=== added file 'utilities/check-db-revision.py'
52--- utilities/check-db-revision.py 1970-01-01 00:00:00 +0000
53+++ utilities/check-db-revision.py 2010-04-12 19:57:34 +0000
54@@ -0,0 +1,22 @@
55+#!/usr/bin/python2.5 -S
56+# Copyright 2010 Canonical Ltd. All rights reserved.
57+
58+"""
59+Check that the database revision of the current branch matches the current
60+database schema number.
61+"""
62+
63+import _pythonpath
64+import sys
65+
66+from canonical.database.revision import (
67+ confirm_dbrevision_on_startup, InvalidDatabaseRevision)
68+
69+try:
70+ confirm_dbrevision_on_startup()
71+except InvalidDatabaseRevision, err:
72+ print "Oops, we are trying to use an invalid database revision!"
73+ print err
74+ sys.exit(1)
75+else:
76+ sys.exit(0)