Skip to content

Addition of migrations

Choose a tag to compare

@Faheem-maker Faheem-maker released this 20 Apr 15:00
· 33 commits to main since this release
c07c0cf

Migrations allow you to version control your database schema. You can create a migration file using the make:migration command.

Example:

php tiny make:migration create_products_table

Example Migration

Here's an example that creates a migration for a products table:

<?php

namespace app\migrations;

class CreateProductsTable
{
    public function up()
    {
        $tableCmd = db()->createTable('products');
        $tableCmd->id();
        $tableCmd->string('title');
        $tableCmd->string('image');
        $tableCmd->timestamps();
        $tableCmd->execute();
    }

    public function down()
    {
        db()->dropTable('products');
    }
}

Executing Migration

Finally, you can apply the migration using migrate command.

php tiny migrate