Merge ~ines-almeida/launchpad:project-tokens/db-patch into launchpad:master

Proposed by Ines Almeida
Status: Superseded
Proposed branch: ~ines-almeida/launchpad:project-tokens/db-patch
Merge into: launchpad:master
Diff against target: 31 lines (+25/-0)
1 file modified
database/schema/patch-2211-22-0.sql (+25/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Needs Resubmitting
William Grant db Pending
Review via email: mp+451470@code.launchpad.net

This proposal has been superseded by a proposal from 2023-09-21.

Commit message

DB patch: Add project to access token table

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

Normally speaking, the index changes would have to be done in a separate hot patch. However, given that there's a grand total of 409 `AccessToken` rows on staging today, I think we can get away with it in this case.

Adding William for a second DB review.

review: Approve (db)
Revision history for this message
Colin Watson (cjwatson) wrote :

Oh, I only just noticed - this is a cold patch, so you'll have to transplant it onto db-devel and re-propose this merge proposal with the target branch set to db-devel.

review: Needs Resubmitting
bd42b70... by Ines Almeida

Rework DB indexes from access token targets

Revision history for this message
Ines Almeida (ines-almeida) wrote :

I updated the indexes and resubmitted the MP

Unmerged commits

bd42b70... by Ines Almeida

Rework DB indexes from access token targets

Failed
[SUCCEEDED] docs:0 (build)
[FAILED] lint:0 (build)
[WAITING] mypy:0 (build)
13 of 3 results
f9e08c2... by Ines Almeida

DB patch: Add project to access token table

Succeeded
[SUCCEEDED] docs:0 (build)
[SUCCEEDED] lint:0 (build)
[SUCCEEDED] mypy:0 (build)
13 of 3 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/database/schema/patch-2211-22-0.sql b/database/schema/patch-2211-22-0.sql
2new file mode 100644
3index 0000000..27c6dea
4--- /dev/null
5+++ b/database/schema/patch-2211-22-0.sql
6@@ -0,0 +1,25 @@
7+-- Copyright 2023 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 AccessToken
13+ ADD COLUMN project integer REFERENCES product;
14+
15+COMMENT ON COLUMN AccessToken.project IS 'The project for which the token was issued.';
16+
17+CREATE INDEX accesstoken__project__idx
18+ ON AccessToken (project) WHERE project IS NOT NULL;
19+
20+DROP INDEX accesstoken__git_repository__idx;
21+CREATE INDEX accesstoken__git_repository__idx
22+ ON AccessToken (git_repository) WHERE git_repository IS NOT NULL;
23+
24+-- There can only be either a git_repository or a project as target
25+ALTER TABLE AccessToken
26+ ALTER COLUMN git_repository DROP NOT NULL,
27+ ADD CONSTRAINT one_target CHECK (
28+ (public.null_count(ARRAY[git_repository, project]) = 1)
29+ );
30+
31+INSERT INTO LaunchpadDatabaseRevision VALUES (2211, 22, 0);

Subscribers

People subscribed via source and target branches

to status/vote changes: