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