-
-
Save kommen/a902e4c5bfef1395e69a617d1cb427ac to your computer and use it in GitHub Desktop.
Datomic schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A profile handle needs to be unique, but the profile can be "owned" by either a person or a group. | |
schema1 makes it hard (impossible?) to validate with clojure.spec. | |
schema2 it would be possible to validate with a or in clojure.spec, but would have the drawback of not knowing by just looking at the profile` if it is owned by a group or a person. | |
Questions: | |
1) Which one is more idiomatic? | |
2) Is "this would be easier to validated with clojure.spec" a valid argument for datomic schema design | |
3) What to we gain though the profile entity indirection? :profile/handle could be an attribute on the person or group entity directly | |
4) When using the second approach, should we add an :profile/owner-type attribute which defines what :profile/owner references? | |
5) Should we consider isComponent for this? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
(def profile | |
[{:db/ident :profile/handle | |
:db/unique :db.unique/value | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one} | |
{:db/ident :profile/website | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one}]) | |
(def person | |
[{:db/ident :person/email | |
:db/unique :db.unique/value | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one} | |
{:db/ident :person/password-digest | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one | |
:db/doc "bcrypt encoded"} | |
{:db/ident :person/profile | |
:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/one}]) | |
(def group | |
[{:db/ident :group/name | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one} | |
{:db/ident :group/profile | |
:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/one} | |
{:db/ident :group/member | |
:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many}]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def profile | |
[{:db/ident :profile/handle | |
:db/unique :db.unique/value | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one} | |
{:db/ident :profile/website | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one} | |
{:db/ident :profile/owner | |
:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/one}]) | |
(def person | |
[{:db/ident :person/email | |
:db/unique :db.unique/value | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one} | |
{:db/ident :person/password-digest | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one | |
:db/doc "bcrypt encoded"}]) | |
(def group | |
[{:db/ident :group/name | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one} | |
{:db/ident :group/member | |
:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment