Merge lp:~stub/launchpad/pending-db-changes into lp:launchpad/db-devel

Proposed by Stuart Bishop
Status: Merged
Approved by: Stuart Bishop
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~stub/launchpad/pending-db-changes
Merge into: lp:launchpad/db-devel
Diff against target: 118 lines (+20/-12)
6 files modified
database/replication/helpers.py (+1/-1)
database/replication/initialize.py (+3/-3)
database/replication/repair-restored-db.py (+1/-1)
database/schema/patch-2207-21-0.sql (+2/-1)
database/schema/patch-2207-27-0.sql (+1/-1)
lib/canonical/database/sqlbase.py (+12/-5)
To merge this branch: bzr merge lp:~stub/launchpad/pending-db-changes
Reviewer Review Type Date Requested Status
Paul Hummer (community) code Approve
Review via email: mp+17872@code.launchpad.net

Commit message

Repair staging and replication scripts.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

We recently refactored read-only mode, which broke our staging and replication scripts due to config changes and removal of a helper.

Revision history for this message
Paul Hummer (rockstar) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/replication/helpers.py'
2--- database/replication/helpers.py 2010-01-08 05:15:13 +0000
3+++ database/replication/helpers.py 2010-01-22 10:21:20 +0000
4@@ -287,7 +287,7 @@
5 assert len(node_ids) == 1, "Multiple nodes but no paths."
6 master_node_id = node_ids[0]
7 master_connection_string = ConnectionString(
8- config.database.main_master)
9+ config.database.rw_main_master)
10 master_connection_string.user = 'slony'
11 return [Node(
12 master_node_id, 'node%d_node' % master_node_id,
13
14=== modified file 'database/replication/initialize.py'
15--- database/replication/initialize.py 2010-01-06 13:53:16 +0000
16+++ database/replication/initialize.py 2010-01-22 10:21:20 +0000
17@@ -41,9 +41,9 @@
18 """Duplicate the master schema into the slaves."""
19 log.info('Duplicating database schema')
20
21- master_cs = ConnectionString(config.database.main_master)
22+ master_cs = ConnectionString(config.database.rw_main_master)
23 master_cs.user = options.dbuser
24- slave1_cs = ConnectionString(config.database.main_slave)
25+ slave1_cs = ConnectionString(config.database.rw_main_slave)
26 slave1_cs.user = options.dbuser
27
28 # We can't use pg_dump to replicate security as not all of the roles
29@@ -70,7 +70,7 @@
30 """Initialize the cluster."""
31 log.info('Initializing Slony-I cluster')
32 master_connection_string = ConnectionString(
33- config.database.main_master)
34+ config.database.rw_main_master)
35 master_connection_string.user = 'slony'
36 helpers.execute_slonik("""
37 node 1 admin conninfo = '%s';
38
39=== modified file 'database/replication/repair-restored-db.py'
40--- database/replication/repair-restored-db.py 2009-11-18 03:46:31 +0000
41+++ database/replication/repair-restored-db.py 2010-01-22 10:21:20 +0000
42@@ -86,7 +86,7 @@
43 log.debug('Broken or no Slony-I install.')
44 return False
45
46- connection_string = ConnectionString(config.database.main_master)
47+ connection_string = ConnectionString(config.database.rw_main_master)
48 if options.dbname:
49 connection_string.dbname = options.dbname
50 if options.dbuser:
51
52=== modified file 'database/schema/patch-2207-21-0.sql'
53--- database/schema/patch-2207-21-0.sql 2010-01-04 04:48:37 +0000
54+++ database/schema/patch-2207-21-0.sql 2010-01-22 10:21:20 +0000
55@@ -3,6 +3,7 @@
56 ALTER TABLE Language ALTER englishname SET NOT NULL;
57
58 ALTER TABLE LibraryFileContent ALTER filesize TYPE bigint;
59-CLUSTER LibraryFileContent USING libraryfilecontent_pkey; -- repack
60+-- Do later - too much downtime this cycle.
61+--CLUSTER LibraryFileContent USING libraryfilecontent_pkey; -- repack
62
63 INSERT INTO LaunchpadDatabaseRevision VALUES (2207, 21, 0);
64
65=== modified file 'database/schema/patch-2207-27-0.sql'
66--- database/schema/patch-2207-27-0.sql 2010-01-19 15:51:48 +0000
67+++ database/schema/patch-2207-27-0.sql 2010-01-22 10:21:20 +0000
68@@ -4,7 +4,7 @@
69 SET client_min_messages TO ERROR;
70
71 DROP INDEX bug__hotness__idx;
72-ALTER table bug ADD COLUMN heat_last_updated timestamp;
73+ALTER table bug ADD COLUMN heat_last_updated timestamp without time zone;
74 ALTER table bug RENAME COLUMN hotness to heat;
75 ALTER table bugtask RENAME COLUMN hotness_rank to heat_rank;
76 CREATE INDEX bug__heat_last_updated__idx ON bug USING btree (heat_last_updated);
77
78=== modified file 'lib/canonical/database/sqlbase.py'
79--- lib/canonical/database/sqlbase.py 2010-01-13 20:06:09 +0000
80+++ lib/canonical/database/sqlbase.py 2010-01-22 10:21:20 +0000
81@@ -7,7 +7,6 @@
82 from datetime import datetime
83 import re
84 from textwrap import dedent
85-
86 import psycopg2
87 from psycopg2.extensions import (
88 ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ_COMMITTED,
89@@ -758,6 +757,17 @@
90
91 Default database name is the one specified in the main configuration file.
92 """
93+ con = psycopg2.connect(connect_string(user, dbname))
94+ con.set_isolation_level(isolation)
95+ return con
96+
97+
98+def connect_string(user, dbname=None):
99+ """Return a PostgreSQL connection string.
100+
101+ Allows you to pass the generated connection details to external
102+ programs like pg_dump or embed in slonik scripts.
103+ """
104 from canonical import lp
105 # We start with the config string from the config file, and overwrite
106 # with the passed in dbname or modifications made by db_options()
107@@ -780,10 +790,7 @@
108 con_str_overrides.append('dbname=%s' % dbname)
109
110 con_str = ' '.join([con_str] + con_str_overrides)
111-
112- con = psycopg2.connect(con_str)
113- con.set_isolation_level(isolation)
114- return con
115+ return con_str
116
117
118 class cursor:

Subscribers

People subscribed via source and target branches

to status/vote changes: