1 | <?php |
||
9 | trait DbHelper |
||
10 | { |
||
11 | /** |
||
12 | * @var string Table name where migrations info is kept |
||
13 | */ |
||
14 | private $migrationsTable = 'migrations'; |
||
15 | |||
16 | /** |
||
17 | * @var string Table name where seeds info is kept |
||
18 | */ |
||
19 | private $seedsTable = 'seeds'; |
||
20 | |||
21 | /** |
||
22 | * Return class name by file basename |
||
23 | * @param string $baseName |
||
24 | * |
||
25 | * @return string |
||
26 | */ |
||
27 | private function getClassName($baseName) |
||
28 | { |
||
29 | $filenameParts = explode('_', $baseName); |
||
30 | $class = ''; |
||
31 | |||
32 | array_shift($filenameParts); |
||
33 | |||
34 | foreach ($filenameParts as $key => $filenamePart) { |
||
35 | $class .= ucfirst($filenamePart); |
||
36 | } |
||
37 | |||
38 | return $class; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @param string $tableName |
||
43 | */ |
||
44 | private function safeCreateTable($tableName) |
||
45 | { |
||
46 | if (!Capsule::schema()->hasTable($tableName)) { |
||
47 | Capsule::schema()->create($tableName, function($table) { |
||
48 | $table->string('version'); |
||
49 | $table->timestamp('apply_time')->useCurrent(); |
||
50 | $table->primary('version'); |
||
51 | }); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param string $name |
||
57 | * @param string $table |
||
58 | * @return bool |
||
59 | */ |
||
60 | private function isRowExist($name, $table) |
||
61 | { |
||
62 | $item = Capsule::table($table)->where('version', $name)->first(); |
||
63 | return !is_null($item); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @param string $name |
||
68 | * @param string $table |
||
69 | */ |
||
70 | private function insertRow($name, $table) |
||
71 | { |
||
72 | Capsule::table($table)->insert([ |
||
73 | 'version' => $name, |
||
74 | ]); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param string $name |
||
79 | * @param string $table |
||
80 | */ |
||
81 | private function deleteRow($name, $table) |
||
87 | |||
88 | /** |
||
89 | * Run list of commands in files |
||
90 | * |
||
91 | * @param string $path |
||
92 | * @param OutputInterface $output |
||
93 | * @param string $tableName |
||
94 | * @param string $method |
||
95 | * |
||
96 | * @return void |
||
97 | */ |
||
98 | private function runAction($path, OutputInterface $output, $tableName, $method) |
||
143 | } |
||
144 |