<?php

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

class CreateAnnouncementSegmentTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('announcement_segment', function (Blueprint $table) {

            $table->primary(['announcement_id', 'segment_id']);
            $table->bigInteger('announcement_id')->unsigned();
            $table->bigInteger('segment_id')->unsigned();
            $table->timestamps();
            $table->foreign('announcement_id')
                ->references('id')
                ->on('announcements')->onDelete('cascade');
            $table->foreign('segment_id')
                ->references('id')
                ->on('segments')->onDelete('cascade');
        });
    }

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