1
-- Copyright 2011 Canonical Ltd. This software is licensed under the
2
-- GNU Affero General Public License version 3 (see the file LICENSE).
4
SET client_min_messages=ERROR;
6
-- denormalise message.owner for query efficiency.
7
ALTER TABLE QuestionMessage ADD COLUMN owner int;
9
CREATE INDEX questionmessage__owner__idx ON QuestionMessage(owner);
11
UPDATE QuestionMessage SET owner = (
12
SELECT owner FROM Message WHERE Message.id=QuestionMessage.message);
14
ALTER TABLE QuestionMessage ALTER COLUMN owner SET NOT NULL;
16
-- Triggers to maintain in both directions.
17
CREATE TRIGGER questionmessage__owner__mirror
18
AFTER UPDATE OR INSERT ON questionmessage
19
FOR EACH ROW EXECUTE PROCEDURE questionmessage_copy_owner_from_message();
20
CREATE TRIGGER message__owner__mirror__questionmessage AFTER UPDATE ON message
21
FOR EACH ROW EXECUTE PROCEDURE message_copy_owner_to_questionmessage();
23
INSERT INTO LaunchpadDatabaseRevision VALUES (2208, 69, 0);