Add primary key to CategoryItems table
Table CategoryItems, that holds relations between categories and their items (which item is placed where) is one of a few table without normal auto-increment primary key. To solve this in meantime we've set CategoryId as ID field of that table (in unit config) and instead of loading by ID alone as we usually do we load by CategoryId + ResourceId of category item.
This has undesired side effect when you have CategoryId, but don't have any category item present at a moment to finalize loading process. This problem is also explained in [in-commerce] Product creation errors [5.2.1-B2] ("SQL error on product save" section), but here we'll be creating a temporary hack.
Here I propose to add an auto-increment primary key to CategoryItems table and make use of it. Not sure though how long that ALTER TABLE query will take for CategoryItems table that has thousands of records.