<?php

use Server\Database\Migrations\ParentMigration;
use Illuminate\Database\Schema\Blueprint;

class CreateContractsTable extends ParentMigration
{

    public function up()
    {

            $has_mining = getenv("NODE_MINING");
            if ($has_mining === "yes") {

                $this->schema->create('contracts', function (Blueprint $table) {
                
                    $table->increments('id');

                    $table->integer('user_id');
                    $table->string('plan')->nullable();
                    $table->string('expiry_date')->nullable();
                    $table->integer('power')->default(1);
                    $table->integer('hashrate')->default(1);

                    $table->integer('currency')->default(1);
                    $table->float('speed_per_day', 11, 8);
                    $table->float('speed_per_second', 11, 8);

                    $table->integer('start_timestamp');
                    $table->integer('end_timestamp')->nullable();
                    $table->integer('expiry_timestamp')->nullable();

                    $table->float('seconds_past')->nullable();
                    $table->float('minutes_past')->nullable();
                    $table->float('hours_past')->nullable();
                    $table->float('days_past')->nullable();

                    $table->double('mined', 14, 5)->default(0);
                    $table->double('added', 14, 5)->default(0);

                    $table->boolean('status')->default(1);

                    $table->string('updated_at_month')->nullable();
                    $table->string('updated_at_day')->nullable();
                    $table->timestamps();

                });
   
            }
    }

    public function down()
    {
        $has_mining = getenv("NODE_MINING");
        if ($has_mining === "yes") {
            $this->schema->drop('contracts');
        }
    }
}