Completed
Push — master ( f5a493...f6c233 )
by Joao
03:20
created

MySqlCommand::executeSql()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace ByJG\DbMigration\Commands;
4
5
use ByJG\AnyDataset\ConnectionManagement;
6
use ByJG\AnyDataset\Repository\DBDataset;
7
8
class MySqlCommand extends AbstractCommand
9
{
10
11
    public static function prepareEnvironment(ConnectionManagement $connection)
12
    {
13
        $database = $connection->getDatabase();
14
15
        $newConnection = new ConnectionManagement(str_replace("/$database", "/", $connection->getDbConnectionString()));
16
        $dbDataset = new DBDataset($newConnection->getDbConnectionString());
17
        $dbDataset->execSQL("CREATE SCHEMA IF NOT EXISTS `$database` DEFAULT CHARACTER SET utf8 ;");
18
    }
19
20
    public function createDatabase()
21
    {
22
        $database = $this->getDbDataset()->getConnectionManagement()->getDatabase();
23
24
        $this->getDbDataset()->execSQL("CREATE SCHEMA IF NOT EXISTS `$database` DEFAULT CHARACTER SET utf8 ;");
25
        $this->getDbDataset()->execSQL("USE `$database`");
26
    }
27
28
    public function dropDatabase()
29
    {
30
        $database = $this->getDbDataset()->getConnectionManagement()->getDatabase();
31
32
        $this->getDbDataset()->execSQL("drop database `$database`");
33
    }
34
35
    public function createVersion()
36
    {
37
        $this->getDbDataset()->execSQL('CREATE TABLE IF NOT EXISTS migration_version (version int)');
38
        $this->checkExistsVersion();
39
    }
40
41
    public function executeSql($sql)
42
    {
43
        $this->getDbDataset()->execSQL($sql);
44
    }
45
}
46