aboutsummaryrefslogtreecommitdiff
path: root/database/migrations/2021_08_02_000000_create_rates_table.php
blob: 0aef61daa37bebf518a2f9edcfe3e5d287f2f41a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

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

class CreateRatesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('currency', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('unit');
            $table->string('description')->nullable();
            $table->timestamps();
        });

        Schema::create('rates', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('currency_id');
            $table->foreign('currency_id')->references('id')->on('currency');
            $table->unsignedBigInteger('relative_id');
            $table->foreign('relative_id')->references('id')->on('currency');
            $table->float('value');
            $table->timestamps();
        });
        DB::table('currency')->insert(
          array(
            'name' => 'Bitcoin',
            'unit' => 'BTC',
            'description' => 'Created by Satoshi'
          )
        );
    }

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