Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding regular readme to make github happy
- Loading branch information
1 parent
9d455b1
commit 3f2407b
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
h1. database-verioning | ||
|
||
database-versioning is a system roughly equivalent to rails migrations. 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. | ||
|
||
<code> | ||
(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") | ||
</code> | ||
|
||
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). | ||
|
||
<code> | ||
(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 | ||
</code> |