Completed
Push — master ( 424df6...6d7ac3 )
by Joao
9s
created

MySqlDatabase::createVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace ByJG\DbMigration\Database;
4
5
use ByJG\AnyDataset\Factory;
6
use ByJG\Util\Uri;
7
use Psr\Http\Message\UriInterface;
8
9
class MySqlDatabase extends AbstractDatabase
10
{
11
12 View Code Duplication
    public static function prepareEnvironment(UriInterface $uri)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
    {
14
        $database = preg_replace('~^/~', '', $uri->getPath());
15
16
        $customUri = new Uri($uri->__toString());
17
18
        $dbDriver = Factory::getDbRelationalInstance($customUri->withPath('/')->__toString());
19
        $dbDriver->execute("CREATE SCHEMA IF NOT EXISTS `$database` DEFAULT CHARACTER SET utf8 ;");
20
    }
21
22 View Code Duplication
    public function createDatabase()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24
        $database = preg_replace('~^/~', '', $this->getDbDriver()->getUri()->getPath());
25
26
        $this->getDbDriver()->execute("CREATE SCHEMA IF NOT EXISTS `$database` DEFAULT CHARACTER SET utf8 ;");
27
        $this->getDbDriver()->execute("USE `$database`");
28
    }
29
30
    public function dropDatabase()
31
    {
32
        $database = preg_replace('~^/~', '', $this->getDbDriver()->getUri()->getPath());
33
34
        $this->getDbDriver()->execute("drop database `$database`");
35
    }
36
37
    /**
38
     * @throws \ByJG\DbMigration\Exception\DatabaseNotVersionedException
39
     * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException
40
     */
41
    public function createVersion()
42
    {
43
        $this->getDbDriver()->execute('CREATE TABLE IF NOT EXISTS migration_version (version int, status varchar(20))');
44
        $this->checkExistsVersion();
45
    }
46
47
    public function executeSql($sql)
48
    {
49
        $this->getDbDriver()->execute($sql);
50
    }
51
}
52