<?php

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

class CreateKeyValuePairsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('key_value_pairs', function (Blueprint $table) {
            $table->id();
            $table->string('owner_type'); //'user', 'order', 'transaction'
            $table->unsignedBigInteger('owner_id');
            $table->string('key');
            $table->string('value');
            $table->timestamps();

            $table->index(['owner_type', 'owner_id']);
        });
    }

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