| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
INSERT INTO lists (scope, scope_id, kind, title, required, owner_id) |
| 22 |
SELECT 'repo', r.id, 'issues', r.name || ': issues', FALSE, r.user_id |
| 23 |
FROM git_repos r |
| 24 |
ON CONFLICT DO NOTHING; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
CREATE OR REPLACE FUNCTION seed_repo_notification_lists() RETURNS TRIGGER AS $$ |
| 31 |
BEGIN |
| 32 |
INSERT INTO lists (scope, scope_id, kind, title, required, owner_id) |
| 33 |
VALUES ('repo', NEW.id, 'issues', NEW.name || ': issues', FALSE, NEW.user_id) |
| 34 |
ON CONFLICT DO NOTHING; |
| 35 |
RETURN NEW; |
| 36 |
END; |
| 37 |
$$ LANGUAGE plpgsql; |
| 38 |
|
| 39 |
DROP TRIGGER IF EXISTS trg_seed_repo_notification_lists ON git_repos; |
| 40 |
CREATE TRIGGER trg_seed_repo_notification_lists |
| 41 |
AFTER INSERT ON git_repos |
| 42 |
FOR EACH ROW EXECUTE FUNCTION seed_repo_notification_lists(); |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
CREATE OR REPLACE FUNCTION rename_repo_notification_lists() RETURNS TRIGGER AS $$ |
| 47 |
BEGIN |
| 48 |
IF NEW.name IS DISTINCT FROM OLD.name THEN |
| 49 |
UPDATE lists SET title = NEW.name || ': issues' |
| 50 |
WHERE scope = 'repo' AND scope_id = NEW.id AND kind = 'issues'; |
| 51 |
END IF; |
| 52 |
RETURN NEW; |
| 53 |
END; |
| 54 |
$$ LANGUAGE plpgsql; |
| 55 |
|
| 56 |
DROP TRIGGER IF EXISTS trg_rename_repo_notification_lists ON git_repos; |
| 57 |
CREATE TRIGGER trg_rename_repo_notification_lists |
| 58 |
AFTER UPDATE ON git_repos |
| 59 |
FOR EACH ROW EXECUTE FUNCTION rename_repo_notification_lists(); |
| 60 |
|