Passed
Pull Request — master (#9)
by nguereza
02:20
created

AddProductsTable20231207060117::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 25
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 36
rs 9.52
1
<?php
2
declare(strict_types=1);
3
4
namespace Platine\Framework\Migration;
5
6
use Platine\Database\Schema\CreateTable;
7
use Platine\Framework\Migration\AbstractMigration;
8
9
class AddProductsTable20231207060117 extends AbstractMigration
10
{
11
12
    public function up(): void
13
    {
14
        //Action when migrate up
15
        $this->create('products', function (CreateTable $table) {
16
            $table->integer('id')
17
                  ->autoincrement()
18
                 ->primary();
19
            
20
            $table->string('name')
21
                 ->description('The product name')
22
                 ->notNull();
23
            
24
            $table->string('description')
25
                 ->description('The product description');
26
            
27
            $table->float('price')
28
                   ->defaultValue(0)
29
                   ->description('The product price')
30
                   ->notNull();
31
            
32
            $table->float('quantity')
33
                   ->defaultValue(0)
34
                   ->description('The product quantity')
35
                   ->notNull();
36
            
37
            $table->integer('product_category_id')
38
                 ->description('Product category')
39
                  ->notNull();
40
            
41
            $table->timestamps();
42
            
43
            $table->foreign('product_category_id')
44
                  ->references('product_categories', 'id')
45
                  ->onDelete('NO ACTION');
46
47
            $table->engine('INNODB');
48
        });
49
    }
50
51
    public function down(): void
52
    {
53
        //Action when migrate down
54
        $this->drop('products');
55
    }
56
}