This is not an official Laravel package. This package was built when I wished to have Laravel migrations in any other projects that is not using Laravel.
- Require this package with composer:
composer require talandis/lara-migrations
- Create
migrations
folder in you project's root directory
- After updating composer, create an executable file that runs migrator in your project's root folder. Sample file named
artisan
is included in this repository. - Create folder named
migrations
. All migration files will be stored here. You may change path to this folder inartisan
file. - Set database configuration
For migrations to work you have to setup database credentials. To do that you should call registerContainerItem with first parameter 'db-config' and second parameter should return an array with configuration
Sample array of database configuration
[
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'sample_db',
'username' => 'root',
'password' => 'super_secret_pass',
'charset' => 'utf8',
'prefix' => '',
'collation' => 'utf8_general_ci',
'schema' => 'public'
]
There are only two commands that looks completely the same as in Laravel
php artisan make:migration my_new_migration_name
php artisan migrate
Migration with custom database
php artisan migrate --database=development
There is an optional argument for migrate command named --database=...
.
When using this argument you might want to modify your db-config
item to reflect to that variable.
Sample with environments in separate configuration files. The following sample presumes your configuration file defines 4 constants.
$migrator->registerContainerItem( 'db-config', function ($c) {
require_once( $c['config-path'] . $c['environment'] . '.php');
return [
'driver' => 'mysql',
'host' => DB_HOST,
'database' => DB_NAME,
'username' => DB_USERNAME,
'password' => DB_PASSWORD,
'charset' => 'utf8',
'prefix' => '',
'collation' => 'utf8_general_ci',
'schema' => 'public'
];
} );