From f8a3093d830a5787edbbcfd99db88719de44ee8d Mon Sep 17 00:00:00 2001 From: Carson Full Date: Thu, 9 Nov 2023 16:09:33 -0600 Subject: [PATCH] Move Language/Project name to Named mixin --- dbschema/language.esdl | 5 +---- dbschema/project.esdl | 4 ++-- dbschema/z.named.esdl | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 dbschema/z.named.esdl diff --git a/dbschema/language.esdl b/dbschema/language.esdl index c57e408c32..8adb1852e0 100644 --- a/dbschema/language.esdl +++ b/dbschema/language.esdl @@ -1,8 +1,5 @@ module default { - type Language extending Resource, Project::ContextAware, Mixin::Pinnable, Mixin::Taggable { - required name: str; - index on (str_sortable(.name)); - + type Language extending Resource, Project::ContextAware, Mixin::Named, Mixin::Pinnable, Mixin::Taggable { required displayName: str { default := .name; } diff --git a/dbschema/project.esdl b/dbschema/project.esdl index 3fa427ebd0..8a9d639a11 100644 --- a/dbschema/project.esdl +++ b/dbschema/project.esdl @@ -1,6 +1,6 @@ module default { - abstract type Project extending Resource, Project::ContextAware, Mixin::Pinnable, Mixin::Taggable { - required name: str { + abstract type Project extending Resource, Project::ContextAware, Mixin::Named, Mixin::Pinnable, Mixin::Taggable { + overloaded name { constraint exclusive; }; diff --git a/dbschema/z.named.esdl b/dbschema/z.named.esdl new file mode 100644 index 0000000000..6b11d46ff5 --- /dev/null +++ b/dbschema/z.named.esdl @@ -0,0 +1,24 @@ +module Mixin { + abstract type Named { + required name: str { + rewrite insert, update using (default::str_clean(.name)); + }; + + index on (default::str_sortable(.name)); + + index fts::index on ( + fts::with_options( + .name, + language := fts::Language.eng, + ) + ); + } +} + +module default { + function str_clean(string: str) -> optional str + using( + with trimmed := str_trim(string, " \t\r\n") + select if len(trimmed) > 0 then trimmed else {} + ); +}