Skip to content

Commit 89d17ad

Browse files
committed
fix: update SQL table creation syntax for tree and multiple_tree migrations to use standard data types and indexing.
1 parent 4033556 commit 89d17ad

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ The nested sets model is a technique for storing hierarchical data in a relation
7878
Example tree structure:
7979
Electronics (1,12,0)
8080
├── Mobile Phones (2,7,1)
81-
│ └── Smartphones (3,6,1)
82-
│ └── iPhone (4,5,2)
81+
│ └── Smartphones (3,6,2)
82+
│ └── iPhone (4,5,3)
8383
└── Computers (8,11,1)
8484
└── Laptops (9,10,2)
8585
@@ -135,37 +135,37 @@ return [
135135
**Single tree** (`m250707_103609_tree.php`). Creates a `tree` table for single hierarchical structure.
136136

137137
```sql
138-
CREATE TABLE `tree` (
139-
`id` int(11) NOT NULL AUTO_INCREMENT,
140-
`name` varchar(255) NOT NULL,
141-
`lft` int(11) NOT NULL,
142-
`rgt` int(11) NOT NULL,
143-
`depth` int(11) NOT NULL,
144-
PRIMARY KEY (`id`),
145-
KEY `idx_tree_lft` (`lft`),
146-
KEY `idx_tree_rgt` (`rgt`),
147-
KEY `idx_tree_depth` (`depth`),
148-
KEY `idx_tree_lft_rgt` (`lft`,`rgt`)
138+
CREATE TABLE tree (
139+
id INTEGER NOT NULL PRIMARY KEY,
140+
name VARCHAR(255) NOT NULL,
141+
lft INTEGER NOT NULL,
142+
rgt INTEGER NOT NULL,
143+
depth INTEGER NOT NULL
149144
);
145+
146+
CREATE INDEX idx_tree_lft ON tree (lft);
147+
CREATE INDEX idx_tree_rgt ON tree (rgt);
148+
CREATE INDEX idx_tree_depth ON tree (depth);
149+
CREATE INDEX idx_tree_lft_rgt ON tree (lft, rgt);
150150
```
151151

152152
**Multiple trees** (`m250707_104009_multiple_tree.php`). Creates a `multiple_tree` table for multiple independent trees.
153153

154154
```sql
155-
CREATE TABLE `multiple_tree` (
156-
`id` int(11) NOT NULL AUTO_INCREMENT,
157-
`tree` int(11) DEFAULT NULL, -- Tree identifier
158-
`name` varchar(255) NOT NULL,
159-
`lft` int(11) NOT NULL,
160-
`rgt` int(11) NOT NULL,
161-
`depth` int(11) NOT NULL,
162-
PRIMARY KEY (`id`),
163-
KEY `idx_multiple_tree_tree` (`tree`),
164-
KEY `idx_multiple_tree_lft` (`lft`),
165-
KEY `idx_multiple_tree_rgt` (`rgt`),
166-
KEY `idx_multiple_tree_depth` (`depth`),
167-
KEY `idx_multiple_tree_tree_lft_rgt` (`tree`,`lft`,`rgt`)
155+
CREATE TABLE multiple_tree (
156+
id INTEGER NOT NULL PRIMARY KEY,
157+
tree INTEGER DEFAULT NULL,
158+
name VARCHAR(255) NOT NULL,
159+
lft INTEGER NOT NULL,
160+
rgt INTEGER NOT NULL,
161+
depth INTEGER NOT NULL
168162
);
163+
164+
CREATE INDEX idx_multiple_tree_tree ON multiple_tree (tree);
165+
CREATE INDEX idx_multiple_tree_lft ON multiple_tree (lft);
166+
CREATE INDEX idx_multiple_tree_rgt ON multiple_tree (rgt);
167+
CREATE INDEX idx_multiple_tree_depth ON multiple_tree (depth);
168+
CREATE INDEX idx_multiple_tree_tree_lft_rgt ON multiple_tree (tree, lft, rgt);
169169
```
170170

171171
### Basic Configuration

0 commit comments

Comments
 (0)