Code Monkey home page Code Monkey logo

generations's Introduction

generations

Clojars Project

A Clojure library designed to support simple database schema migrations for Datomic.

Usage

This library allows to simply keep syncronized schema attributes in all the databases on different machines, such as developers' local machines, staging, production, etc.

For this, we use the idea of "generation": it is a plain transaction request, a list of lists or list of maps with transaction data. And you have to keep all the generations in a vector. To evolve database schema, new generation should be added to the end of this vector.

In other words, you always keep schema related transactions ordered in this vector:

(def my-project-generations
  [

   ;; -*- Generation 1 -*-

   [
	   {:db/id #db/id[:db.part/db]
	    :db/ident :user/id
        :db/valueType :db.type/uuid
        ...
	    :db.install/_attribute :db.part/db}

	   {:db/id #db/id[:db.part/db]
	    :db/ident :user/email
        :db/valueType :db.type/string
        ...
	    :db.install/_attribute :db.part/db}

	   {:db/id #db/id[:db.part/db]
	    :db/ident :enums
	    :db.install/_parition :db.part/db}
   ]

   ;; -*- Generation 2 -*-

   [
	   {:db/id #db/id[:enums] :db/ident :locale/en}
	   {:db/id #db/id[:enums] :db/ident :locale/nl}
	   {:db/id #db/id[:enums] :db/ident :locale/it}

	   {:db/id #db/id[:db.part/db]
	    :db/ident :user/address
        :db/valueType :db.type/string
        ...
	    :db.install/_attribute :db.part/db}

	]

	...

   ])

ilshad.generations/install automatically installs only generations which are not installed yet:

(ilshad.generations/install my-project-generations db-conn)

For example, put this into your main function to ensure actual database schema always installed:

(ns my-project
  (:require [datomic.api :as d]
            [ilshad.generations :as generations]))

(defn -main [& args]
  (let [uri "datomic:dev://localhost:4334/my-database"]
    (when (d/create-database uri)
	  (log/info "New database has been created:" uri))
    (generations/install my-project-generations (d/connect uri))))

To achieve its goal, this library installs :generation/id and :generation/data attributes into the database and thus it stores an information about all the generations.

License

Copyright © 2013-2016 Ilshad Khabibullin.

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

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.