-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDbalNestedSetSchema.php
More file actions
48 lines (40 loc) · 1.37 KB
/
DbalNestedSetSchema.php
File metadata and controls
48 lines (40 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace PNX\NestedSet\Storage;
use Doctrine\DBAL\Schema\Schema;
use PNX\NestedSet\NestedSetSchemaInterface;
/**
* Provides DBAL Nested set schema operations.
*/
class DbalNestedSetSchema extends BaseDbalStorage implements NestedSetSchemaInterface {
/**
* {@inheritdoc}
*/
public function create() {
$schema = new Schema();
$tree = $schema->createTable($this->tableName);
$tree->addColumn("id", "integer", ["unsigned" => TRUE]);
$tree->addColumn("revision_id", "integer", ["unsigned" => TRUE]);
$tree->addColumn("left_pos", "integer", ["unsigned" => TRUE]);
$tree->addColumn("right_pos", "integer", ["unsigned" => TRUE]);
$tree->addColumn("depth", "integer", ["unsigned" => TRUE]);
$tree->setPrimaryKey(['id', 'revision_id']);
$tree->addIndex(['revision_id']);
$tree->addIndex(['id', 'revision_id', 'left_pos', 'right_pos', 'depth']);
$tree->addIndex(['left_pos', 'right_pos']);
$tree->addIndex(['right_pos']);
$tree->addIndex(['depth']);
foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
$this->connection->exec($sql);
}
}
/**
* {@inheritdoc}
*/
public function drop() {
$schema = new Schema();
$schema->dropTable($this->tableName);
foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
$this->connection->exec($sql);
}
}
}