<?php

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

class CreateProdottiTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('categorie', function (Blueprint $table) {
            $table->increments('id');
            $table->string('nome', 50);
            $table->timestamps();
        });
        
        Schema::create('prodotti', function (Blueprint $table) {
            $table->increments('id');
            $table->string('descrizione', 300);
            $table->decimal('prezzo', 19, 5);
            $table->text('note');
            
            $table->integer('categoria_id')->unsigned();
            $table->foreign('categoria_id')->references('id')->on('categorie')->onDelete('cascade');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('prodotti', function(Blueprint $table){
            $table->dropForeign('prodotti_categoria_id_foreign');
            //$table->dropColumn('copyright_id');
        }); 
        
        Schema::drop('categorie');
        Schema::drop('prodotti');
    }
}
