Database migration framework for Erlang
Usage: erlsqlmigrate [options] [up|down|create] migrationNameOptions: -h, --helpShow the program options -v, --verboseBe verbose about what gets done -V, --Versionoutput the version number -e, --environmentEnvironment you are running migration on. Defaults to 'development' -m, --migration-dirThe directory containing your SQL migration files [./migrations] -c, --config-dirLocation of your config files [./config]
If you want to run the migrations from your code. There is an API available.
Config = [{erlcass,["host",9042,"keyspace","username","password"]}].MigDir = "migrations"Name = "description_of_migration"erlsqlmigrate:create(Config, MigDir, Name)erlsqlmigrate:up(Config, MigDir, Name)erlsqlmigrate:down(Config, MigDir, Name)
Create a config file which contains the database connection parameters as an erlang term. Using the defaults in the script this wouldsit in ./config/[enviroment].config:
{pgsql,["host",5432,"database","username","password"]}.
$ erlsqlmigrate create add-users
This will create a two files ./migrations/pgsql/up/[datestamp]_add-users.sql and ./migrations/pgsql/down/[datestamp]_add-users.sql.
All you have to do is populate these with your SQL Command and you are ready to migrate.
For example in up/add-users.sql:
CREATE TABLE users( id SERIAL PRIMARY KEY, email TEXT UNIQUE NOT NULL );
and in down/add-users.sql
DROP TABLE users
Then just run the migration
$ erlsqlmigrate up [add-users]
If there is a problem then rollback. Note if you don't supply a name it will rollback all the migrations.
$ erlsqlmigrate down [add-users]
Currently only have Postgres support and mysql support.If you would like to add functionality for another Database get in touch.It's fairly easy to add support for other databases.