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

Mysql   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B dropAllTables() 0 30 1
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