Completed
Push — master ( 0f46ff...89eb26 )
by yuuki
11s
created

CouchbaseMigrationRepository::createRepository()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
10
 * THE SOFTWARE.
11
 */
12
13
namespace Ytake\LaravelCouchbase\Migrations;
14
15
use Illuminate\Database\Schema\Blueprint;
16
use Ytake\LaravelCouchbase\Schema\Builder;
17
use Ytake\LaravelCouchbase\Query\Builder as QueryBuilder;
18
use Ytake\LaravelCouchbase\Schema\Blueprint as CouchbaseBlueprint;
19
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
20
21
/**
22
 * Class CouchbaseMigrationRepository
23
 * @codeCoverageIgnore
24
 *
25
 * @author Yuuki Takezawa<[email protected]>
26
 */
27
class CouchbaseMigrationRepository extends DatabaseMigrationRepository
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function log($file, $batch)
33
    {
34
        $record = ['migration' => $file, 'batch' => $batch];
35
36
        $builder = $this->table();
37
        if ($builder instanceof QueryBuilder) {
38
            /** @var Builder */
39
            $builder->key("{$file}:{$batch}")->insert($record);
40
41
            return;
42
        }
43
        $builder->insert($record);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function createRepository()
50
    {
51
        $schema = $this->getConnection()->getSchemaBuilder();
52
53
        if ($schema instanceof Builder) {
54
            $schema->create($this->table, function (CouchbaseBlueprint $table) {
55
                $table->primaryIndex();
56
                $table->index(['migration', 'batch'], 'migration_secondary_index');
57
            });
58
59
            return;
60
        }
61
        $schema->create($this->table, function (Blueprint $table) {
62
            $table->string('migration');
63
            $table->integer('batch');
64
        });
65
    }
66
}
67