Giter Club home page Giter Club logo

dation's Introduction

Dation

Dation helps you write Datomic schemas using EDN.

Status

Unreleased.

Documentation

License

Distributed under the EPL v2.0

dation's People

Contributors

alidcast avatar

dation's Issues

schema versioning and migrations

I'm thinking about how to best handle schema migrations

datomic transactions are idempotent so as a default one could install their schema on startup every time

but just because datomic will only transact new values does not mean that updating the schema without some sort of versioning system is harmless. specially, some attribute changes require altering data (e.g. changing the type of an attribute).

so along with an installs property that list the attributes to install, it's likely necessary to require a schema name and version to serve as metadata for tracking schema changes.

{:name :my-schema
 :version "1.0"
 :installs [#attr {:user/username :db.type/string]}

To reinstall schema attributes, the use just has to up the configured version.

now, regarding migrations, I considered requiring the prior version, i.e. :version-before "1.0" so that we can know whether it is necessary to run a migration. but that might be unnecessary given that Datomic encourages schema growth, and thus rollbacks are unnecessary. perhaps giving each migration a name will be sufficient and we can keep track of the ones we have/haven't ran, and always run them in order:

{:name :my-schema
 :version "1.0"
 :installs [...]
 :migrations [{:name :change-foo :tx-fn 'myapp.migrations/change-foo} 
              {:name :change-bar :tx-fn 'myapp.migrations/change-bar}]}

Similar to attribute installs, the user has to change the database version so that we can know to recheck/rerun the necessary changes.

remove #db/ent reader literal

not flexible enough in regards to positional vector arguments, plus it encourages thinking of design of schema in wrong way

datomic attribute shorthands

currently we provide a vector shorthand that expands into datomic attribute map

namely, we have the #attr pattern: [ident type cardinality ?(unique | component) ?pred]
*if type is db.type/ref then third index is a db/isComponent boolean otherwise it is a db.unique value.

examples:
-#attr [:user/username :db.type/string :db.cardinality/one :db.unique/identity]
-#attr [:note/owner :db.type/ref :db.cardinality/one true]

This works great because the majority of attributes require an ident, type, and cardinality so it's easy to pick up on the pattern, and for other cases we provide other reader literal shorthands (i.e. #ent, and #spec.)

Note, I also considered providing shorthands for the :db value forms but every alternative considered loses semantic meaning. i.e. the keyword :one is less semantically meaningful than :cardinality/one and we can't just do :cardinality/one because that implies it is a non-namespaced attribute, which it's not.

Of the fourth alternatives below (fourth one being default datomic attribute map), the third variation offers succinctness without losing important meaning.
-#attr [:user/username :string]
-#attr [:user/username :type/string cardinality/one]
-#attr [:user/username :db.type/string :db.cardinality/one]
-{:db/ident :user/username :db/type :db.type/string :db/cardinality :db.cardinality/one}

One alternative that would have been great is if namespaced keywords were allowed in EDN files, i.e. ::type.one could be expanded into db.type/one but unfortunately that's not allowed so for now we'll stick with fully specifying datomic attribute values.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.