Merge ~cjwatson/lp-signing:charm-migrate-db into lp-signing:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 2d087620c84010f1659b68862223af79527ae615
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/lp-signing:charm-migrate-db
Merge into: lp-signing:master
Prerequisite: ~cjwatson/lp-signing:encrypted-private-keys
Diff against target: 36 lines (+19/-1)
1 file modified
charm/lp-signing/reactive/lp-signing.py (+19/-1)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+382431@code.launchpad.net

Commit message

Run migrations in charm

Description of the change

In the long term we might want to do separate manual migrations instead; but the database structure is pretty simple, so this is good enough for now.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charm/lp-signing/reactive/lp-signing.py b/charm/lp-signing/reactive/lp-signing.py
2index 8dbed78..3e46c23 100644
3--- a/charm/lp-signing/reactive/lp-signing.py
4+++ b/charm/lp-signing/reactive/lp-signing.py
5@@ -47,7 +47,24 @@ def configure_rsync():
6 raise RuntimeError('Failed to restart rsync')
7
8
9-@when('ols.configured', 'db.master.available')
10+@when('ols.configured', 'db-admin.master.available')
11+@when_not('service.migrated')
12+def migrate(pgsql):
13+ if pgsql.master is None:
14+ return
15+
16+ hookenv.log('Running migrations.')
17+ success, output = postgres.run_migration(pgsql, action=False)
18+ if success:
19+ hookenv.log('Migrations run successfully.')
20+ set_state('service.migrated')
21+ else:
22+ hookenv.log('Failed to run migrations:')
23+ for line in output.splitlines():
24+ hookenv.log(line)
25+
26+
27+@when('ols.configured', 'db.master.available', 'service.migrated')
28 @when_not('service.configured')
29 def configure(pgsql):
30 if pgsql.master is None:
31@@ -84,4 +101,5 @@ def check_is_running():
32 def build_label_changed():
33 remove_state('ols.service.installed')
34 remove_state('ols.configured')
35+ remove_state('service.migrated')
36 remove_state('service.configured')

Subscribers

People subscribed via source and target branches