pai-sklep/database/migrations/2021_12_08_203110_create_ca...

42 lines
1.0 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->uuid("uuid")->primary();
$table->timestamps();
$table->string("name")->index()->unique();
});
Schema::create('categories_products', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->foreignUuid("product_uuid")->references("uuid")->on("products")->cascadeOnDelete()->cascadeOnUpdate();
$table->foreignUuid("category_uuid")->references("uuid")->on("categories")->cascadeOnDelete()->cascadeOnUpdate();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('categories');
}
}