Download the PHP package phpixie/migrate without Composer

On this page you can find all versions of the php package phpixie/migrate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package migrate

Migrate

PHPixie migration library

Author Source Code Software License

PHPixie Migrate allows you to version your database schema and apply updates to it in a conistent way. It also allows you to define some data to be inserted in the database, which is useful when writing tests or demo-ing the code.

Configuration

Let's look at the default configuration in assets/config/migrate.php:

Most proably you won't need to change anything here, unless you are handling multiple databases, or different sets of seed data.

Creating and destroying the database

You can now create and destroy your database using the command line. This is done using the framework:database command:

E.g. running conole framework:database create will create a database.

Migrations

First let's start with a brief introduction. Migrations allow you to keep your database schema modifications in your code, which is much more convenient than sharing database dumps or manually applying changes on your production database. They work in simple way: a special table is created in the database that has a single row and column and keeps the name of the last applied migration. When a migration is executed all migrations that have a name "larger" than the current one will be applied in natsort() order. E.g. if we have files 1.sql, 2.sql,...22.sql and the latest executed migration is 13.sql then all migrations between 14 and 22 will be executed and the last migration field will be set to 22. The migrations can be written in .sql and .php formats.

SQL migrations

These are very simple. It is just an SQL file with statememnts delimited by the -- statement separator:

PHP migrations

These are just PHP files that also allow you to execute SQL commands and also provide access to the Database component.

PHP migrations allow you a bit more flexibility than SQL ones, but SQL migration files can also be executed directly on the database without even using the Migrate component.

It is highly recommended to add some short description to your migration names, and since we are using natsort() order you can safely write any comment you like after for example an underscore: 33_fairies_table.sql.

You can also use subfolders in your migrations directory, which is helpful if you have a lot of files there. In that case the sorting will be applied to the entire subpath, not just the file name. E.g. you can have your files in such structure: /2016/03/22/fairies_table.sql.

To execute the migrations use the framework:migrate command:

We also need to address some questions here.

Why arent there down migrations for rollback?

If you think from the perspective of the database itself, there is no such thing as a schema rollback. Rolling back is just applying another migration that reverses previous changes. In many cases a rollback is not even possible, for example if you rollback table deletion, the rollback might recreate the table structure but won't bring back the data in it.

Why are changes written in raw SQL and not using some universal methods like createTable etc.?

The problem of universal methods is that they often omit the subtle differences between databases and make too many assumptions. There is also the possibility that after an update such universal library might start creating the tables in a slightly different fashion and then your production database that had the migrations applied months ago will be in a different state than a new database whre the same migrations have been applied more recently. Additionaly there already exist many tools for creating and converting database schemas that there is no need to replicate this functionality in a migration library.

Seeds

Seeds are sets of data that can be used to fill the database. This can be some default users, item categories etc. They also can be used to prepare your application for some functional tests. Each seed file contains data for a single table and it's name must match the name of that table. The files themselves can be either .json or .php, e.g:

or

When using .php files you also have access to the Database component:

To insert the seed data use the framework:seed command:

If some tables that are to be seeded already contain some data this will result in an error. To cler the tables before inserting the data use the --truncate flag.

You can create multiple seed profiles in separate directories for the same database connection by adding them to /assets/config/migrate.php configuration file.

Using without the framework

As all the other PHPixie components you can use Migrate without the framework. For example like this:

In this case the console commands will be run, seed and database, without the framework prefix.


All versions of migrate with dependencies

PHP Build Version
Package Version
Requires phpixie/console Version ~3.3
phpixie/slice Version ~3.0
phpixie/database Version ~3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package phpixie/migrate contains the following files

Loading the files please wait ....