Merge ~pappacena/launchpad:gitrepo-status-column into launchpad:db-devel

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: e600171299c007cb9c6d5df41e43e2d3848467aa
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/launchpad:gitrepo-status-column
Merge into: launchpad:db-devel
Diff against target: 23 lines (+17/-0)
1 file modified
database/schema/patch-2210-17-0.sql (+17/-0)
Reviewer Review Type Date Requested Status
William Grant db Approve
Review via email: mp+385199@code.launchpad.net

Commit message

Database patch to create GitRepository.status column.

Description of the change

This MP is just adding the column, a quick operation that should be done on a fast downtime deployment. The NOT NULL and default value constraint, together with an index, is being created in a hot db patch here: https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/385198.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

Pushed the requested changes with comments.

Revision history for this message
William Grant (wgrant) :
review: Approve (db)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/database/schema/patch-2210-17-0.sql b/database/schema/patch-2210-17-0.sql
2new file mode 100644
3index 0000000..3f5946a
4--- /dev/null
5+++ b/database/schema/patch-2210-17-0.sql
6@@ -0,0 +1,17 @@
7+-- Copyright 2020 Canonical Ltd. This software is licensed under the
8+-- GNU Affero General Public License version 3 (see the file LICENSE).
9+
10+SET client_min_messages=ERROR;
11+
12+ALTER TABLE GitRepository ADD COLUMN status INTEGER;
13+
14+-- ALTER COLUMN ... SET DEFAULT doesn't trigger a table rewrite,
15+-- while ADD COLUMN ... DEFAULT xx does. In pg <11 this operation is slow.
16+-- That's why we first create, and then we set the default value.
17+-- Data backfilling will be done in a hot patch instead of a fast downtime.
18+ALTER TABLE GitRepository ALTER COLUMN status SET DEFAULT 2;
19+
20+COMMENT ON COLUMN GitRepository.status
21+ IS 'The current status of this git repository.';
22+
23+INSERT INTO LaunchpadDatabaseRevision VALUES (2210, 17, 0);