Module

Migrations

Generate Migrations

In VaahCms to generate Migrations follow the steps provided below:

step 1:

Generate migrations with the help of VaahCLI by clicking here

or

Run the below command

 npx vaah cms:m-make migration <module-name> <migration-name>

e.g

npx vaah cms:m-make migration Sample sp_products

step 2:

This will generate a migration file at VaahCms/Modules/Sample/Database/Migrations/. You can make changes to this file acording to your database schema needs.

Let's edit the migration file to following:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class SpProducts extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        Schema::create('sp_products', function (Blueprint $table) {
            $table->increments('id');
            $table->uuid('uuid')->nullable()->index();
            $table->string('name')->index();
            $table->string('slug')->index();
            $table->unsignedInteger('price')->index();
            //----common fields
            $table->text('meta')->nullable();
            $table->integer('created_by')->nullable()->index();
            $table->integer('updated_by')->nullable()->index();
            $table->integer('deleted_by')->nullable()->index();
            $table->timestamps();
            $table->softDeletes();
            $table->index(['created_at', 'updated_at', 'deleted_at']);
            //----/common fields

        });
    }

    /**
    * Reverse the migrations.
    *
    * @return void
    */
    public function down()
    {
        Schema::dropIfExists('sp_products');
    }
}

step 3:

Now you need to run the migrations by visiting the following url

<public-url>/backend#/vaah/modules/

List of all the modules will be displayed. From this list, find your module and click on Actions button present on the right side of that same module to run the migrations.
Follow below image for reference: migration

step 4:

Now you need to click on Run Migrations button out of three options available to you.
Follow below image for reference: run the migrations

The table will be created and will be added to the database tables's list.
Follow below image for reference: products-table


Copyright © 2024