Skip to content

Database migrations and utilities

Jason Austin edited this page Aug 19, 2013 · 1 revision

OTF provides several utilities, accessible in the ottools folder, dealing with databases. These are command line utilities that are not web-accessible.

Database Migrations

OTF comes with a built-in database migration script manager, similar to that provided by Ruby on Rails. Database migrations are housed in the /db folder and are numbered sequentially. Each migration has an up() and down() method, doing and undoing an action, respectably.

The utility, migrate.php has several options:

-c is the command. -c has the options for up, down, latest, rebuild, createtable and setlatestversion

-e is the environment to use. This integrates in with the apps application.ini file to pull db connection information from the requested environment.

To run the utility, you will do php otutils/migrate.php -c latest -e development. This will bring your development DB environment up to the latest DB migration.

DB Table Prefixing

It is important to note that OTF allows for DB table prefixing. That means that a developer can specify a table name prefix to add to every table in the system. All the models will take this into account without any developer interaction. This is good for deploying a codebase in multiple places with the same database powering it.

This is available to the DB migrations as well. It is a best practice to reference the table prefix in the queries inside each db migration. You access the table prefix as a class public variable $this->tablePrefix.

Database Backup

OTF provides a simple file to backup your database to the filesystem. dbbackup.php has several options:

-e environment to copy. Mapped to the enivornments in your application.ini file.

-p path to copy the file to. Make sure the user running the script has the ability to write to the desired directory.

To execute this command, you would do php otutils/dbbackup.php -e development -p /usr/local/backup.sql.

It is important to note that dbbackup.php uses mysqldump on the backend.

Database Copy

Copying database content around can be a pain, but OTF has you covered. dbcopy.php has several options:

-s source environment to copy from. Mapped to the enivornments in your application.ini file.

-d destination environment to copy to. Mapped to the enivornments in your application.ini file. Note that you cannot set the destination as the production environment. This is to protect you from doing something dumb and overwritting the production DB with a development DB.

To execute this command, you would do php otutils/dbcopy.php -s production -d development.

It is important to note that dbcopy.php uses mysqldump on the backend.

Clone this wiki locally