Completed
Pull Request — master (#30)
by
unknown
06:34
created

Mysql::dropAllTables()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
namespace Spatie\MigrateFresh\TableDroppers;
4
5
use DB;
6
use Schema;
7
use stdClass;
8
9
class Mysql implements TableDropper
10
{
11
    public function dropAllTables()
12
    {
13
        Schema::disableForeignKeyConstraints();
14
15
        collect(DB::select("SHOW FULL TABLES WHERE Table_Type = 'BASE TABLE'"))
16
            ->map(
17
                function (stdClass $tableProperties) {
18
                    return get_object_vars($tableProperties)[key($tableProperties)];
19
                }
20
            )
21
            ->each(
22
                function (string $tableName) {
23
                    Schema::drop($tableName);
24
                }
25
            );
26
            
27
        collect(DB::select("SHOW FULL TABLES WHERE Table_Type = 'VIEW'"))
28
            ->map(
29
                function (stdClass $tableProperties) {
30
                    return get_object_vars($tableProperties)[key($tableProperties)];
31
                }
32
            )
33
            ->each(
34
                function (string $viewName) {
35
                    DB::statement('DROP VIEW '.$viewName);
36
                }
37
            );
38
39
        Schema::enableForeignKeyConstraints();
40
    }
41
}
42