Open bohdan-vorona opened 1 year ago
@samdark
order_attributes
field to JSON format. JsonAttributeBehavior
- it would be useful for future models with JSON field(s) for data like tags/attributes.I needed the method executeAfterFind
since I have the field order_attributes_array
I use for quick accessing the attributes in array format like this:
return implode(', ', array_map(function ($attr) {
return Html::a(Html::encode($attr), Url::to(['index', 'OrderSearch[order_attributes]' => Html::encode($attr)]));
}, $model->order_attributes_array));
But anyway I moved it to the JsonAttributeBehavior
and changed the name.
Working on checking this but my local machine is running slow. Trying to reduce the dataset.
Won't the real dataset be even larger?
Yes. And I'm not sure why it is running slow. I'm going to copy production to another database on Digital Oceans server and run the migration against it.
@cgsmith
Working on checking this but my local machine is running slow. Trying to reduce the dataset.
After adding the field?
Yes. And I'm not sure why it is running slow. I'm going to copy production to another database on Digital Oceans server and run the migration against it.
It just sits there while trying to add the field. I tried from the mysql cli too.
A good idea is to give @bohdan-vorona a DB dump so he reproduce/fix it.
Good idea. I'll get a sql dump today for you @bohdan-vorona
@cgsmith @samdark It turned out a pretty tricky thing...
On my local machine it took almost 300 seconds (5 minutes) to execute the query:
ALTER TABLE
orders
ADDorder_attributes
JSON NULL DEFAULT NULL AFTERnotes
;
To be short, it will take lots of time to add a new field to the table orders
due to lots of records. I tried all the variants I've found on the internet like setting a different mode, locking/unlocking, creating a tmp table and then moving data between tables, etc. I even tried to remove FULLTEXT due to restrictions for one of the modes presented here - https://dev.mysql.com/doc/refman/8.0/en/innodb-online-ddl-operations.html
The "faster" way: (except the direct query execution)
Only 1 minute difference
.Total time approximately: ~9-10 minutes (on my local machine).
So:
Option A. Just apply the migration as is. Probably for this purpose, it would be better to have a column, not a separate table. In addition, as a separate task, I'd propose to:
schema.sql
file with only the DB structuretest_data.sql
with test dataOption B. Create a new table - order_attribute(s)
.
Option C. Create a new table but with keeping in mind then potentially we can extend the table with other columns in future. Let's name it order_extra
or order_param(s)
with the first field attributes
needed for this task.
BTW it takes lots of time also removing the column 😁
That sounds alright. @cgsmith let's apply that during "maintenance window"?
https://github.com/CGSmith-LLC/shipwise-api/issues/165
Listing:
View:
Add/Update:
API: