Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engagement Workflow v2 #3245

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions dbschema/engagement-workflow.esdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module Engagement {
type WorkflowEvent extending Project::ContextAware {
required engagement: default::Engagement {
readonly := true;
on target delete delete source;
};
required who: default::Actor {
readonly := true;
default := global default::currentActor;
};
required at: datetime {
readonly := true;
default := datetime_of_statement();
};
transitionKey: uuid {
readonly := true;
};
required to: Status {
readonly := true;
};
notes: default::RichText {
readonly := true;
};

trigger setEngagementStatus after insert for all do (
update default::Engagement
filter default::Engagement in __new__.engagement
set {
status := default::Engagement.latestWorkflowEvent.to ?? Engagement::Status.InDevelopment
}
);
trigger refreshEngagementStatus after delete for all do (
update default::Engagement
filter default::Engagement in __old__.engagement
set {
status := default::Engagement.latestWorkflowEvent.to ?? Engagement::Status.InDevelopment
}
);
}

scalar type Status extending enum<
atGit2021 marked this conversation as resolved.
Show resolved Hide resolved
InDevelopment,
DidNotDevelop,
Rejected,

Active,
ActiveChangedPlan,

DiscussingTermination,
DiscussingReactivation,
DiscussingChangeToPlan,
DiscussingSuspension,
Suspended,

FinalizingCompletion,
Terminated,
Completed,

# deprecated / legacy
Converted,
Unapproved,
Transferred,
NotRenewed,
>;
}
34 changes: 9 additions & 25 deletions dbschema/engagement.esdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ module default {
required status: Engagement::Status {
default := Engagement::Status.InDevelopment;
}
latestWorkflowEvent := (select .workflowEvents order by .at desc limit 1);
workflowEvents := .<engagement[is Engagement::WorkflowEvent];
trigger assertMatchingLatestWorkflowEvent after insert, update for each do (
assert(
__new__.latestWorkflowEvent.to ?= __new__.status
or (not exists __new__.latestWorkflowEvent and __new__.status = Engagement::Status.InDevelopment),
message := "Engagement status must match the latest workflow event"
)
);
statusModifiedAt: datetime {
rewrite update using (datetime_of_statement() if .status != __old__.status else .statusModifiedAt);
}
Expand Down Expand Up @@ -141,31 +150,6 @@ module default {
}

module Engagement {
scalar type Status extending enum<
InDevelopment,
DidNotDevelop,
Rejected,

Active,

DiscussingTermination,
DiscussingReactivation,
DiscussingChangeToPlan,
DiscussingSuspension,

FinalizingCompletion,
ActiveChangedPlan,
Suspended,

Terminated,
Completed,

# deprecated / legacy
Converted,
Unapproved,
Transferred,
NotRenewed,
>;

scalar type InternPosition extending enum<
ConsultantInTraining,
Expand Down
68 changes: 68 additions & 0 deletions dbschema/migrations/00012-m1vbhai.edgeql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 0 additions & 56 deletions dbschema/seeds/011.language-engagements.edgeql

This file was deleted.

117 changes: 117 additions & 0 deletions dbschema/seeds/011.language-engagements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import type { SeedFn } from '~/core/edgedb/seeds.run';
import { EngagementStatus } from '../../src/components/engagement/dto';

const engagementsInput: Input[] = [
{
project: 'Misty Mountains',
language: 'English',
status: 'InDevelopment',
startDateOverride: '2020-04-01',
endDateOverride: '2020-06-30',
},
{
project: 'Arnor Lake',
language: 'Quenya',
status: 'FinalizingCompletion',
startDateOverride: '2016-04-01',
endDateOverride: '2017-06-30',
},
{
project: 'Lothlorien',
language: 'Sindarin',
status: 'Active',
},
{
project: 'Emyn Muil',
language: 'Khuzdul',
status: 'Active',
},
{
project: 'South Downs',
language: 'Westron',
status: 'FinalizingCompletion',
paratextRegistryId: '1234567890',
},
];

interface Input {
project: string;
language: string;
status: string;
startDateOverride?: string;
endDateOverride?: string;
paratextRegistryId?: string;
}

export default (async function ({ e, db, print }) {
const existingLanguageEngagements = await e
.select(e.LanguageEngagement, () => ({
project: {
name: true,
},
language: {
name: true,
},
}))
.run(db);
const newEngagements = engagementsInput.filter(
(engagementSeed) =>
!existingLanguageEngagements.some(
(engagementData) =>
engagementData.project.name === engagementSeed.project &&
engagementData.language.name === engagementSeed.language,
),
);

if (newEngagements.length === 0) {
return;
}

for (const { language, project, status, ...engagement } of newEngagements) {
const languageQ = e.assert_exists(
e.select(e.Language, (item) => ({
filter_single: e.op(item.displayName, '=', language),
...e.Language['*'],
})),
);

const translationProjectQ = e.assert_exists(
e.select(e.TranslationProject, (item) => ({
filter_single: e.op(item.name, '=', project),
...e.TranslationProject['*'],
})),
);

const insertQ = e.insert(e.LanguageEngagement, {
project: translationProjectQ,
projectContext: translationProjectQ.projectContext,
startDateOverride: engagement.startDateOverride
? e.cal.local_date(engagement.startDateOverride)
: undefined,
endDateOverride: engagement.endDateOverride
? e.cal.local_date(engagement.endDateOverride)
: undefined,
language: languageQ,
paratextRegistryId: engagement.paratextRegistryId,
});
const query = e.select(insertQ, () => ({ id: true, projectContext: true }));
const inserted = await query.run(db);

const engagementRef = e.cast(e.Engagement, e.uuid(inserted.id));

if (status !== 'InDevelopment') {
await e
.insert(e.Engagement.WorkflowEvent, {
engagement: engagementRef,
projectContext: engagementRef.projectContext,
to: status as EngagementStatus,
})
.run(db);
}
}
print({
'Added LanguageEngagments': newEngagements.map(
(engagement) => engagement.project + ' - ' + engagement.language,
),
});
} satisfies SeedFn);
Loading
Loading