Migration backend rewrite

13 views
Skip to first unread message

Nicolas Buduroi

unread,
Jun 8, 2011, 6:28:51 PM6/8/11
to lobos-...@googlegroups.com
The migration backend has finally been rewritten, sorry that I could not pull this out earlier. It basically follow the main ideas found in this discussion with James Reeves. In summary, migrations are now found in a single file as real (namespaced) Clojure code, here's an example of this file:

$ cat src/lobos/migrations.clj

(ns
 lobos.migrations
 (:refer-clojure
  :exclude
  [alter defonce drop bigint boolean char double float time])
 (:use
  (lobos [migration :only [defmigration]] core schema)
  lobos.config))

(defmigration
 create-users
 (up [] (create h2-spec (table :users (integer :id :primary-key))))
 (down [] (drop h2-spec (table :users (integer :id :primary-key)))))

(defmigration
 create-posts
 (up [] (create h2-spec (table :posts (integer :id :primary-key))))
 (down [] (drop h2-spec (table :posts (integer :id :primary-key)))))

As you see, this file is now located by default in your project `src` directory and is usable from any other part of your application. The `dump` command will generate it if not already created. You can now reorder migrations at will and run them from inside a jar/war file.

One thing to note is that for some practical reason, I've decided to make the migration methods not take any arguments, the actions are copied verbatim. Because of this, the migrations namespace load a another namespace, lobos.config by default, that will contain the relevant variables used inside all actions. As this is standard Clojure code, you could change those defaults at will.

I've updated the readme file, but not the website documentation page yet. The migration frontend as not changed much anyway. Hopefully, that will be the last major change for this feature, I'm looking for any sort of feedback, meanwhile I'll continue to improve it until it is ready for the 0.8 release.

The new code is available in the latest SNAPSHOT release on Clojars.

P.S.: I won't be giving any more support for the old code, as it was only experimental, switch to the new code as soon as you can!
Reply all
Reply to author
Forward
0 new messages