From be6f7374fa213ca2392db42a75c86d6ad5fcce3e Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 12 Jun 2024 02:42:38 -0400 Subject: [PATCH 1/6] Add note upgrade Support JSON columns for MariaDB 10.4 or higher. --- framework/UPGRADE.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index 3a9569a9822..df59de44a58 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -51,6 +51,11 @@ if you want to upgrade from version A to version C and there is version B between A and C, you need to follow the instructions for both A and B. +Upgrade from Yii 2.0.50 + +* Since Yii 2.0.50 added tests for `MariaDB`, correcting the behavior for `JSON` column type, now they work the same for +`MySQL` and `MariaDb`. + Upgrade from Yii 2.0.48 ----------------------- From 21132cca9c58aa6328391f289bad9a6a658dcc9c Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 12 Jun 2024 02:45:46 -0400 Subject: [PATCH 2/6] fix. --- framework/UPGRADE.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index df59de44a58..cdaa4d028e4 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -52,9 +52,11 @@ version B between A and C, you need to follow the instructions for both A and B. Upgrade from Yii 2.0.50 +----------------------- -* Since Yii 2.0.50 added tests for `MariaDB`, correcting the behavior for `JSON` column type, now they work the same for -`MySQL` and `MariaDb`. +* Minimum PHP version requirement is now PHP `7.3.0`. +* Added tests for `MariaDB`, correcting the behavior for `JSON` column type, now they work the same for `MySQL` and +`MariaDb`. Upgrade from Yii 2.0.48 From 46e7a8722793b54de3caf95799bec4e56b8c16d0 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 26 Jun 2024 07:13:56 -0400 Subject: [PATCH 3/6] Apply fix review. --- framework/UPGRADE.md | 106 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 3 deletions(-) diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index cdaa4d028e4..f38665640bb 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -54,10 +54,110 @@ for both A and B. Upgrade from Yii 2.0.50 ----------------------- -* Minimum PHP version requirement is now PHP `7.3.0`. -* Added tests for `MariaDB`, correcting the behavior for `JSON` column type, now they work the same for `MySQL` and -`MariaDb`. +* Correcting the behavior for `JSON` column type in `MariaDb`. +Example usage of `JSON` column type in `db`: + +```php +db; +$command = $db->createCommand(); + +// Create a table with a JSON column +$command->createTable( + 'products', + [ + 'id' => Schema::TYPE_PK, + 'details' => Schema::TYPE_JSON, + ], +)->execute(); + +// Insert a new product +$command->insert( + 'products', + [ + 'details' => [ + 'name' => 'apple', + 'price' => 100, + 'color' => 'blue', + 'size' => 'small', + ], + ], +)->execute(); + +$records = $db->createCommand('SELECT * FROM product')->queryAll(); +``` + +Example usage of `JSON` column type in `ActiveRecord`: + +```php +details = [ + 'name' => 'windows', + 'color' => 'red', + 'price' => 200, + 'size' => 'large', +]; + +// Save the product +$product->save(); + +// Read the first product +$product = ProductModel::findOne(1); + +// Get the product details +$details = $product->details; + +echo 'Name: ' . $details['name']; +echo 'Color: ' . $details['color']; +echo 'Size: ' . $details['size']; + +// Read all products with color red +$products = ProductModel::find() + ->where(new \yii\db\Expression('JSON_EXTRACT(details, "$.color") = :color', [':color' => 'red'])) + ->all(); + +// Loop through all products +foreach ($products as $product) { + $details = $product->details; + echo 'Name: ' . $details['name']; + echo 'Color: ' . $details['color']; + echo 'Size: ' . $details['size']; +} +``` Upgrade from Yii 2.0.48 ----------------------- From ce8948e0144e8023500bde830873025b783c67b8 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 26 Jun 2024 07:16:49 -0400 Subject: [PATCH 4/6] Fix error typo. --- framework/UPGRADE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index f38665640bb..5de3c9eb7b6 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -96,7 +96,7 @@ Example usage of `JSON` column type in `ActiveRecord`: ```php Date: Wed, 26 Jun 2024 07:22:55 -0400 Subject: [PATCH 5/6] Add comment. --- framework/UPGRADE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index 5de3c9eb7b6..fb257b32f68 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -88,6 +88,7 @@ $command->insert( ], )->execute(); +// Read all products $records = $db->createCommand('SELECT * FROM product')->queryAll(); ``` From 9799212ab9f3249b3278dc07dd70687ce865612e Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 26 Jun 2024 08:54:55 -0400 Subject: [PATCH 6/6] Fix error typo. --- framework/UPGRADE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index fb257b32f68..f75f025301c 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -89,7 +89,7 @@ $command->insert( )->execute(); // Read all products -$records = $db->createCommand('SELECT * FROM product')->queryAll(); +$records = $db->createCommand('SELECT * FROM products')->queryAll(); ``` Example usage of `JSON` column type in `ActiveRecord`: