Skip to content

Commit 7e52b41

Browse files
committed
numeric type calculation for 1.5+ tnt versions
1 parent e7f8de7 commit 7e52b41

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

src/Migrations/Bootstrap.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ public function migrate(Contracts\Manager $manager)
1414
}
1515

1616
$schema = $manager->getSchema();
17+
$number = $schema->getNumberType();
1718

1819
$schema->createSpace('sequence');
19-
$schema->createIndex('sequence', 'id', ['parts' => [1, 'UNSIGNED']]);
20-
$schema->createIndex('sequence', 'space', ['parts' => [2, 'UNSIGNED']]);
20+
$schema->createIndex('sequence', 'id', ['parts' => [1, $number]]);
21+
$schema->createIndex('sequence', 'space', ['parts' => [2, $number]]);
2122

2223
$schema->createSpace('property');
23-
$schema->createIndex('property', 'id', ['parts' => [1, 'UNSIGNED']]);
24-
$schema->createIndex('property', 'space', ['parts' => [2, 'UNSIGNED'], 'unique' => false]);
25-
$schema->createIndex('property', 'index_space', ['parts' => [3, 'UNSIGNED', 2, 'UNSIGNED']]);
24+
$schema->createIndex('property', 'id', ['parts' => [1, $number]]);
25+
$schema->createIndex('property', 'space', ['parts' => [2, $number], 'unique' => false]);
26+
$schema->createIndex('property', 'index_space', ['parts' => [3, $number, 2, $number]]);
2627
$schema->createIndex('property', 'type', ['parts' => [5, 'STR'], 'unique' => false]);
2728

2829
$client = $manager->getClient();

src/Schema/Convention.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
namespace Tarantool\Mapper\Schema;
44

55
use Tarantool\Mapper\Contracts;
6+
use Exception;
67

78
class Convention implements Contracts\Convention
89
{
10+
private $numberType;
11+
12+
public function setNumberType($type)
13+
{
14+
$this->numberType = $type;
15+
}
16+
917
public function getType($property)
1018
{
1119
if ($property == 'id') {
@@ -24,7 +32,10 @@ public function getTarantoolType($type)
2432
return 'STR';
2533
}
2634

27-
return 'UNSIGNED';
35+
if(!$this->numberType) {
36+
throw new Exception("numberType property is null", 1);
37+
}
38+
return $this->numberType;
2839
}
2940

3041
public function isPrimitive($type)

src/Schema/Meta.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public function getConvention()
145145
{
146146
if (!isset($this->convention)) {
147147
$this->convention = new Convention();
148+
$this->convention->setNumberType($this->manager->getSchema()->getNumberType());
148149
}
149150

150151
return $this->convention;

src/Schema/Schema.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class Schema implements Contracts\Schema
1111
{
1212
protected $client;
13+
protected $numberType;
1314
protected $spaceSpace;
1415
protected $indexSpace;
1516
protected $spaceId = [];
@@ -21,14 +22,24 @@ public function __construct(Client $client, array $data = null)
2122
$this->indexSpace = $client->getSpace(Space::VINDEX);
2223

2324
if($data) {
24-
$this->spaceId = $data;
25+
$this->spaceId = $data[0];
26+
$this->numberType = $data[1];
2527

2628
} else {
2729
$this->collectData();
2830
}
2931

3032
}
3133

34+
public function getNumberType()
35+
{
36+
if(!$this->numberType) {
37+
$version = $this->client->evaluate('return box.info.version')->getData()[0];
38+
$this->numberType = $version >= '1.7' ? 'UNSIGNED' : 'NUM';
39+
}
40+
return $this->numberType;
41+
}
42+
3243
public function getSpaceId($space)
3344
{
3445
if (!array_key_exists($space, $this->spaceId)) {
@@ -140,6 +151,6 @@ private function collectData()
140151
public function toArray()
141152
{
142153
$this->collectData();
143-
return $this->spaceId;
154+
return [$this->spaceId, $this->numberType];
144155
}
145156
}

0 commit comments

Comments
 (0)