Skip to content

Commit a501c9a

Browse files
authored
Merge pull request #3040 from SeedCompany/0869-edgedb-more-seeding
[EdgeDB] Add seed data for `User`, `Language`, `TranslationProject`, and `LanguageEngagement`
2 parents 51e34c8 + 37faf92 commit a501c9a

File tree

7 files changed

+434
-2
lines changed

7 files changed

+434
-2
lines changed

dbschema/language.esdl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ module default {
2424
.<language[is Ethnologue::Language]
2525
));
2626
trigger connectEthnologue after insert for each do (
27-
insert Ethnologue::Language {
27+
(select Ethnologue::Language filter .language = __new__) ??
28+
(insert Ethnologue::Language {
2829
language := __new__,
2930
ownSensitivity := __new__.ownSensitivity,
3031
projectContext := __new__.projectContext
31-
}
32+
})
3233
);
3334
trigger matchEthnologueToOwnSens after update for each do (
3435
update __new__.ethnologue

dbschema/migrations/00040.edgeql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CREATE MIGRATION m1asch4l54f7eltalgtn3ft3kbtgzascsjujcjnonx6yloej5ujkpa
2+
ONTO m1zqlgbrht5kontkpocymsg2f7wit5rsxkmgy6uy56myfyhncrvlvq
3+
{
4+
ALTER TYPE default::Language {
5+
ALTER TRIGGER connectEthnologue USING (((SELECT
6+
Ethnologue::Language
7+
FILTER
8+
(.language = __new__)
9+
) ?? (INSERT
10+
Ethnologue::Language
11+
{
12+
language := __new__,
13+
ownSensitivity := __new__.ownSensitivity,
14+
projectContext := __new__.projectContext
15+
})));
16+
};
17+
};

dbschema/seeds/004.users.edgeql

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
with
2+
usersJson := to_json('[
3+
{
4+
"email": "[email protected]",
5+
"realFirstName": "Bilbo",
6+
"realLastName": "Baggins",
7+
"about": "A halfling from the Shire",
8+
"roles": ["ProjectManager"],
9+
"title": "Halfling Manager",
10+
"education": [
11+
{
12+
"degree": "Bachelors",
13+
"major": "Unlikely Heroics",
14+
"institution": "Shire University"
15+
}
16+
]
17+
},
18+
{
19+
"email": "[email protected]",
20+
"realFirstName": "Frodo",
21+
"realLastName": "Baggins",
22+
"about": "The nephew of a halfling from the Shire",
23+
"roles": ["FinancialAnalyst"],
24+
"title": "Jewlery Steward",
25+
"education": [
26+
{
27+
"degree": "Bachelors",
28+
"major": "Unlikely Heroics",
29+
"institution": "Shire University"
30+
},
31+
{
32+
"degree": "Masters",
33+
"major": "Determination Tactics",
34+
"institution": "Shire University"
35+
}
36+
]
37+
},
38+
{
39+
"email": "[email protected]",
40+
"realFirstName": "Gandalf",
41+
"realLastName": "The Gray",
42+
"about": "A wizard of Ainur",
43+
"roles": ["Controller"],
44+
"title": "Mithrandir of Middle Earth",
45+
"education": [
46+
{
47+
"degree": "Doctorate",
48+
"major": "Wizardry Proper",
49+
"institution": "Timeless Halls"
50+
}
51+
]
52+
},
53+
{
54+
"email": "[email protected]",
55+
"realFirstName": "Samwise",
56+
"realLastName": "Gamgee",
57+
"about": "A gardening halfing.",
58+
"roles": ["ConsultantManager"],
59+
"title": "Son of the Gaffer",
60+
"education": [
61+
{
62+
"degree": "Bachelors",
63+
"major": "Arboriculture",
64+
"institution": "Shire University"
65+
}
66+
]
67+
},
68+
{
69+
"email": "[email protected]",
70+
"realFirstName": "Meriadoc",
71+
"realLastName": "Brandybuck",
72+
"about": "A halfling friend",
73+
"roles": ["Controller"],
74+
"title": "Holdwine of the Shire",
75+
"education": [
76+
{
77+
"degree": "Bachelors",
78+
"major": "Unexpected Bravery",
79+
"institution": "Shire University"
80+
}
81+
]
82+
},
83+
{
84+
"email": "[email protected]",
85+
"realFirstName": "Peregrin",
86+
"realLastName": "Took",
87+
"about": "A halfing of mild mischief.",
88+
"roles": ["RegionalDirector"],
89+
"title": "Master of Curiousity",
90+
"education": [
91+
{
92+
"degree": "Bachelors",
93+
"major": "Culinary Arts",
94+
"institution": "Shire University"
95+
}
96+
]
97+
},
98+
{
99+
"email": "[email protected]",
100+
"realFirstName": "Aragorn",
101+
"realLastName": "Son of Arathorn",
102+
"about": "A human of the Dunedain.",
103+
"roles": ["Leadership"],
104+
"title": "King of Gondor and Arnor",
105+
"education": [
106+
{
107+
"degree": "Bachelors",
108+
"major": "Leadership",
109+
"institution": "Rivendell University"
110+
},
111+
{
112+
"degree": "Masters",
113+
"major": "Swordsmanship",
114+
"institution": "Rivendell University"
115+
}
116+
]
117+
}
118+
]'),
119+
users := (
120+
for user in json_array_unpack(usersJson)
121+
union (
122+
(select User filter .email = <str>user['email']) ??
123+
(insert User {
124+
email := <str>user['email'],
125+
realFirstName := <str>user['realFirstName'],
126+
realLastName := <str>user['realLastName'],
127+
phone := '555-555-5555',
128+
about := <str>user['about'],
129+
roles := <str>json_array_unpack(user['roles']),
130+
title := <str>user['title'],
131+
education := (
132+
for edu in json_array_unpack(user['education'])
133+
union (
134+
insert User::Education {
135+
degree := <str>edu['degree'],
136+
major := <str>edu['major'],
137+
institution := <str>edu['institution']
138+
}
139+
)
140+
)
141+
})
142+
)
143+
),
144+
new := (select users filter .createdAt = datetime_of_statement())
145+
select { `Added Users` := new.realFirstName ++ ' ' ++ new.realLastName }
146+
filter count(new) > 0;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
with
2+
languagesJson := to_json('[
3+
{
4+
"name": "English",
5+
"displayNamePronunciation": "[ENG-lish]",
6+
"sensitivity": "Low",
7+
"registryOfDialectsCode": "00120",
8+
"populationOverride": 100000,
9+
"ethnologue": {
10+
"code": "eng",
11+
"population": 500000
12+
}
13+
},
14+
{
15+
"name": "Quenya",
16+
"displayNamePronunciation": "[KWEN-ya]",
17+
"sensitivity": "Medium",
18+
"registryOfDialectsCode": "99931",
19+
"populationOverride": 500000,
20+
"leastOfThese": true,
21+
"ethnologue": {
22+
"code": "kwn",
23+
"population": 1000000
24+
}
25+
},
26+
{
27+
"name": "Sindarin",
28+
"displayNamePronunciation": "[sin-DAR-in]",
29+
"sensitivity": "Medium",
30+
"registryOfDialectsCode": "12345",
31+
"hasExternalFirstScripture": true,
32+
"ethnologue": {
33+
"code": "sdn",
34+
"provisionalCode": "sdi",
35+
"population": 700000
36+
}
37+
},
38+
{
39+
"name": "Khuzdul",
40+
"displayNamePronunciation": "[KUHZ-dul]",
41+
"sensitivity": "High",
42+
"registryOfDialectsCode": "22225",
43+
"leastOfThese": true,
44+
"hasExternalFirstScripture": true,
45+
"ethnologue": {
46+
"provisionalCode": "khu",
47+
"population": 9900000
48+
}
49+
},
50+
{
51+
"name": "Westron",
52+
"displayNamePronunciation": "[WEST-ron]",
53+
"sensitivity": "Low",
54+
"registryOfDialectsCode": "78910",
55+
"isSignLanguage": true,
56+
"signLanguageCode": "WT10",
57+
"ethnologue": {
58+
"code": "wst",
59+
"population": 1000
60+
}
61+
}
62+
]'),
63+
languages := (
64+
for language in json_array_unpack(languagesJson)
65+
union (
66+
(select Language filter .name = <str>language['name']) ??
67+
(with
68+
ethnologue := language['ethnologue'],
69+
projectContext := (insert Project::Context),
70+
languageEntity := (insert Language {
71+
name := <str>language['name'],
72+
displayNamePronunciation := <str>language['displayNamePronunciation'],
73+
ownSensitivity := <Sensitivity>json_get(language, 'sensitivity'),
74+
isDialect := <bool>json_get(language, 'isDialect') ?? false,
75+
registryOfDialectsCode := <str>json_get(language, 'registryOfDialectsCode'),
76+
leastOfThese := <bool>json_get(language, 'leastOfThese') ?? false,
77+
isSignLanguage := exists json_get(language, 'signLanguageCode'),
78+
signLanguageCode := <str>json_get(language, 'signLanguageCode'),
79+
hasExternalFirstScripture := <bool>json_get(language, 'hasExternalFirstScripture') ?? false,
80+
populationOverride := <population>json_get(language, 'populationOverride'),
81+
projectContext := projectContext,
82+
}),
83+
ethnologueEntity := (insert Ethnologue::Language {
84+
language := languageEntity,
85+
ownSensitivity := <Sensitivity>json_get(language, 'sensitivity'),
86+
code := <Ethnologue::code>json_get(ethnologue, 'code'),
87+
provisionalCode := <Ethnologue::code>json_get(ethnologue, 'provisionalCode'),
88+
population := <population>json_get(ethnologue, 'population'),
89+
projectContext := projectContext,
90+
})
91+
select languageEntity)
92+
)
93+
),
94+
new := (select languages filter .createdAt = datetime_of_statement())
95+
select { `Added Languages` := new.name }
96+
filter count(new) > 0;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
with
2+
projectsJson := to_json('[
3+
{
4+
"name": "Misty Mountains",
5+
"step": "EarlyConversations",
6+
"mouStart": "2020-01-01",
7+
"mouEnd": "2023-12-30",
8+
"estimatedSubmission": "2023-12-01",
9+
"financialReportPeriod": "Monthly"
10+
},
11+
{
12+
"name": "Arnor Lake",
13+
"step": "FinalizingProposal",
14+
"mouStart": "2015-01-01",
15+
"mouEnd": "2018-12-30",
16+
"estimatedSubmission": "2022-12-01",
17+
"financialReportPeriod": "Monthly"
18+
},
19+
{
20+
"name": "Lothlorien",
21+
"step": "Active",
22+
"mouStart": "2020-01-01",
23+
"mouEnd": "2025-05-30",
24+
"financialReportPeriod": "Quarterly"
25+
},
26+
{
27+
"name": "Emyn Muil",
28+
"step": "Active",
29+
"mouStart": "2019-03-01",
30+
"mouEnd": "2022-10-30",
31+
"financialReportPeriod": "Quarterly"
32+
},
33+
{
34+
"name": "South Downs",
35+
"step": "FinalizingCompletion",
36+
"mouStart": "2020-01-01",
37+
"mouEnd": "2023-12-30",
38+
"estimatedSubmission": "2023-09-01",
39+
"financialReportPeriod": "Monthly"
40+
}
41+
]'),
42+
projects := (
43+
for project in json_array_unpack(projectsJson)
44+
union (
45+
select (
46+
(select TranslationProject filter .name = <str>project['name']) ??
47+
(insert TranslationProject {
48+
name := <str>project['name'],
49+
step := <str>project['step'],
50+
mouStart := <cal::local_date>project['mouStart'],
51+
mouEnd := <cal::local_date>project['mouEnd'],
52+
estimatedSubmission := <cal::local_date>json_get(project, 'estimatedSubmission'),
53+
financialReportPeriod := <str>project['financialReportPeriod']
54+
})
55+
)
56+
)
57+
),
58+
new := (select projects filter .createdAt = datetime_of_statement())
59+
select { `Added Projects` := new.name }
60+
filter count(new) > 0;
61+
62+
# Update all projects to self reference for their context (has to be separate query)
63+
with updated := (
64+
for project in Project union (
65+
update project.projectContext
66+
set { projects := project }
67+
)
68+
)
69+
select <str>{};

0 commit comments

Comments
 (0)