Skip to content

Commit b71d9af

Browse files
committed
Merge branch 'develop'
2 parents a0de2b9 + 0cad09b commit b71d9af

19 files changed

+294
-18
lines changed

.github/actions/edgedb-setup/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ runs:
66
- name: Setup EdgeDB
77
uses: edgedb/setup-edgedb@v1
88

9+
- run: edgedb configure set session_idle_transaction_timeout 30s
10+
shell: bash
11+
912
- run: edgedb migrate --dev-mode
1013
shell: bash
1114

dbschema/funding-account.esdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module default {
33
overloaded name {
44
constraint exclusive;
55
}
6-
6+
77
required accountNumber: int16 {
88
constraint min_value(0);
99
constraint max_value(9);

dbschema/migrations/00033.edgeql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE MIGRATION m1ijgeabkfengfe2lpxjtq7xxqjiulhehay7tuutdoa5g3scsenwvq
2+
ONTO m1hb7zty3d4ekb5ftznc4tv4h5mgkxy6db42zbxylaw2rmrpveqsxq
3+
{
4+
ALTER TYPE Project::Child {
5+
ALTER TRIGGER enforceCorrectProjectContext USING (std::assert((__new__.projectContext = __new__.project.projectContext), message := "Given project context must match given project's context"));
6+
};
7+
};

dbschema/migrations/00034.edgeql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE MIGRATION m1abuwgh5eb3m3ivtyo6lru3w6k7ermhoof3bphd72jtx2cezj7ewa
2+
ONTO m1ijgeabkfengfe2lpxjtq7xxqjiulhehay7tuutdoa5g3scsenwvq
3+
{
4+
ALTER TYPE default::Project {
5+
CREATE LINK fieldRegion: default::FieldRegion;
6+
CREATE LINK marketingLocation: default::Location;
7+
CREATE LINK primaryLocation: default::Location;
8+
CREATE TRIGGER enforceFundingAccount
9+
AFTER UPDATE
10+
FOR EACH DO (std::assert((std::any((__new__.primaryLocation.fundingAccount.accountNumber > 0)) OR NOT (EXISTS (__new__.primaryLocation))), message := 'Project must have a primary location with a specified funding account'));
11+
ALTER PROPERTY departmentId {
12+
SET TYPE std::int32 USING (<std::int32>.departmentId);
13+
};
14+
};
15+
};

dbschema/migrations/00035.edgeql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE MIGRATION m13bndkbclxwviy3uj4eskx56bd2chw2xbvfn5pae557oslmbz2ssa
2+
ONTO m1abuwgh5eb3m3ivtyo6lru3w6k7ermhoof3bphd72jtx2cezj7ewa
3+
{
4+
ALTER TYPE default::Project {
5+
ALTER PROPERTY departmentId {
6+
CREATE CONSTRAINT std::exclusive;
7+
CREATE CONSTRAINT std::max_value(99999);
8+
CREATE CONSTRAINT std::min_value(10000);
9+
};
10+
};
11+
};

dbschema/migrations/00036.edgeql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
CREATE MIGRATION m1ydhle3dwjru34saeiidf5dyepbesugdwttrvnsyxhezpme5bfqga
2+
ONTO m13bndkbclxwviy3uj4eskx56bd2chw2xbvfn5pae557oslmbz2ssa
3+
{
4+
ALTER TYPE default::Project {
5+
ALTER PROPERTY departmentId {
6+
CREATE REWRITE
7+
UPDATE
8+
USING ((IF ((NOT (EXISTS (.departmentId)) AND (.status <= Project::Status.Active)) AND (.step >= Project::Step.PendingFinanceConfirmation)) THEN (WITH
9+
fa :=
10+
std::assert_exists(__subject__.primaryLocation.fundingAccount, message := 'Project must have a primary location')
11+
,
12+
existing :=
13+
(SELECT
14+
(DETACHED default::Project).departmentId
15+
FILTER
16+
(default::Project.primaryLocation.fundingAccount = fa)
17+
)
18+
,
19+
available :=
20+
(std::range_unpack(std::range(((fa.accountNumber * 10000) + 11), ((fa.accountNumber * 10000) + 9999))) EXCEPT existing)
21+
SELECT
22+
std::min(available)
23+
) ELSE .departmentId));
24+
};
25+
};
26+
};

dbschema/migrations/00037.edgeql

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
CREATE MIGRATION m1xzy4deu3w7kduilieoiydxysopymo7skj4sftggjen4vi3og6kaq
2+
ONTO m1ydhle3dwjru34saeiidf5dyepbesugdwttrvnsyxhezpme5bfqga
3+
{
4+
CREATE MODULE Scripture IF NOT EXISTS;
5+
CREATE TYPE Scripture::Collection {
6+
CREATE REQUIRED PROPERTY label: std::str {
7+
SET readonly := true;
8+
};
9+
};
10+
CREATE TYPE Scripture::VerseRange {
11+
CREATE REQUIRED PROPERTY label: std::str {
12+
SET readonly := true;
13+
};
14+
};
15+
ALTER TYPE Scripture::Collection {
16+
CREATE MULTI LINK verses: Scripture::VerseRange {
17+
ON SOURCE DELETE DELETE TARGET IF ORPHAN;
18+
SET readonly := true;
19+
};
20+
};
21+
CREATE TYPE Scripture::Verse {
22+
CREATE REQUIRED PROPERTY verseId: std::int16 {
23+
SET readonly := true;
24+
CREATE CONSTRAINT std::max_value(31101);
25+
CREATE CONSTRAINT std::min_value(0);
26+
};
27+
CREATE REQUIRED PROPERTY book: std::str {
28+
SET readonly := true;
29+
};
30+
CREATE REQUIRED PROPERTY chapter: std::int16 {
31+
SET readonly := true;
32+
CREATE CONSTRAINT std::max_value(150);
33+
CREATE CONSTRAINT std::min_value(1);
34+
};
35+
CREATE REQUIRED PROPERTY verse: std::int16 {
36+
SET readonly := true;
37+
CREATE CONSTRAINT std::max_value(176);
38+
CREATE CONSTRAINT std::min_value(1);
39+
};
40+
CREATE PROPERTY label := (((((.book ++ ' ') ++ <std::str>.chapter) ++ ':') ++ <std::str>.verse));
41+
};
42+
ALTER TYPE Scripture::VerseRange {
43+
CREATE REQUIRED LINK `end`: Scripture::Verse {
44+
ON SOURCE DELETE DELETE TARGET IF ORPHAN;
45+
SET readonly := true;
46+
};
47+
CREATE REQUIRED LINK `start`: Scripture::Verse {
48+
ON SOURCE DELETE DELETE TARGET IF ORPHAN;
49+
SET readonly := true;
50+
};
51+
CREATE PROPERTY ids := (std::range(<std::int32>.`start`.verseId, <std::int32>.`end`.verseId, inc_upper := true));
52+
};
53+
ALTER TYPE Scripture::Collection {
54+
CREATE PROPERTY ids := (std::multirange(std::array_agg(.verses.ids)));
55+
};
56+
ALTER TYPE default::Producible {
57+
CREATE LINK scripture: Scripture::Collection {
58+
ON SOURCE DELETE DELETE TARGET IF ORPHAN;
59+
};
60+
CREATE TRIGGER denyEmptyScriptureCollection
61+
AFTER UPDATE, INSERT
62+
FOR EACH DO (std::assert(EXISTS (__new__.scripture.verses), message := '`Producible.scripture` should have a `Scripture::Collection` with verses or be null/empty-set'));
63+
};
64+
ALTER TYPE default::Producible {
65+
DROP PROPERTY scriptureReferences;
66+
};
67+
};

dbschema/producible.esdl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ module default {
44
delegated constraint exclusive;
55
};
66

7-
scriptureReferences: multirange<int32>;
7+
scripture: Scripture::Collection {
8+
on source delete delete target if orphan;
9+
# https://github.com/edgedb/edgedb/issues/5827
10+
# rewrite insert, update using (
11+
# if exists .scripture.verses then .scripture else <Scripture::Collection>{}
12+
# );
13+
}
14+
# Enforce no empty collections for this type's use-case. Use null/empty-set instead.
15+
trigger denyEmptyScriptureCollection after insert, update for each do (
16+
assert(
17+
exists __new__.scripture.verses,
18+
message := "`Producible.scripture` should have a `Scripture::Collection` with verses or be null/empty-set"
19+
)
20+
);
821
}
922

1023
type EthnoArt extending Producible;

dbschema/project.esdl

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,32 @@ module default {
1010
default := Sensitivity.High;
1111
};
1212

13-
departmentId: str;
13+
departmentId: int32 {
14+
constraint exclusive;
15+
constraint min_value(10000);
16+
constraint max_value(99999);
17+
rewrite update using (
18+
if (
19+
not exists .departmentId and
20+
.status <= Project::Status.Active and
21+
.step >= Project::Step.PendingFinanceConfirmation
22+
) then ((
23+
with
24+
fa := assert_exists(
25+
__subject__.primaryLocation.fundingAccount,
26+
message := "Project must have a primary location"
27+
),
28+
existing := (
29+
select detached Project.departmentId filter Project.primaryLocation.fundingAccount = fa
30+
),
31+
available := (
32+
range_unpack(range(fa.accountNumber * 10000 + 11, fa.accountNumber * 10000 + 9999))
33+
except existing
34+
)
35+
select min(available)
36+
)) else .departmentId
37+
);
38+
};
1439

1540
required step: Project::Step {
1641
default := Project::Step.EarlyConversations;
@@ -44,9 +69,17 @@ module default {
4469
# multi link engagements := .<project[is Engagement];
4570
property engagementTotal := count(.<project[is Engagement]);
4671

47-
# link primaryLocation: Location;
48-
# link marketingLocation: Location;
49-
# link fieldRegion: FieldRegion;
72+
primaryLocation: Location;
73+
trigger enforceFundingAccount after update for each do (
74+
assert(
75+
any(__new__.primaryLocation.fundingAccount.accountNumber > 0)
76+
or not exists __new__.primaryLocation, # allow clearing
77+
message := "Project must have a primary location with a specified funding account"
78+
)
79+
);
80+
marketingLocation: Location;
81+
fieldRegion: FieldRegion;
82+
5083
link rootDirectory: Directory;
5184

5285
overloaded link projectContext: Project::Context {
@@ -102,8 +135,8 @@ module Project {
102135

103136
trigger enforceCorrectProjectContext after insert, update for each do (
104137
assert(
105-
__new__.project in __new__.projectContext.projects,
106-
message := "Given project must be in given project context"
138+
__new__.projectContext = __new__.project.projectContext,
139+
message := "Given project context must match given project's context"
107140
)
108141
);
109142
}

dbschema/scripture.esdl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
module Scripture {
2+
type Collection {
3+
required label: str {
4+
readonly := true;
5+
}
6+
# Want to allow optional for now for DerivativeScriptureProduct's scripture override use-case
7+
multi verses: VerseRange {
8+
readonly := true;
9+
on source delete delete target if orphan;
10+
}
11+
ids := multirange(array_agg(.verses.ids));
12+
}
13+
14+
type VerseRange {
15+
required label: str {
16+
readonly := true;
17+
}
18+
required `start`: Verse {
19+
readonly := true;
20+
on source delete delete target if orphan;
21+
}
22+
required `end`: Verse {
23+
readonly := true;
24+
on source delete delete target if orphan;
25+
}
26+
ids := range(
27+
<int32>.`start`.verseId,
28+
<int32>.`end`.verseId,
29+
inc_upper := true
30+
);
31+
}
32+
33+
type Verse {
34+
label := .book ++ " " ++ <str>.chapter ++ ":" ++ <str>.verse;
35+
required book: str {
36+
readonly := true;
37+
}
38+
required chapter: int16 {
39+
readonly := true;
40+
constraint min_value(1);
41+
constraint max_value(150); # Psalms
42+
}
43+
required verse: int16 {
44+
readonly := true;
45+
constraint min_value(1);
46+
constraint max_value(176); # Psalms 119
47+
}
48+
required verseId: int16 {
49+
readonly := true;
50+
constraint min_value(0);
51+
constraint max_value(31101);
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)