h1. database-migrations

database-migrations is a system roughly equivalent to rails migrations for common lisp.  It allows you to migrate your database from one version to another in an easy manner.

h2. documentation

The system is very simple, so there isn't really much documentation available besides the docstrings.  They should be sufficient for your needs.

h2. example

I use the current unix system time to name my migrations.  You may use any number, as long as its positive.

First create the migrations for your system and write them in your source.  To easen the burden, there is a package available to do this work in.  You may however prefer to make one of your own.

  (in-package :migration-user)
  (setf *db-connection-parameters* '("database-name" "database-user" "database-password" "hostname-or-server-connection-path"))
  (def-query-migration 1239884301 "create users"
    :execute "CREATE TABLE application_user ( user_id SERIAL PRIMARY KEY, name text, email text )"
    :revert  "DROP TABLE application_user")
  (def-query-migration 1239884351 "create books"
    :execute "CREATE TABLE book ( book_id SERIAL PRIMARY KEY, owner_id INTEGER REFERENCES application_user, title text, description text )"
    :revert  "DROP TABLE book")

After loading this source, you can easily update the database in the REPL.  Each of these commands take a version, so you're able to specify how far you want the migration to be done.  The given version is always inclusive (thus downgrade will remove all higher-numbered migrations including that one, and upgrade will add all lower-numbered versions including that one).

  (migration-user::upgrade) ;; this will upgrade the database to the latest version available
  (migration-user::downgrade) ;; this will downgrade the database to the first version

Aad Versteden <>
Aad Versteden <>