Skip to content

Commit f7e9eae

Browse files
committed
fix: update name column type to varchar(255) in tree and multiple_tree migrations; add MySQL table options.
1 parent e7c88e0 commit f7e9eae

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Creates a `tree` table with the following structure:
137137
```sql
138138
CREATE TABLE `tree` (
139139
`id` int(11) NOT NULL AUTO_INCREMENT,
140-
`name` text NOT NULL,
140+
`name` varchar(255) NOT NULL,
141141
`lft` int(11) NOT NULL,
142142
`rgt` int(11) NOT NULL,
143143
`depth` int(11) NOT NULL,
@@ -157,7 +157,7 @@ Creates a `multiple_tree` table with the following structure:
157157
CREATE TABLE `multiple_tree` (
158158
`id` int(11) NOT NULL AUTO_INCREMENT,
159159
`tree` int(11) DEFAULT NULL,
160-
`name` text NOT NULL,
160+
`name` varchar(255) NOT NULL,
161161
`lft` int(11) NOT NULL,
162162
`rgt` int(11) NOT NULL,
163163
`depth` int(11) NOT NULL,

migrations/m250707_103609_tree.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@ class m250707_103609_tree extends Migration
99
public function safeUp()
1010
{
1111
$rawPrimaryKey = 'NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY';
12+
$tableOptions = [];
13+
14+
if ($this->db->driverName === 'mysql') {
15+
$tableOptions = 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci';
16+
}
1217

1318
$this->createTable(
1419
'{{%tree}}',
1520
[
1621
'id' => $this->db->driverName !== 'oci' ? $this->primaryKey()->notNull() : $rawPrimaryKey,
17-
'name' => $this->db->driverName === 'oci' ? $this->string()->notNull() : $this->text()->notNull(),
22+
'name' => $this->string(255)->notNull(),
1823
'lft' => $this->integer()->notNull(),
1924
'rgt' => $this->integer()->notNull(),
2025
'depth' => $this->integer()->notNull(),
2126
],
27+
$tableOptions,
2228
);
2329

2430
$this->createIndex('idx_tree_lft', '{{%tree}}', 'lft');

migrations/m250707_104009_multiple_tree.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@ public function safeUp()
1010
{
1111
$rawPrimaryKey = 'NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY';
1212

13+
if ($this->db->driverName === 'mysql') {
14+
$tableOptions = 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci';
15+
}
16+
1317
$this->createTable(
1418
'{{%multiple_tree}}',
1519
[
1620
'id' => $this->db->driverName !== 'oci' ? $this->primaryKey()->notNull() : $rawPrimaryKey,
1721
'tree' => $this->integer()->null(),
18-
'name' => $this->db->driverName === 'oci' ? $this->string()->notNull() : $this->text()->notNull(),
22+
'name' => $this->string(255)->notNull(),
1923
'lft' => $this->integer()->notNull(),
2024
'rgt' => $this->integer()->notNull(),
2125
'depth' => $this->integer()->notNull(),
2226
],
27+
$tableOptions,
2328
);
2429

2530
$this->createIndex('idx_multiple_tree_tree', '{{%multiple_tree}}', 'tree');

0 commit comments

Comments
 (0)