# MTC Migrations

MTC Migrations are a simplified version of laravel Migrations, without the use of artisan

Currently supported features:
 - Class based Migrations
 - Migration Tracking - so no migration is run twice
 - up based migrations

Unsupported features:
 - Rollback (down based) migrations

### Executing migrations

There are two ways that migrations will be executed

 1. manually via `php migrations.php`
 2. automatically, via `composer install` or `composer update`

The second option will not output any statuses.

### Using Migrations

Follow these steps to create a migration for the system, this can apply to core, shop, cms etc. These are intedended to be unique per site, not for inclusion within the core

 - Create a migrations File in the migrations folder at root level. this should be named in the following format:
 **yyyymmdd-i-name.php** for example **20161005-1-AddNamesToMembers.php**
 The Filename **MUST** have Date, Index and Name for the migration to be recognised
 - Name the class to match the Name specified in the filename eg class `AddNamesToMembers`
 - Make sure the class is in the `Mtc\Migrations` namespace
 - Make sure the class implements the `MigrationTemplate` interface
 - Implement the changes in the `up` function
 - Make sure the `up` function returns `true` at the end, otherwise it will not be registered as complete
 - Return a string in the `getDescription` function
 - Return a string in the `getPrettyName` function

An Example:
```php
<?php
namespace Mtc\Migrations;

use Mtc\Core\Models\MigrationTemplate;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
 

class AddNamesToMembers implements MigrationTemplate
{
 
    public function up(SchemaBuilder $schema)
    {
        if (false !== $schema->hasColumn('members', 'firstname')) {
            return true;
        }

        $schema->table('members', function (Blueprint $table) {
            $table->string('firstname');
            $table->string('lastname');
        });
                  
        return true;
    }
 
    public function getDescription()
    {
        return 'Add First name and Last name to the Members Table';
    }
 
    public function down(SchemaBuilder $schema)
    {
    }
 
    public function getPrettyName()
    {
        return 'Add Names to Members';
    }
    
}

```