generated from yii2-extensions/template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add migration files for tree and multiple_tree tables with support for various database drivers.
#66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6920654
feat: Add migration files for `tree` and `multiple_tree` tables with …
terabytesoftw 87c490b
Apply fixes from StyleCI
StyleCIBot 848d8ef
fix: update database migration rollback to include all migrations.
terabytesoftw dce2ec7
fix: enhance database creation by ensuring migration table is dropped…
terabytesoftw 3ac2128
fix: update migration rollback parameters for consistency and improve…
terabytesoftw 0eaa556
fix: ensure migration tables are dropped before running migrations in…
terabytesoftw 80be5fc
fix: replace migration command with direct database creation in test …
terabytesoftw f3b8b32
fix: streamline database setup by removing redundant table drops in t…
terabytesoftw 6de7b05
fix: refactor migration table creation for consistency and improve te…
terabytesoftw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use yii\db\Migration; | ||
|
|
||
| class m250707_103609_tree extends Migration | ||
| { | ||
| public function safeUp() | ||
| { | ||
| $primaryKey = $this->db->driverName === 'oci' | ||
| ? 'NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY' | ||
| : $this->primaryKey(); | ||
|
|
||
| $nameColumn = $this->db->driverName === 'oci' | ||
| ? $this->string(4000)->notNull() | ||
| : $this->text()->notNull(); | ||
|
|
||
| $this->createTable('{{%tree}}', [ | ||
| 'id' => $primaryKey, | ||
| 'name' => $nameColumn, | ||
| 'lft' => $this->integer()->notNull(), | ||
| 'rgt' => $this->integer()->notNull(), | ||
| 'depth' => $this->integer()->notNull(), | ||
| ]); | ||
|
|
||
| $this->createIndex('idx_tree_lft', '{{%tree}}', 'lft'); | ||
| $this->createIndex('idx_tree_rgt', '{{%tree}}', 'rgt'); | ||
| $this->createIndex('idx_tree_depth', '{{%tree}}', 'depth'); | ||
| $this->createIndex('idx_tree_lft_rgt', '{{%tree}}', ['lft', 'rgt']); | ||
|
|
||
| if ($this->db->driverName !== 'sqlite') { | ||
| $this->addCommentOnTable('{{%tree}}', 'Nested sets tree structure for hierarchical data'); | ||
| $this->addCommentOnColumn('{{%tree}}', 'id', 'Primary key of the tree node'); | ||
| $this->addCommentOnColumn('{{%tree}}', 'name', 'Name of the tree node'); | ||
| $this->addCommentOnColumn('{{%tree}}', 'lft', 'Left boundary of nested set'); | ||
| $this->addCommentOnColumn('{{%tree}}', 'rgt', 'Right boundary of nested set'); | ||
| $this->addCommentOnColumn('{{%tree}}', 'depth', 'Node depth in the tree hierarchy'); | ||
| } | ||
| } | ||
|
|
||
| public function safeDown() | ||
| { | ||
| $this->dropTable('{{%tree}}'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use yii\db\Migration; | ||
|
|
||
| class m250707_104009_multiple_tree extends Migration | ||
| { | ||
| public function safeUp() | ||
| { | ||
| $primaryKey = $this->db->driverName === 'oci' | ||
| ? 'NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY' | ||
| : $this->primaryKey(); | ||
|
|
||
| $nameColumn = $this->db->driverName === 'oci' | ||
| ? $this->string(4000)->notNull() | ||
| : $this->text()->notNull(); | ||
|
|
||
| $this->createTable('{{%multiple_tree}}', [ | ||
| 'id' => $primaryKey, | ||
| 'tree' => $this->integer()->null(), | ||
| 'name' => $nameColumn, | ||
| 'lft' => $this->integer()->notNull(), | ||
| 'rgt' => $this->integer()->notNull(), | ||
| 'depth' => $this->integer()->notNull(), | ||
| ]); | ||
terabytesoftw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $this->createIndex('idx_multiple_tree_tree', '{{%multiple_tree}}', 'tree'); | ||
| $this->createIndex('idx_multiple_tree_lft', '{{%multiple_tree}}', 'lft'); | ||
| $this->createIndex('idx_multiple_tree_rgt', '{{%multiple_tree}}', 'rgt'); | ||
| $this->createIndex('idx_multiple_tree_depth', '{{%multiple_tree}}', 'depth'); | ||
| $this->createIndex('idx_multiple_tree_tree_lft_rgt', '{{%multiple_tree}}', ['tree', 'lft', 'rgt']); | ||
|
|
||
| if ($this->db->driverName !== 'sqlite') { | ||
| $this->addCommentOnTable('{{%multiple_tree}}', 'Multiple nested sets tree structure for hierarchical data'); | ||
| $this->addCommentOnColumn('{{%multiple_tree}}', 'tree', 'Tree identifier for multiple trees support'); | ||
| $this->addCommentOnColumn('{{%multiple_tree}}', 'lft', 'Left boundary of nested set'); | ||
| $this->addCommentOnColumn('{{%multiple_tree}}', 'rgt', 'Right boundary of nested set'); | ||
| $this->addCommentOnColumn('{{%multiple_tree}}', 'depth', 'Node depth in the tree hierarchy'); | ||
| } | ||
| } | ||
|
|
||
| public function safeDown() | ||
| { | ||
| $this->dropTable('{{%multiple_tree}}'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace yii2\extensions\nestedsets\tests\support\stub; | ||
|
|
||
| use yii\console\controllers\MigrateController; | ||
|
|
||
| final class EchoMigrateController extends MigrateController | ||
| { | ||
| public function stdout($string) | ||
| { | ||
| echo $string; | ||
|
|
||
| return true; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.