Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Erlang implementation of a SQL migration application

License

NotificationsYou must be signed in to change notification settings

hengestone/erlcqlmigrate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Database migration framework for Erlang

Usage

Command Line

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]

API

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)

Creating Migrations

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]

Database support

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.

About

Erlang implementation of a SQL migration application

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Erlang100.0%

[8]ページ先頭

©2009-2025 Movatter.jp