Completed
Push — master ( f0c834...50e414 )
by Freek
01:47
created

Pgsql   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dropAllTables() 0 10 2
A getTableNames() 0 6 1
1
<?php
2
3
namespace Spatie\MigrateFresh\TableDroppers;
4
5
use DB;
6
use Illuminate\Support\Collection;
7
8
class Pgsql implements TableDropper
9
{
10
    public function dropAllTables()
11
    {
12
        $tableNames = $this->getTableNames();
13
14
        if ($tableNames->isEmpty()) {
15
            return;
16
        }
17
18
        DB::statement("DROP TABLE {$tableNames->implode(',')} CASCADE");
19
    }
20
21
    /**
22
     * Get a list of all tables in the schema.
23
     *
24
     * @return \Illuminate\Support\Collection
25
     */
26
    protected function getTableNames()
27
    {
28
        return collect(
29
            DB::select('SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = ?', [DB::getConfig('schema')])
30
        )->pluck('tablename');
31
    }
32
}
33