simple migration tool with UP only

View project onGitHub


Dbup is a simple migration tool that is written by PHP.

  • You have only to download dbup.phar.
  • Dbup has only up command. Dbup does not have down command.
  • Dbup uses just a plain old sql, so you don't have to learn ORM nor DSL. You write sql file and just call up command.
  • Dbup uses just PDO class to migrate.
  • Dbup doesn't need the table of the migration status in a database to do up.
  • Dbup uses .ini format for your database configuration. It is familier to each languages.


  • PHP 5.4.0 or later
  • PDO extension


see on github

Quick Install and Run

// if you want to get from CLI
$ cd your_repo_root/repo_name
$ wget https://github.com/brtriver/dbup/raw/master/dbup.phar

// initialize dbup
$ php dbup.phar init
$ vi .dbup/properties.ini

// make a migration old plain sql file.
$ vi sql/V1__sample_select.sql
$ php dbup.phar status
$ php dbup.phar up --dry-run
$ php dbup.phar up


Installing Dbup is as easy as it can get. Download the dbup.phar and run init, then .dbup and sql directory are created and set a sample properties.ini file and sql files.

$ php dbup.phar init

change the database config in .dbup/properties.ini.

dsn = "mysql:dbname=testdatabase;host=localhost"
user = "testuser"
password = "testpassword"

see also PHP PDO document

You can also assign environment variables to your database configuration file. Dbup reads DBUP_ prefixed environment variables if the names are placed in .ini file with surrounded '%%'. For example, user parameter of the following ini will be replaced to a value of the environment variable DBUP_USERNAME if it is defined.

user = "%%DBUP_USERNAME%%"

Naming for migration sql files

You have to name a sql file like below:


V is prefix. the separator is __ (two underscores). Suffix is .sql

You have to do $ php dbup.phar create scriptname. This comamnd create an empty new sql file.


List all commands.

$ php dbup.phar

You have to write a sql file to sql directory.

Show status.

$ php dbup.phar status
dbup migration status
Applied At | migration sql file
2013-05-01 22:37:32 | V1__sample_select.sql
appending... | V2__sample.sql
appending... | V3__sample.sql
appending... | V20__sample.sql
appending... | V100__sample.sql

update database after writing a new sql file.

$ php dbup.phar up

that's all. simple.

How check status ?

When you run up command, the sql file will be copied to .dbup/applied directory. Dbup compares with .dbup/applied and sql directory whether the sql file has done or not. If the same name files exist in both directories, up command ignores this file as being applied.

In other words, If you copy the sql file to .dbup/applied directory manualy, this sql file is ignored. And If you delete the sql from .dbup/applied directory manualy, this sql file will be used agein.

With git

If you manage your project by git or want not to share applied statuses, you have to add .dbup/applied/* in .gitignore.


Dbup is not stable now so before you use dbup in your production, it is necessary to test enough in devlopment or staging environment.




Dbup is licensed under the MIT license.