<?php

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

class CreateShareLinksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('share_links', function (Blueprint $table) {
            $table->id();
            $table->string('uid')->unique();
            $table->string('type', 20);
            $table->bigInteger('gallery_id')->unsigned()->nullable();
            $table->bigInteger('gallery_item_id')->unsigned()->nullable();
            $table->json('permissions');
            $table->string('url', 255);
            $table->dateTime('expires_at')->nullable();

            $table->timestamps();

            $table->foreign('gallery_id')
                ->references('id')
                ->on('galleries')
                ->onDelete('cascade');

            $table->foreign('gallery_item_id')
                ->references('id')
                ->on('gallery_items')
                ->onDelete('cascade');
        });
    }

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