# Migrations
Migrations are version control for your database schema. Krayin uses Laravel's Schema facade, so the same migration runs unchanged across MySQL, MariaDB, PostgreSQL, and SQLite. This page picks up from Routes โ next we'll create the examples table the controller will read from.
For deeper Laravel-specific guidance, see the Laravel migrations docs (opens new window).
# ๐ Create the migration file
There are two ways to generate the file. Pick the path you used in Getting Started.
# Option A โ Krayin Package Generator (recommended)
php artisan package:make-migration CreateExamplesTable Webkul/Example
| Argument | Meaning |
|---|---|
CreateExamplesTable | Migration class name (will be timestamped) |
Webkul/Example | Target package |
The file lands in packages/Webkul/Example/src/Database/Migrations/.
# Option B โ Laravel artisan
If you're not using the generator, create the folder structure first:
packages
โโโ Webkul
โโโ Example
โโโ src
โโโ ...
โโโ Database
โโโ Migrations
โโโ Seeders
Then generate the migration into that folder by passing --path:
php artisan make:migration create_examples_table \
--path=packages/Webkul/Example/src/Database/Migrations
# ๐งฑ Define the table schema
Open the new migration file and replace the generated body with your schema. The Schema::create() method takes a table name and a closure that receives a Blueprint for defining columns:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('examples', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('parent_id')->nullable();
$table->string('title')->nullable();
$table->longText('description')->nullable();
$table->tinyInteger('status')->default(0);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('examples');
}
};
Always implement `down()`
The down() method must reverse whatever up() did. Skipping it makes php artisan migrate:rollback silently leave junk in the database.
# โ๏ธ Wire the migrations into the service provider
Open packages/Webkul/Example/src/Providers/ExampleServiceProvider.php and call loadMigrationsFrom() inside boot():
<?php
namespace Webkul\Example\Providers;
use Illuminate\Support\ServiceProvider;
class ExampleServiceProvider extends ServiceProvider
{
public function boot(): void
{
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
}
}
Without this call, Laravel never discovers the package's migration files.
# โจ๏ธ Run the migration
Apply the migration to your database:
php artisan migrate
You should see the new migration listed as Migrated.
To roll it back during development:
php artisan migrate:rollback
# ๐งช Verify
Confirm the examples table exists:
php artisan migrate:status | grep CreateExamplesTable
You should see a Ran (or โ) marker against the migration name. If it shows Pending, the migration file wasn't picked up โ re-check that loadMigrationsFrom() is in boot() and run composer dump-autoload followed by php artisan migrate again.
# ๐ Next steps
- Models โ create the Eloquent model that maps to this table.
- Repository โ build the repository the controller will call.
โ Models Controllers โ