<?php

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

class ChangeColumnOfOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->dropColumn('payment_id');
            $table->dropColumn('payment_code');
            $table->dropColumn('delivery_address_id');
            $table->string('code')->nullable()->after('id');
            $table->text('note')->nullable()->after('estimated_delivery_date');
            $table->smallInteger('payment_method')->default(1)->after('estimated_delivery_date');
            $table->string('type')->nullable()->change();
        });
        Schema::table('payments', function (Blueprint $table) {
            $table->integer('order_id')->nullable()->after('id');
            $table->longText('customer_info')->nullable()->after('content');
            $table->longText('content')->nullable()->change();
            $table->longText('error_content')->nullable()->change();
        });
        Schema::table('delivery_addresses', function (Blueprint $table) {
            $table->integer('order_id')->nullable()->after('id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->dropColumn('code');
            $table->dropColumn('note');
            $table->dropColumn('payment_method');
            $table->string('payment_id')->nullable()->after('estimated_delivery_date');
            $table->string('payment_code')->nullable()->after('estimated_delivery_date');
            $table->integer('delivery_address_id')->nullable()->after('estimated_delivery_date');
            $table->string('type')->nullable()->change();
        });
        Schema::table('payments', function (Blueprint $table) {
            $table->dropColumn('order_id');
            $table->dropColumn('customer_info');
            $table->longText('content')->nullable()->change();
            $table->longText('error_content')->nullable()->change();
        });
        Schema::table('delivery_addresses', function (Blueprint $table) {
            $table->dropColumn('order_id');
        });
    }
}
