Skip to content

Commit eb741e6

Browse files
[EdgeDB] Create Product schema (#3063)
Co-authored-by: Carson Full <[email protected]>
1 parent 00141e4 commit eb741e6

File tree

4 files changed

+227
-1
lines changed

4 files changed

+227
-1
lines changed

dbschema/migrations/00050.edgeql

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
CREATE MIGRATION m1vlgekf4eyzweb6xmldmxwzohoh7xbrre6fbc7e2d3t7q7ry3qobq
2+
ONTO m1kzwpoy3r3awvbzqxxzz3upkkemxjtf33ra53zkuxzexsc7r5x4zq
3+
{
4+
CREATE MODULE Product IF NOT EXISTS;
5+
CREATE TYPE Scripture::UnspecifiedPortion {
6+
CREATE REQUIRED PROPERTY book: std::str {
7+
SET readonly := true;
8+
};
9+
CREATE REQUIRED PROPERTY totalVerses: std::int16 {
10+
SET readonly := true;
11+
CREATE CONSTRAINT std::min_value(1);
12+
};
13+
};
14+
CREATE SCALAR TYPE Product::Medium EXTENDING enum<Print, Web, EBook, App, TrainedStoryTellers, Audio, Video, Other>;
15+
CREATE SCALAR TYPE Product::Methodology EXTENDING enum<Paratext, OtherWritten, Render, Audacity, AdobeAudition, OtherOralTranslation, StoryTogether, SeedCompanyMethod, OneStory, Craft2Tell, OtherOralStories, Film, SignLanguage, OtherVisual>;
16+
CREATE SCALAR TYPE Product::ProgressMeasurement EXTENDING enum<Number, Percent, Boolean>;
17+
CREATE SCALAR TYPE Product::Purpose EXTENDING enum<EvangelismChurchPlanting, ChurchLife, ChurchMaturity, SocialIssues, Discipleship>;
18+
CREATE SCALAR TYPE Product::Step EXTENDING enum<ExegesisAndFirstDraft, TeamCheck, CommunityTesting, BackTranslation, ConsultantCheck, InternalizationAndDrafting, PeerRevision, ConsistencyCheckAndFinalEdits, Craft, Test, `Check`, Record, Develop, Translate, Completed>;
19+
CREATE ABSTRACT TYPE default::Product EXTENDING Engagement::Child {
20+
CREATE LINK scripture: Scripture::Collection {
21+
ON SOURCE DELETE DELETE TARGET IF ORPHAN;
22+
};
23+
CREATE PROPERTY describeCompletion: std::str;
24+
CREATE MULTI PROPERTY mediums: Product::Medium;
25+
CREATE PROPERTY methodology: Product::Methodology;
26+
CREATE PROPERTY placeholderDescription: std::str;
27+
CREATE PROPERTY pnpIndex: std::int16;
28+
CREATE PROPERTY progressStepMeasurement: Product::ProgressMeasurement;
29+
CREATE PROPERTY progressTarget: std::int16;
30+
CREATE MULTI PROPERTY purposes: Product::Purpose;
31+
CREATE MULTI PROPERTY steps: Product::Step;
32+
CREATE TRIGGER denyEmptyScriptureCollection
33+
AFTER UPDATE, INSERT
34+
FOR EACH DO (std::assert((NOT (EXISTS (__new__.scripture)) OR EXISTS (__new__.scripture.verses)), message := '`Product.scripture` should have a `Scripture::Collection` with verses or be null/empty-set'));
35+
};
36+
CREATE TYPE default::DirectScriptureProduct EXTENDING default::Product {
37+
CREATE LINK unspecifiedScripture: Scripture::UnspecifiedPortion {
38+
ON SOURCE DELETE DELETE TARGET IF ORPHAN;
39+
};
40+
CREATE PROPERTY totalVerseEquivalents: std::int32;
41+
CREATE PROPERTY totalVerses: std::int16;
42+
};
43+
CREATE TYPE default::DerivativeScriptureProduct EXTENDING default::Product {
44+
CREATE REQUIRED LINK produces: default::Producible;
45+
ALTER LINK scripture {
46+
SET OWNED;
47+
};
48+
CREATE LINK scriptureOverride: Scripture::Collection {
49+
ON SOURCE DELETE DELETE TARGET IF ORPHAN;
50+
};
51+
ALTER LINK scripture {
52+
CREATE REWRITE
53+
INSERT
54+
USING ((IF EXISTS (.scriptureOverride) THEN .scriptureOverride ELSE .produces.scripture));
55+
CREATE REWRITE
56+
UPDATE
57+
USING ((IF EXISTS (.scriptureOverride) THEN .scriptureOverride ELSE .produces.scripture));
58+
};
59+
CREATE REQUIRED PROPERTY composite: std::bool {
60+
SET default := false;
61+
};
62+
CREATE PROPERTY totalVerseEquivalents: std::int32;
63+
CREATE PROPERTY totalVerses: std::int16;
64+
};
65+
ALTER TYPE default::Producible {
66+
CREATE TRIGGER updateDerivativeProducts
67+
AFTER UPDATE
68+
FOR EACH DO (UPDATE
69+
__new__.<produces[IS default::DerivativeScriptureProduct]
70+
FILTER
71+
((__new__.scripture != __old__.scripture) AND NOT (EXISTS (.scriptureOverride)))
72+
SET {
73+
scripture := __new__.scripture
74+
});
75+
ALTER TRIGGER denyEmptyScriptureCollection USING (std::assert((NOT (EXISTS (__new__.scripture)) OR EXISTS (__new__.scripture.verses)), message := '`Producible.scripture` should have a `Scripture::Collection` with verses or be null/empty-set'));
76+
};
77+
CREATE TYPE default::OtherProduct EXTENDING default::Product {
78+
CREATE PROPERTY description: std::str;
79+
CREATE REQUIRED PROPERTY title: std::str;
80+
};
81+
};

dbschema/producible.esdl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ module default {
1414
# Enforce no empty collections for this type's use-case. Use null/empty-set instead.
1515
trigger denyEmptyScriptureCollection after insert, update for each do (
1616
assert(
17-
exists __new__.scripture.verses,
17+
not exists __new__.scripture or exists __new__.scripture.verses,
1818
message := "`Producible.scripture` should have a `Scripture::Collection` with verses or be null/empty-set"
1919
)
2020
);
21+
22+
trigger updateDerivativeProducts after update for each do (
23+
update __new__.<produces[is DerivativeScriptureProduct]
24+
filter __new__.scripture != __old__.scripture and not exists .scriptureOverride
25+
set { scripture := __new__.scripture }
26+
);
2127
}
2228

2329
type EthnoArt extending Producible;

dbschema/product.esdl

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
module default {
2+
abstract type Product extending Engagement::Child {
3+
# https://github.com/edgedb/edgedb/issues/6766
4+
# overloaded engagement: LanguageEngagement;
5+
6+
scripture: Scripture::Collection {
7+
on source delete delete target if orphan;
8+
};
9+
10+
multi mediums: Product::Medium;
11+
multi purposes: Product::Purpose;
12+
multi steps: Product::Step;
13+
methodology: Product::Methodology;
14+
15+
describeCompletion: str;
16+
placeholderDescription: str;
17+
pnpIndex: int16;
18+
progressTarget: int16;
19+
progressStepMeasurement: Product::ProgressMeasurement;
20+
21+
#TODO - category := ??? - add this computed field here after migration
22+
23+
# Enforce no empty collections for this type's use-case. Use null/empty-set instead.
24+
trigger denyEmptyScriptureCollection after insert, update for each do (
25+
assert(
26+
not exists __new__.scripture or exists __new__.scripture.verses,
27+
message := "`Product.scripture` should have a `Scripture::Collection` with verses or be null/empty-set"
28+
)
29+
);
30+
}
31+
32+
type DirectScriptureProduct extending Product {
33+
unspecifiedScripture: Scripture::UnspecifiedPortion {
34+
on source delete delete target if orphan;
35+
};
36+
37+
totalVerses: int16;
38+
totalVerseEquivalents: int32;
39+
}
40+
41+
type DerivativeScriptureProduct extending Product {
42+
required produces: default::Producible;
43+
44+
overloaded scripture {
45+
rewrite insert, update using (
46+
# coalescing `??` bugged with links
47+
# https://github.com/edgedb/edgedb/issues/6767
48+
if exists .scriptureOverride then .scriptureOverride else .produces.scripture
49+
);
50+
};
51+
52+
scriptureOverride: Scripture::Collection {
53+
on source delete delete target if orphan;
54+
};
55+
56+
required composite: bool { default := false };
57+
58+
totalVerses: int16;
59+
totalVerseEquivalents: int32;
60+
}
61+
62+
type OtherProduct extending Product {
63+
required title: str;
64+
description: str;
65+
}
66+
}
67+
68+
module Product {
69+
scalar type Medium extending enum<
70+
Print,
71+
Web,
72+
EBook,
73+
App,
74+
TrainedStoryTellers,
75+
Audio,
76+
Video,
77+
Other
78+
>;
79+
80+
scalar type Methodology extending enum<
81+
Paratext,
82+
OtherWritten,
83+
Render,
84+
Audacity,
85+
AdobeAudition,
86+
OtherOralTranslation,
87+
StoryTogether,
88+
SeedCompanyMethod,
89+
OneStory,
90+
Craft2Tell,
91+
OtherOralStories,
92+
Film,
93+
SignLanguage,
94+
OtherVisual,
95+
>;
96+
97+
scalar type ProgressMeasurement extending enum<
98+
Number,
99+
Percent,
100+
Boolean
101+
>;
102+
103+
scalar type Purpose extending enum<
104+
EvangelismChurchPlanting,
105+
ChurchLife,
106+
ChurchMaturity,
107+
SocialIssues,
108+
Discipleship
109+
>;
110+
111+
scalar type Step extending enum<
112+
ExegesisAndFirstDraft,
113+
TeamCheck,
114+
CommunityTesting,
115+
BackTranslation,
116+
ConsultantCheck,
117+
InternalizationAndDrafting,
118+
PeerRevision,
119+
ConsistencyCheckAndFinalEdits,
120+
Craft,
121+
Test,
122+
`Check`,
123+
Record,
124+
Develop,
125+
Translate,
126+
Completed,
127+
>;
128+
}

dbschema/scripture.esdl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,15 @@ module Scripture {
4848
constraint expression on (__subject__ >= 0 and __subject__ <= 31101);
4949
}
5050
}
51+
52+
type UnspecifiedPortion {
53+
required book: str {
54+
readonly := true;
55+
}
56+
57+
required totalVerses: int16 {
58+
readonly := true;
59+
constraint min_value(1);
60+
}
61+
}
5162
}

0 commit comments

Comments
 (0)