Bugfix constraint migration fix#4230
Conversation
- Function to delete attribute links with one or more attribute definitions. - Call function to implement an effective cascading delete. - Refactor function naming to meet PSR-12 conventions Signed-off-by: objecttothis <objecttothis@gmail.com>
- Add drop of Generated Column to prevent failure of migration on MySQL databases. Signed-off-by: objecttothis <objecttothis@gmail.com>
- Removed blank lines - Refactored function naming for PSR compliance - Reformatted code for PSR compliance - Added logic to drop dependent foreign key constraints before deleting an index then recreating them. Signed-off-by: objecttothis <objecttothis@gmail.com>
- DROP and CREATE session table to prevent migration problems on populated databases Signed-off-by: objecttothis <objecttothis@gmail.com>
- In the event that item_id = null (e.g., it's a dropdown) it should not be included in the results. Signed-off-by: objecttothis <objecttothis@gmail.com>
- Removed delete_value function in Attributes Controller as it is unused. - Renamed postDelete_attribute_value function for PSR-12 compliance. - Renamed delete_value Attribute model function for PSR-12 compliance. - Refactored out function to getAttributeIdByValue - Replaced == with === to prevent type juggling - Reorganized parts of model to make it easier to find CRUD functions. Signed-off-by: objecttothis <objecttothis@gmail.com>
- PSR-12 Compliance formatting changes - Refactored several generic functions into the migration_helper.php - First check if primary key exists before attempting to create it. - Grouped functions together in migration_helper.php - phpdoc commenting functions Signed-off-by: objecttothis <objecttothis@gmail.com>
- There are two queries run while opening the Items view which time out on large databases with weak hardware. These indices cut the query execution in half or better. Signed-off-by: objecttothis <objecttothis@gmail.com>
- This migration reverts ospos_attribute_links_ibfk_1 and 2 to ON DELETE RESTRICT. Cascade delete is done programmatically. This is needed to have a unique column on the attribute_links table which prevents duplicate attributes from begin created with the same item_id-attribute_id-definition_id combination Signed-off-by: objecttothis <objecttothis@gmail.com>
9c1dbce to
b24dee4
Compare
Signed-off-by: objecttothis <objecttothis@gmail.com>
There was a problem hiding this comment.
This heading would be for private Model functions.
There was a problem hiding this comment.
I'd try to code to structure things logically.. having to add comments might be a code smell (according to clean code guidelines). It might just indicate naming is not good or classes are not sticking to single resonsibility principle.
|
@jekkos, I think the commit history is a little rough after rebasing on the master. When I merge, per usual I'm planning to do a squash and merge with a commit message of this to clean everything up: This PR is now ready for review. |
|
@jekkos the PHPLinter is failing on PHP 8.4 deprecations (https://github.com/opensourcepos/opensourcepos/actions/runs/15184079188/job/42700305258). I do think we need to make these changes to remove deprecated code, but that needs to be a separate PR from this one. |
|
We can keep the full history in the squashed commit message body. So typically a good commit message has a short first line describing what is is about, and then more details can be added after the first newline. I find it very useful to add info to the history this way, it's a bit of an ongoing documentation with every change that is done. |
jekkos
left a comment
There was a problem hiding this comment.
I'm not going to block the PR here at this point, I know these things take time to test. But I do have some minor remarks on the usage of comments and eventual removal of a duplicated log line. Beside that I think it looks good.
| return $builder->get()->getResultArray(); | ||
| } | ||
|
|
||
| // ============== |
There was a problem hiding this comment.
I'd try to code to structure things logically.. having to add comments might be a code smell (according to clean code guidelines). It might just indicate naming is not good or classes are not sticking to single resonsibility principle.
|
@jekkos in the morning I'll remove the comments and extra log lines. I think I was just mimicking what was in other migrations. I'm OK with just ordering class functions logically, but I think we should agree on an order and move functions to those locations as we work on the code. Doing it all here would make the commit pretty difficult to parse. I'll squash and merge after pushing those commits. |
- Removed Comments separating sections of code in Attribute model - Removed extra log line to prevent cluttering of the log Signed-off-by: objecttothis <objecttothis@gmail.com>

20250213000000_fix_attributes_cascading_delete.php reverted a change on the ospos_attribute_links_ibfk_1 and ospos_attribute_links_ibfk_2 constraints on the ospos_attribute_links table to fix a bug with not being able to delete a dropdown value. The problem is that these need to be ON DELETE RESTRICT in order to use generated_unique_column and attribute_links_uq3 to enforce no duplication of attribute links. The solution to this (in this PR) is to change them back to ON DELETE RESTRICT and programmatically cascade delete before trying to remove an entry. This way we can enforce uniqueness AND deleting dropdown rows.
closing #4237
closing #4251