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

Pgsql::dropAllTables()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
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