Completed
Pull Request — 4.0 (#124)
by
unknown
02:42
created

OracleBlueprint::setTablePrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Yajra\Oci8\Schema;
4
5
use Illuminate\Database\Schema\Blueprint;
6
7
class OracleBlueprint extends Blueprint
8
{
9
    /**
10
     * Database prefix variable
11
     *
12
     * @var string
13
     */
14
    protected $prefix;
15
16
    /**
17
     * Table comment
18
     *
19
     * @var string
20
     */
21
    public $commentTable = null;
22
23
    /**
24
     * Column comments
25
     *
26
     * @var array
27
     */
28
    public $commentColumn = [];
29
30
    /**
31
     * set table prefix settings
32
     *
33
     * @param string $prefix
34
     */
35
    public function setTablePrefix($prefix = '')
36
    {
37
        $this->prefix = $prefix;
38
    }
39
40
    /**
41
     * Add creation and update timestampTz columns to the table.
42
     *
43
     * @return void
44
     */
45
    public function timestampsTz()
46
    {
47
        $this->timestampTz('created_at');
48
49
        $this->timestampTz('updated_at');
50
    }
51
52
    /**
53
     * Create a default index name for the table.
54
     *
55
     * @param  string $type
56
     * @param  array $columns
57
     * @return string
58
     */
59
    protected function createIndexName($type, array $columns)
60
    {
61
        $index = strtolower($this->prefix . $this->table . '_' . implode('_', $columns) . '_' . $type);
62
63
        // max index name length is 30 chars
64
        return substr(str_replace(['-', '.'], '_', $index), 0, 30);
65
    }
66
67
    /**
68
     * Set the column comment for an existing table
69
     *
70
     * @param  string $column
71
     * @param  string $comment
72
     */
73
    public function commentColumn($column, $comment)
74
    {
75
        $this->commentColumn[] = [
76
            'name' => $column,
77
            'comment' => $comment ?: ''
78
        ];
79
    }
80
81
    /**
82
     * Set the table comment for an existing table
83
     *
84
     * @param  string $comment
85
     */
86
    public function comment($comment)
87
    {
88
        $this->commentTable = $comment ?: '';
89
    }
90
}
91