Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended way to declare Datomic schema in Clojure application

I'm starting to develop a Datomic-backed Clojure app, and I'm wondering what's the best way to declare the schema, in order to address the following concerns:

  1. Having a concise, readable representation for the schema
  2. Ensuring the schema is installed and up-to-date prior to running a new version of my app.

Intuitively, my approach would be the following:

  1. Declaring some helper functions to make schema declarations less verbose than with the raw maps
  2. Automatically installing the schema as part of the initialization of the app (I'm not yet knowledgeable enough to know if that always works).

Is this the best way to go? How do people usually do it?

like image 887
Valentin Waeselynck Avatar asked Jul 14 '15 20:07

Valentin Waeselynck


3 Answers

  1. Raw maps are verbose, but have some great advantages over using some high level api:

    • Schema is defined in transaction form, what you specify is transactable (assuming the word exists)
    • Your schema is not tied to a particular library or spec version, it will always work.
    • Your schema is serializable (edn) without calling a spec API.
    • So you can store and deploy your schema more easily in a distributed environment since it's in data-form and not in code-form.

For those reasons I use raw maps.

  1. Automatically installing schema.

This I don't do either.

Usually when you make a change to your schema many things may be happening:

  • Add new attribute
  • Change existing attribute type
  • Create full-text for an attribute
  • Create new attribute from other values
  • Others

Which may need for you to change your existing data in some non obvious and not generic way, in a process which may take some time.

I do use some automatization for applying a list of schemas and schema changes, but always in a controlled "deployment" stage when more things regarding data updating may occur.

Assuming you have users.schema.edn and roles.schema.edn files:

(require '[datomic-manage.core :as manager])
(manager/create uri)
(manager/migrate uri [:users.schema
                      :roles.schema])
like image 164
guilespi Avatar answered Nov 16 '22 15:11

guilespi


I Use Conformity for this see Conformity repository. There is also a very useful blogpost from Yeller Here which will guide you how to use Conformity.

like image 4
Mitchel Kuijpers Avatar answered Nov 16 '22 16:11

Mitchel Kuijpers


For #1, datomic-schema might be of help. I haven't used it, but the example looks promising.

like image 2
nberger Avatar answered Nov 16 '22 16:11

nberger