File migration

PHOTO EMBED

Tue Aug 09 2022 02:39:45 GMT+0000 (Coordinated Universal Time)

Saved by @Anoplay

// function up default
public function up()
{
  Schema::create('tests', function (Blueprint $table) {
    $table->id();
    $table->timestamps();
  });
}


// function down default
public function down()
{
  Schema::dropIfExists('tests');
}


// column uuid
$table->uuid('id');

// column string
$table->string('caption');

// column boolean
$table->boolean('do');

// column datetime
$table->dateTime('date');

// column jsonb
$table->jsonb('config');

// column integer
$table->integer('point');

// column text
$table->text('desc');

// column is primary
$table->uuid('id')->primary();

// column is index
$table->string('type')->index();

// column is nullable
$table->text('description')->nullable();

// column is unsigned
$table->integer('order')->unsigned();

// colimn is default value
$table->boolean('publish_score')->default(false);

// drop column
$table->dropColumn('alt_absence_config');

// example while add new column on table

public function up()
{
  Schema::table('deeds', function (Blueprint $table) {
    $table->dropColumn('deed_rule_id');
    $table->boolean('do')->nullable()->change();
    $table->uuid('deedable_id')->index();
    $table->string('deedable_type')->index();
  });
}

public function down()
{
  Schema::table('deeds', function (Blueprint $table) {
    $table->uuid('deed_rule_id')->index();
    $table->boolean('do')->nullable(false)->change();
    $table->dropColumn('deedable_id');
    $table->dropColumn('deedable_type');
  });
}

// end example

content_copyCOPY