|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tarantool\Mapper\Migrations; |
|
4
|
|
|
|
|
5
|
|
|
use Tarantool\Mapper\Contracts; |
|
6
|
|
|
|
|
7
|
|
|
class Bootstrap implements Contracts\Migration |
|
8
|
|
|
{ |
|
9
|
|
|
public function migrate(Contracts\Manager $manager) |
|
10
|
|
|
{ |
|
11
|
|
|
$client = $manager->getClient(); |
|
|
|
|
|
|
12
|
|
|
if ($manager->getSchema()->hasSpace('sequences')) { |
|
13
|
|
|
return true; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
$schema = $manager->getSchema(); |
|
17
|
|
|
|
|
18
|
|
|
$schema->createSpace('sequences'); |
|
19
|
|
|
$schema->createIndex('sequences', 'id', ['parts' => [1, 'NUM']]); |
|
20
|
|
|
$schema->createIndex('sequences', 'name', ['parts' => [2, 'STR']]); |
|
21
|
|
|
|
|
22
|
|
|
$schema->createSpace('mapping'); |
|
23
|
|
|
$schema->createIndex('mapping', 'id', ['parts' => [1, 'NUM']]); |
|
24
|
|
|
$schema->createIndex('mapping', 'space', ['parts' => [2, 'STR'], 'unique' => false]); |
|
25
|
|
|
|
|
26
|
|
|
$client = $manager->getClient(); |
|
27
|
|
|
|
|
28
|
|
|
$mapping = $client->getSpace('mapping'); |
|
29
|
|
|
$mapping->insert([1, 'sequences', 0, 'id']); |
|
30
|
|
|
$mapping->insert([2, 'sequences', 1, 'name']); |
|
31
|
|
|
$mapping->insert([3, 'sequences', 2, 'value']); |
|
32
|
|
|
$mapping->insert([4, 'mapping', 0, 'id']); |
|
33
|
|
|
$mapping->insert([5, 'mapping', 1, 'space']); |
|
34
|
|
|
$mapping->insert([6, 'mapping', 2, 'line']); |
|
35
|
|
|
$mapping->insert([7, 'mapping', 3, 'property']); |
|
36
|
|
|
|
|
37
|
|
|
$sequence = $client->getSpace('sequences'); |
|
38
|
|
|
$sequence->insert([1, 'sequences', 2]); |
|
39
|
|
|
$sequence->insert([2, 'mapping', 7]); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.