~launchpad-pqm/launchpad/devel

7675.1244.1 by Jeroen Vermeulen
Lint.
1
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
8687.15.9 by Karl Fogel
Add the copyright header block to more files (everything under database/).
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
#
8687.15.29 by Karl Fogel
Fix some problems:
4
# Quick hack makefile to (re)create the Launchpad database.
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
5
# One day the guts of this will be migrated to Python
1155 by Canonical.com Patch Queue Manager
More robust authentication
6
#
7
8357.5.5 by Gary Poster
fix make schema and a test that now reliably uses the new simplejson
8
PYTHON=../../bin/py
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
9
1102.1.10 by David Allouche
allow overriding of sampledata.sql and newsampledata.sql
10
# The database dump to restore on database creation
11
SAMPLEDATA=../sampledata/current.sql
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
12
SAMPLEDATA_DEV=../sampledata/current-dev.sql
1102.1.10 by David Allouche
allow overriding of sampledata.sql and newsampledata.sql
13
14
# The database dump to create
15
NEWSAMPLEDATA=../sampledata/newsampledata.sql
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
16
NEWSAMPLEDATA_DEV=../sampledata/newsampledata-dev.sql
1102.1.10 by David Allouche
allow overriding of sampledata.sql and newsampledata.sql
17
6887.3.1 by Curtis Hovey
Added a contraint to only check sampledata when there is a change to a patch or
18
# The database dump to create for lint reports
19
LINTDATA=../sampledata/lintdata.sql
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
20
LINTDATA_DEV=../sampledata/lintdata-dev.sql
6887.3.1 by Curtis Hovey
Added a contraint to only check sampledata when there is a change to a patch or
21
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
22
# The development database
7245.1.13 by Guilherme Salgado
A couple changes suggested by Abel/Gavin
23
DBNAME_DEV=launchpad_dev
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
24
TEMPLATE_WITH_DEV_SAMPLEDATA=launchpad_dev_template
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
25
26
# A template for databases used by functional tests.
27
# It is not used directly, but used as a template in a createdb command
28
# to quickly build a populated database to run tests against.
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
29
TEMPLATE_WITH_TEST_SAMPLEDATA=launchpad_ftest_template
1394 by Canonical.com Patch Queue Manager
Create an empty launchpad database as part of db setup
30
EMPTY_DBNAME=launchpad_empty
7019.1.1 by Stuart Bishop
Seperate database for testrunner session storage
31
TEST_SESSION_DBNAME=session_ftest
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
32
7245.1.10 by Guilherme Salgado
A few cleanups here and there.
33
# The database which is a copy of launchpad_ftest_template and can be accessed
8137.13.4 by Stuart Bishop
Use pgmassacre.py --template instead of pgmassacre + pgcreate combination
34
# via http://launchpad.dev when you use LPCONFIG=test-playground.
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
35
TEST_PLAYGROUND_DBNAME=launchpad_ftest_playground
36
2839.4.8 by Stuart Bishop
Automatically build session database
37
# The session database name.
2839.4.9 by Stuart Bishop
Pull connection information for the session database from launchpad.conf
38
SESSION_DBNAME=session_dev
2839.4.8 by Stuart Bishop
Automatically build session database
39
8137.13.4 by Stuart Bishop
Use pgmassacre.py --template instead of pgmassacre + pgcreate combination
40
# The command we use to drop a database.
3432.1.1 by Stuart Bishop
Update pgmassacre to work as unix user other than 'postgres'
41
DROPDB=${PYTHON} ../../utilities/pgmassacre.py
8137.13.4 by Stuart Bishop
Use pgmassacre.py --template instead of pgmassacre + pgcreate combination
42
# The command we use to drop (if exists) and recreate a database.
43
CREATEDB=${PYTHON} ../../utilities/pgmassacre.py -t
3432.1.1 by Stuart Bishop
Update pgmassacre to work as unix user other than 'postgres'
44
7675.1121.43 by Stuart Bishop
Revert db-devel r11053
45
HEADER="-- Copyright 2010-2011 Canonical Ltd.  This software is licensed \
46
  under the\n-- GNU Affero General Public License version 3 (see the file \
9024.1.1 by Jonathan Lange
Include the HEADER file in newsampledata.
47
	LICENSE)."
48
7245.1.10 by Guilherme Salgado
A few cleanups here and there.
49
# The command used (in conjunction with $(call)) to dump the contents of the
50
# given database ($1) into an SQL file ($2).
6374.17.4 by Stuart Bishop
Support tables whose first column isn't an integer in sampledata
51
build_new_sampledata=$(PYTHON) fti.py --null -d ${1} -q && \
52
	echo $(HEADER) > $(2) && \
53
    echo -n "-- Created using " >> $(2) && \
54
    pg_dump --version >> $(2) && \
7675.395.56 by Stuart Bishop
8.4 dropped some short options
55
    pg_dump --schema=public --disable-triggers -a --column-inserts -O ${1} \
7675.1212.28 by Stuart Bishop
LaunchpadDatabase* should not end up in sampledata
56
    | grep -v "\( TOC \|INSERT INTO launchpaddatabase\|sessiondata\|sessionpkgdata\|SELECT pg_catalog\.setval\|^--\| fticache \|'fticache'\|ALTER TABLE secret\|INSERT INTO secret\)" \
6374.17.4 by Stuart Bishop
Support tables whose first column isn't an integer in sampledata
57
    | $(PYTHON) sort_sql.py >> $(2) && \
7245.1.10 by Guilherme Salgado
A few cleanups here and there.
58
    $(PYTHON) fti.py --force -d ${1} -q
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
59
9024.1.1 by Jonathan Lange
Include the HEADER file in newsampledata.
60
1303 by Canonical.com Patch Queue Manager
New database baseline and stop bugtask.txt victimizing other tests
61
# The latest schema dump from production. Database patches are relative
7675.299.1 by Stuart Bishop
New baseline from 2.7.2 release
62
# to this baseline. This dump should be updated occasionally from production
1303 by Canonical.com Patch Queue Manager
New database baseline and stop bugtask.txt victimizing other tests
63
# to ensure that the development database remains in sync with reality
3691.17.3 by Stuart Bishop
New database baseline
64
# on production. It is generated using newbaseline.py in
8201.1.1 by Stuart Bishop
Tidy and reinstate vacuum steps
65
# bzr+ssh://devpad.canonical.com/code/stub/dbascripts
7675.1244.1 by Jeroen Vermeulen
Lint.
66
#
7675.1121.53 by Stuart Bishop
New baseline
67
REV=2209
1303 by Canonical.com Patch Queue Manager
New database baseline and stop bugtask.txt victimizing other tests
68
BASELINE=launchpad-${REV}-00-0.sql
7675.1121.53 by Stuart Bishop
New baseline
69
MD5SUM=cc7a493c924196409a22392a16443d52  launchpad-2209-00-0.sql
7675.299.1 by Stuart Bishop
New baseline from 2.7.2 release
70
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
71
default: all
72
7245.1.10 by Guilherme Salgado
A few cleanups here and there.
73
# Create a launchpad_ftest_template DB and load the test sample data into it.
7675.1244.1 by Jeroen Vermeulen
Lint.
74
test: create
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
75
	@ echo "* Creating database \"$(TEMPLATE_WITH_TEST_SAMPLEDATA)\"."
76
	@ ${CREATEDB} ${EMPTY_DBNAME} ${TEMPLATE_WITH_TEST_SAMPLEDATA}
77
	@ echo "* Loading sample data"
78
	@ psql -v ON_ERROR_STOP=1 -d ${TEMPLATE_WITH_TEST_SAMPLEDATA} -f $(SAMPLEDATA) > /dev/null
7675.1121.57 by Stuart Bishop
Still need those fti.py invocations
79
	@ echo "* Rebuilding full text indexes"
80
	@ ${PYTHON} fti.py --force -q -d ${TEMPLATE_WITH_TEST_SAMPLEDATA}
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
81
	@ echo "* Resetting sequences"
82
	@ ${PYTHON} reset_sequences.py -d ${TEMPLATE_WITH_TEST_SAMPLEDATA}
8201.1.2 by Stuart Bishop
Disable autovacuum on our development template databases
83
	@ echo "* Disabling autovacuum"
84
	@ ${PYTHON} unautovacuumable.py -d ${TEMPLATE_WITH_TEST_SAMPLEDATA}
8201.1.1 by Stuart Bishop
Tidy and reinstate vacuum steps
85
	@ echo "* Vacuuming"
86
	@ vacuumdb -fz ${TEMPLATE_WITH_TEST_SAMPLEDATA}
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
87
7245.1.10 by Guilherme Salgado
A few cleanups here and there.
88
# Create a launchpad_dev_template DB and load the dev sample data into it.
89
# Also create a launchpad_ftest_playground DB as a copy of
90
# launchpad_ftest_template.
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
91
dev: test
92
	@ echo "* Creating ${TEMPLATE_WITH_DEV_SAMPLEDATA}"
93
	@ ${CREATEDB} ${EMPTY_DBNAME} ${TEMPLATE_WITH_DEV_SAMPLEDATA}
94
	@ echo "* Loading sample data"
95
	@ psql -v ON_ERROR_STOP=1 -d ${TEMPLATE_WITH_DEV_SAMPLEDATA} -f $(SAMPLEDATA_DEV) > /dev/null
7675.1121.57 by Stuart Bishop
Still need those fti.py invocations
96
	@ echo "* Rebuilding full text indexes"
97
	@ ${PYTHON} fti.py --force -q -d ${TEMPLATE_WITH_DEV_SAMPLEDATA}
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
98
	@ echo "* Resetting sequences"
99
	@ ${PYTHON} reset_sequences.py -d ${TEMPLATE_WITH_DEV_SAMPLEDATA}
8201.1.2 by Stuart Bishop
Disable autovacuum on our development template databases
100
	@ echo "* Disabling autovacuum"
101
	@ ${PYTHON} unautovacuumable.py -d ${TEMPLATE_WITH_DEV_SAMPLEDATA}
8201.1.1 by Stuart Bishop
Tidy and reinstate vacuum steps
102
	@ echo "* Vacuuming"
103
	@ vacuumdb -fz ${TEMPLATE_WITH_DEV_SAMPLEDATA}
7245.1.13 by Guilherme Salgado
A couple changes suggested by Abel/Gavin
104
	@ echo "* Creating ${DBNAME_DEV}"
105
	@ ${CREATEDB} ${TEMPLATE_WITH_DEV_SAMPLEDATA} ${DBNAME_DEV}
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
106
	@ echo "* Creating ${TEST_PLAYGROUND_DBNAME}"
107
	@ ${CREATEDB} ${TEMPLATE_WITH_TEST_SAMPLEDATA} ${TEST_PLAYGROUND_DBNAME}
108
7245.1.10 by Guilherme Salgado
A few cleanups here and there.
109
# This will create a DB named launchpad_empty and load the base
110
# database schema, full text indexes and grants into it.
111
# It will also create session DBs for the test and dev environments.
112
# No sample data is added at this point.
7675.1244.1 by Jeroen Vermeulen
Lint.
113
create:
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
114
	@ echo "* If this fails you need to run as the postgresql superuser"
115
	@ echo "* eg. sudo -u postgres make create"
116
	@ echo
117
	@ echo "* Creating database \"$(EMPTY_DBNAME)\"."
7675.357.1 by Stuart Bishop
Developer database setup working with PG 8.4
118
	@ ${CREATEDB} template0 ${EMPTY_DBNAME}
1303 by Canonical.com Patch Queue Manager
New database baseline and stop bugtask.txt victimizing other tests
119
	@ echo "* Loading base database schema"
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
120
	@ psql -d ${EMPTY_DBNAME} -f ${BASELINE} | grep : | cat
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
121
	@ echo "* Patching the database schema"
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
122
	@ ${PYTHON} upgrade.py -d ${EMPTY_DBNAME}
1394 by Canonical.com Patch Queue Manager
Create an empty launchpad database as part of db setup
123
	@ echo "* Security setup"
8201.1.1 by Stuart Bishop
Tidy and reinstate vacuum steps
124
	@ ${PYTHON} security.py -q -d ${EMPTY_DBNAME}
8201.1.2 by Stuart Bishop
Disable autovacuum on our development template databases
125
	@ echo "* Disabling autovacuum"
126
	@ ${PYTHON} unautovacuumable.py -d ${EMPTY_DBNAME}
8201.1.1 by Stuart Bishop
Tidy and reinstate vacuum steps
127
	@ echo "* Vacuuming"
128
	@ vacuumdb -fz ${EMPTY_DBNAME}
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
129
7245.1.10 by Guilherme Salgado
A few cleanups here and there.
130
	@ echo "* Creating session databases '${SESSION_DBNAME}' (if necessary)"
6555.7.6 by Stuart Bishop
Use word matching to detect existing databases
131
	@if [ "$$((`psql -l | grep -w ${SESSION_DBNAME} | wc -l`))" = '0' ]; \
7675.357.1 by Stuart Bishop
Developer database setup working with PG 8.4
132
	    then ${CREATEDB} template0 ${SESSION_DBNAME} ; \
3691.52.3 by Stuart Bishop
Fix Bug 46149, moving upserts to stored procedures
133
	    createlang plpgsql ${SESSION_DBNAME}; \
2839.4.13 by Stuart Bishop
Add basic tests
134
	    psql -q -d ${SESSION_DBNAME} -f launchpad_session.sql ; \
2839.4.8 by Stuart Bishop
Automatically build session database
135
	fi
7019.1.1 by Stuart Bishop
Seperate database for testrunner session storage
136
	@ echo "* Creating session database '${TEST_SESSION_DBNAME}'"
7675.357.1 by Stuart Bishop
Developer database setup working with PG 8.4
137
	@ ${CREATEDB} template0 ${TEST_SESSION_DBNAME}
8201.1.1 by Stuart Bishop
Tidy and reinstate vacuum steps
138
	@ createlang plpgsql ${TEST_SESSION_DBNAME}
139
	@ psql -q -d ${TEST_SESSION_DBNAME} -f launchpad_session.sql
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
140
1303 by Canonical.com Patch Queue Manager
New database baseline and stop bugtask.txt victimizing other tests
141
# Confirm that launchpad-XX-00-0.sql hasn't been messed with - this file
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
142
# is our baseline telling us what was installed into production
143
check: search_path
1303 by Canonical.com Patch Queue Manager
New database baseline and stop bugtask.txt victimizing other tests
144
	@if [ "`md5sum ${BASELINE}`" != "${MD5SUM}" ]; then echo "* ${BASELINE} is corrupt or has been modified"; exit 1; else echo "* Using ${BASELINE} as baseline"; fi
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
145
146
search_path:
3691.85.3 by Andrew Bennetts
Merge from rocketfuel.
147
	@psql -d template1 -q -A -t -c 'show search_path'
5728.1.2 by Tom Haddon
Allow the search path to have quotes around the $user variable, or not
148
	@if [ `psql -d template1 -q -A -t -c 'show search_path'` != '$$user,public,ts2' ] && [ `psql -d template1 -q -A -t -c 'show search_path'` != '"$$user",public,ts2' ]; then \
1716.1.2 by Christian Reis
Fix makefile message indicating an unprepared database to be a bit more verbose
149
		echo "* It appears your search path is unconfigured."; \
2903.1.143 by Matthew Paul Thomas
Fixes remaining occurrences from outside lib/canonical/launchpad/.
150
		echo "	Have you read <https://launchpad.canonical.com/DatabaseSetup>?";  \
1716.1.2 by Christian Reis
Fix makefile message indicating an unprepared database to be a bit more verbose
151
		echo; \
5728.1.1 by Tom Haddon
Change error message for search_path in make schema to be more explicit
152
		echo "* Add the following to /etc/postgresql/X.X/main/postgresql.conf"; \
153
		echo " (where X.X is the version of the PostgreSQL DB you're connecting to):"; \
1716.1.2 by Christian Reis
Fix makefile message indicating an unprepared database to be a bit more verbose
154
		echo "    search_path='\$$user,public,ts2'"; \
155
		echo "* Then reload PostgreSQL:";  \
156
		echo "    sudo /etc/init.d/postgresql reload";  \
157
		exit 1; \
158
	 fi
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
159
160
161
all: dev test
162
	@ echo "* All done"
163
164
doc:
7245.1.13 by Guilherme Salgado
A couple changes suggested by Abel/Gavin
165
	postgresql_autodoc -d ${DBNAME_DEV} -f launchpad -t html
1415 by Canonical.com Patch Queue Manager
Pending DB patch for debonzi (mirrors)
166
	tidy -asxhtml launchpad.html > ,launchpad.html || mv ,launchpad.html launchpad.html
1407 by Canonical.com Patch Queue Manager
Rosetta teams added to sampledata
167
168
diagram:
1363 by Canonical.com Patch Queue Manager
Refactored VSourcePackageReleasePublishing for Keybuk
169
	${PYTHON} diagram.py
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
170
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
171
newsampledata_test:
172
	$(call build_new_sampledata,${TEST_PLAYGROUND_DBNAME},${NEWSAMPLEDATA})
173
174
newsampledata_dev:
7245.1.13 by Guilherme Salgado
A couple changes suggested by Abel/Gavin
175
	$(call build_new_sampledata,${DBNAME_DEV},${NEWSAMPLEDATA_DEV})
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
176
177
newsampledata: newsampledata_dev newsampledata_test
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
178
6887.3.1 by Curtis Hovey
Added a contraint to only check sampledata when there is a change to a patch or
179
lintdata:
7245.1.4 by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB.
180
	$(call build_new_sampledata,${TEMPLATE_WITH_TEST_SAMPLEDATA},${LINTDATA})
181
	$(call build_new_sampledata,${TEMPLATE_WITH_DEV_SAMPLEDATA},${LINTDATA_DEV})
6887.3.1 by Curtis Hovey
Added a contraint to only check sampledata when there is a change to a patch or
182
9024.1.2 by Jonathan Lange
Update PHONY to include all phony targets.
183
.PHONY: default test dev create check search_path all doc diagram newsampledata_test newsampledata_dev newsampledata lintdata
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
184