Skip to content

Commit c8eff71

Browse files
authored
Set grandparentName for subprojects when creating projects (#1166)
1 parent f5e8291 commit c8eff71

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

backend/src/database/migrations/U1690192894__fix-grandparent-name.sql

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
DO $$
2+
DECLARE
3+
_segment RECORD;
4+
_grandparent RECORD;
5+
_parent RECORD;
6+
BEGIN
7+
FOR _segment IN SELECT * FROM segments s WHERE s."grandparentSlug" IS NOT NULL AND s."grandparentName" IS NULL
8+
LOOP
9+
SELECT * INTO _grandparent
10+
FROM segments s
11+
WHERE s.slug = _segment."grandparentSlug"
12+
AND s."parentSlug" IS NULL
13+
AND s."grandparentSlug" IS NULL;
14+
15+
RAISE NOTICE 'Updating segment % with grandparent %', _segment.id, _grandparent.name;
16+
UPDATE segments SET "grandparentName" = _grandparent.name WHERE id = _segment.id;
17+
END LOOP;
18+
19+
FOR _segment IN SELECT * FROM segments s WHERE s."parentSlug" IS NOT NULL AND s."parentName" IS NULL
20+
LOOP
21+
SELECT * INTO _parent
22+
FROM segments s
23+
WHERE s.slug = _segment."parentSlug"
24+
AND s."parentSlug" = _segment."grandparentSlug"
25+
AND s."parentSlug" IS NOT NULL
26+
AND s."grandparentSlug" IS NULL;
27+
28+
RAISE NOTICE 'Updating segment % with parent %', _segment.id, _parent.name;
29+
UPDATE segments SET "parentName" = _parent.name WHERE id = _segment.id;
30+
END LOOP;
31+
END;
32+
$$ LANGUAGE plpgsql;
33+

backend/src/services/segmentService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export default class SegmentService extends LoggerBase {
117117
grandparentSlug: data.parentSlug,
118118
name: data.name,
119119
parentName: data.name,
120+
grandparentName: parent.name,
120121
})
121122

122123
await SequelizeRepository.commitTransaction(transaction)

0 commit comments

Comments
 (0)