aboutsummaryrefslogtreecommitdiff
path: root/database/migrations/2021_08_02_000000_create_rates_table.php
blob: c6925d0686a91a340b4dfb14af48ecbbfd6e946a (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
53
54
55
56
57
58
59
60
61
62
63
64
65
<?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'
          )
        );
        DB::table('currency')->insert(
          array(
            'name' => 'US Dollar',
            'unit' => '$',
            'description' => 'Destroyed by Breton Woods'
          )
        );
        DB::table('rates')->insert(
          array(
            'currency_id' =>  1,
            'relative_id' =>  2,
            'value' => 100000.00
          ));
    }

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