Completed
Push — master ( 747e00...006ae1 )
by Changwan
03:04
created

MigrateTemplate::getContext()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 38
ccs 0
cts 32
cp 0
crap 2
rs 8.8571
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Database\Migrator;
3
4
class MigrateTemplate implements MigrateTemplateInterface
5
{
6
    /**
7
     * {@inheritdoc}
8
     */
9
    public function getContext($migrateName)
10
    {
11
        return <<<PHP
12
<?php
13
14
use Wandu\Database\Contracts\ConnectionInterface;
15
use Wandu\Database\Migrator\Migration;
16
use Wandu\Database\Query\CreateQuery;
17
use Wandu\Database\Query\Expression\RawExpression;
18
19
class {$migrateName} extends Migration 
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function migrate(ConnectionInterface \$connection)
25
    {
26
        \$connection->query(\$connection->createQueryBuilder('somethings')->create(function (CreateQuery \$table) {
27
            \$table->bigInteger('id')->unsigned()->autoIncrement();
28
29
            \$table->timestamp('created_at')->default(new RawExpression('CURRENT_TIMESTAMP'));
30
            \$table->addColumn(new RawExpression('`updated_at` TIMESTAMP DEFAULT now() ON UPDATE now()'));
31
32
            \$table->primaryKey('id');
33
        }));
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function rollback(ConnectionInterface \$connection)
40
    {
41
        \$connection->query(\$connection->createQueryBuilder('somethings')->drop());
42
    }
43
}
44
45
PHP;
46
    }
47
}
48