<?php

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

class CreateAnagraficaTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('anagrafica_tipo', function (Blueprint $table) {
            $table->increments('id');
            $table->string('nome', 50);
            $table->timestamps();
        });
        
        Schema::create('anagrafica', function (Blueprint $table) {
            $table->increments('id');
            $table->string('ragione_sociale', 200);
            $table->string('partita_iva', 30);
            $table->string('codice_fiscale', 30);
            $table->string('nome', 50);
            $table->string('cognome', 50);
            $table->string('indirizzo', 200);
            $table->string('citta', 100);
            $table->string('cap', 5);
            $table->string('provincia', 2);
            $table->string('stato', 50);

            $table->string('telefono', 30);
            $table->string('cellulare', 30);
            $table->string('fax', 30);
            $table->string('email', 100);
            $table->string('skype', 50);
            $table->string('sito', 100);
            $table->text('note');
            
            $table->integer('anagrafica_tipo_id')->unsigned();
            $table->foreign('anagrafica_tipo_id')->references('id')->on('anagrafica_tipo')->onDelete('cascade');

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

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