eyf/laravel-exodus is a Laravel package for laravel yaml migrations.
It currently has 8 GitHub stars and 108 downloads on Packagist (latest version v0.2.2).
Install it with composer require eyf/laravel-exodus.
Discover more Laravel packages by eyf
or browse all Laravel packages to compare alternatives.
Last updated
Converts YAML to actual Laravel migration files.
composer require --dev eyf/laravel-exodus
database/migrations.yaml fileDefine a posts table:
# database/migrations.yaml
posts:
id: true
timestamps: true
softDeletes: true
slug: string(100).unique
title: string
content: text
excerpt: string.nullable
author_id: foreignId.constrained('users')
Run exodus command to translate the yaml file into actual Laravel migration files:
php artisan exodus
Created Migration: 2020_05_05_100005_create_posts_table
migrate as normalphp artisan migrate
Exodus is a DEV package, it is meant to ease / speed up development time.
A normal workflow while DEV'ing could be:
migrations.yaml file (Add a posts table)php artisan exodusphp artisan migratemigrations.yaml file (Add a users table)php artisan exodusphp artisan migrate:refresh (--seed)migrations.yaml fileexodus.lock fileBy default the migration file names won't change between multiple exodus runs.
This is because Exodus keeps track of the initial migration file name in database/exodus.lock (to commit in your repository).
This makes sure git sees the edits in the same migration file throughout the whole DEV.
force optionSometimes you may want to bypass the exodus.lock file (For example when you want to change the table order creation).
php artisan exodus --force
What happens:
exodus.lock)Any column can be written fluently exactly like in the Laravel migration syntax. In fact Exodus is just a light translator of a "dot notation" array to the actual PHP syntax.
my_table:
my_column_name: string(50).nullable.unique
Special column types are the "sugar" methods provided by Laravel for a better developer experience: id(), timestamps(), softDeletes(), rememberToken(), etc...
Since these column types don't have a column name (name is in the convention), just specify true as their value:
my_table:
id: true
timestamps: true
softDeletes: true
For generating a pivot table, just use two table names as follow:
users:
id: true
name: string
posts:
id: true
title: string
"@users @posts": []
This will create the following pivot migration file:
<?php
// database/migrations/2020_05_05_085245_create_post_user_pivot_table.php
class CreatePostUserPivotTable extends Migration
{
public function up()
{
Schema::create("post_user", function (Blueprint $table) {
$table
->foreignId("post_id")
->index()
->constrained();
$table
->foreignId("user_id")
->index()
->constrained();
$table->primary(["post_id", "user_id"]);
});
}
public function down()
{
Schema::dropIfExists("post_user");
}
}
You can even provide more columns to the pivot table as normal:
"@users @posts":
timestamps: true
approved_by: foreignId.nullable.constrained('users')
approved_at: timestamp.nullable
This package aims at speedind up development time. It is not meant to be used after you have launched to production. In fact the package does not provide a way to run migrations for adding or removing columns (it used to).
This is by choice.
While DEV'ing you should edit the migrations.yaml file as much as you want and run migrate:refresh (--seed) as often as possible. "This is the way".
By the time you are happy with your Schema, you must have launched in production, and then only you may create normal Laravel migration files for adding or removing column(s) in your tables. This is where the job of this package ends.
TODO: Implement safety guard making sure exodus cannot be run if it detects more migrations files than in exodus.lock.