Skip to content

Clean up sizes/sizegroup: deduplicate sizes + cross-reference table#821

Merged
HaGuesto merged 26 commits into
masterfrom
copilot/clean-up-sizes-and-sizegroups
May 20, 2026
Merged

Clean up sizes/sizegroup: deduplicate sizes + cross-reference table#821
HaGuesto merged 26 commits into
masterfrom
copilot/clean-up-sizes-and-sizegroups

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 21, 2026

Implements the size/sizegroup database cleanup.

Migration 1 – 20260421120000_CreateSizesSizegroupTable

  1. Creates the sizes_sizegroup cross-reference table (many-to-many between sizes and sizegroup).
  2. Populates it from sizes.sizegroup_id for every size currently in the table — including the 66 duplicates that Migration 2 will later remove (so no "extra memberships" block is needed).
  3. Drops the now-redundant sizegroup_id and seq columns from sizes.

The down() method restores sizegroup_id/seq, re-populates them from sizes_sizegroup, and drops the cross-reference table.

Migration 2 – 20260421130000_DeduplicateSizes

Removes 66 duplicate size rows from the sizes table (keeping the entry with the smallest ID for each label). Before deleting the duplicates, all foreign-key references are redirected to the surviving ID:

Table Column(s) updated
stock size_id
shipment_detail source_size_id, target_size_id
history from_int, to_int (for tablename='stock', changes='size_id')
itemsout size_id
distro_events_packing_list_entries size_id
distro_events_tracking_logs size_id
distro_events_unboxed_item_collections size_id

sizes_sizegroup rows for duplicate sizes are then remapped to their canonical ID via INSERT IGNORE (so canonical sizes inherit all sizegroup memberships from their duplicates). The ON DELETE CASCADE on fk_ss_size_id removes the old duplicate rows when the duplicate sizes rows are deleted.

The down() method re-inserts the 66 deleted sizes rows (id + label only, since sizegroup_id/seq are managed by Migration 1) and their corresponding sizes_sizegroup entries, then removes the inherited sizegroup memberships from the canonical sizes (partial rollback; FK remappings cannot be reconstructed).

Migration 3 – 20260421140000_DropAuditColumnsFromSizes

Removes the unused audit columns (created, created_by, modified, modified_by) from the sizes table. These columns are all NULL in every known environment and are not referenced by any application code. FK constraints and indexes on created_by / modified_by are dropped first.

The down() method restores the columns, indexes, and FK constraints referencing cms_users.

Migration 4 – 20260421150000_FixSizesData

Cleans up data inconsistencies in the sizes_sizegroup table:

  1. Sizegroup 1 (XS, S, M, L, XL, XXL): corrects seq values to XS=1, S=2, M=3, L=4, XL=5, XXL=6, Mixed=999.
  2. Sizegroup 23 (Children by year 2-3 to 14-15): corrects seq values to 2-3y=200, 4-5y=201, 6-7y=202, 8-9y=203, 10-11y=204, 12-13y=205, 14-15y=206, All ages=207, Mixed=999.
  3. Sizegroups 17, 18, 22, 25: adds the "All ages" size (id=97) to each sizegroup.

The down() method removes the added "All ages" entries and restores the original seq values.

Migration 5 – 20260421160000_RemoveSizegroup20

Removes the now-superseded sizegroup 20 ("Children by month (2-5)"), replacing it with sizegroup 17 ("Children by year (2-5, 6-10, 11-15)"):

  1. Reassigns any products rows referencing sizegroup_id=20 to sizegroup_id=17.
  2. Deletes sizes_sizegroup rows for sizegroup 20.
  3. Deletes sizegroup ID 20 from the sizegroup table.

The down() method re-inserts sizegroup 20 and its sizes_sizegroup entries (product reassignments are not reversed — partial rollback).

Code changes

File Change
include/container-stock.php Replaced implicit cross join with explicit INNER JOIN sizes_sizegroup … INNER JOIN sizes
library/ajax/getsizes.php Updated size-lookup query to JOIN via sizes_sizegroup
include/stock_edit.php Updated size-dropdown query to JOIN via sizes_sizegroup

Verification

  • Migrations run cleanly on the dev database
  • vendor/bin/parallel-lint – no errors
  • php-cs-fixer – 0 files to fix (excluding auto-generated templates)
  • No duplicate size labels remain
  • All sizegroup memberships preserved: size labels per sizegroup are identical before and after Migration 2
  • After all five migrations, the sizes table contains only id and label
  • Sizegroups 1 and 23 have correct sequential seq values; sizegroups 17, 18, 22, and 25 include "All ages"
  • Sizegroup 20 is removed; products formerly assigned to it are reassigned to sizegroup 17

Copilot AI and others added 2 commits April 21, 2026 13:34
Migration 1 (20260421120000): removes 75 duplicate size rows, updating
references in stock, shipment_detail, and history tables.

Migration 2 (20260421130000): creates sizes_sizegroup cross-reference
table with all size-sizegroup relationships (including extra sizegroup
memberships from merged duplicates), then drops sizes.sizegroup_id and
sizes.seq.

Updates include/container-stock.php to JOIN sizes_sizegroup instead of
filtering on sizes.sizegroup_id.

Agent-Logs-Url: https://github.com/boxwise/dropapp/sessions/870cef39-acd9-49fe-8c16-4dfd54f3b425

Co-authored-by: pylipp <10617122+pylipp@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@pylipp pylipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot revert any (formatting) changes in files that are NOT in db/migrations and NOT container-stock.php

@pylipp
Copy link
Copy Markdown
Contributor

pylipp commented Apr 21, 2026

…ntainer-stock.php

Agent-Logs-Url: https://github.com/boxwise/dropapp/sessions/363f3d93-798a-48aa-b118-9a9a41ecb889

Co-authored-by: pylipp <10617122+pylipp@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 21, 2026

@copilot revert any (formatting) changes in files that are NOT in db/migrations and NOT container-stock.php

Done in b060b78 — reverted formatting changes in all files outside db/migrations/ and include/container-stock.php.

Copilot AI requested a review from pylipp April 21, 2026 14:00
@pylipp pylipp marked this pull request as ready for review April 21, 2026 14:01
@pylipp pylipp requested a review from Copilot April 21, 2026 14:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the app’s size/sizegroup data model by removing duplicate sizes rows and moving from a 1→many (sizes.sizegroup_id) relationship to a many→many relationship via a new sizes_sizegroup cross-reference table, updating stockroom querying accordingly.

Changes:

  • Add a migration to deduplicate sizes labels by remapping foreign keys and deleting duplicate rows.
  • Add a migration to create/populate sizes_sizegroup, then drop sizes.sizegroup_id and sizes.seq.
  • Update the stockroom listing query to join sizes via sizes_sizegroup instead of sizes.sizegroup_id.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
include/container-stock.php Switches sizegroup matching logic to use the new sizes_sizegroup join.
db/migrations/20260421120000_deduplicate_sizes.php Remaps references to removed size IDs and deletes duplicate sizes rows.
db/migrations/20260421130000_create_sizes_sizegroup_table.php Introduces sizes_sizegroup, migrates memberships, and drops legacy sizes columns.

Comment thread include/container-stock.php Outdated
Comment thread db/migrations/20260421130000_create_sizes_sizegroup_table.php Outdated
Comment thread db/migrations/20260421130000_deduplicate_sizes.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Philipp Metzner <10617122+pylipp@users.noreply.github.com>
@pylipp
Copy link
Copy Markdown
Contributor

pylipp commented Apr 21, 2026

@copilot apply changes based on the comments in this thread

Copilot AI and others added 2 commits April 21, 2026 16:14
…getsizes.php, stock_edit.php, sizes_edit.php to use sizes_sizegroup

Agent-Logs-Url: https://github.com/boxwise/dropapp/sessions/ce308e1f-588a-4185-aa41-13ca1c14601d

Co-authored-by: pylipp <10617122+pylipp@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 21, 2026

@copilot apply changes based on the comments in this thread

Done in 18aab4f. Applied all three review changes:

  1. Migration 1 (deduplicate_sizes): Added remapping of itemsout and all distro_events_* tables that have a size_id column (via INFORMATION_SCHEMA) before the DELETE, preventing FK RESTRICT violations.

  2. include/sizes.php and library/ajax/getsizes.php: Updated all queries to JOIN via sizes_sizegroup and order by ss.seq instead of the removed sizes.sizegroup_id/sizes.seq columns. The re-ordering initialization in sizes.php now updates sizes_sizegroup.seq, and the list display uses GROUP_CONCAT for sizes belonging to multiple sizegroups.

  3. include/stock_edit.php and include/sizes_edit.php: Also updated for the removed columns — stock_edit.php uses a JOIN on sizes_sizegroup for the size dropdown, and sizes_edit.php has sizegroup_id removed from savekeys and the form (the column no longer exists on sizes).

Comment thread db/migrations/20260421120000_deduplicate_sizes.php Outdated
Copilot AI requested a review from pylipp April 21, 2026 16:27
Copilot AI requested a review from HaGuesto May 13, 2026 09:14
Copy link
Copy Markdown
Member

@HaGuesto HaGuesto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functional review continued

Run rollback

  • size and sizegroup tables are the same as before

Run first and second migration

  • number of sizes reduced from 179 to 113 as expected.
  • sizes_sizegroup table lost one enty? There seemed to be a duplicate entry of All Ages in one sizegroup.
  • history snapshot of 10 changes was correct
  • stock snapshot of 10 changes was correct
  • shipment_detail snapshot of 10 changes was correct
    @pylipp I found a shipment detail with source_size_id = NULL. does that make sense?

Run rollback of second migration

works

@boxwise boxwise deleted a comment from Copilot AI May 13, 2026
Comment thread db/migrations/20260421130000_deduplicate_sizes.php
@HaGuesto
Copy link
Copy Markdown
Member

ACTION: @HaGuesto to functional test query updates.
ACTION: @HaGuesto to test if removed "All ages" size was removed correctly.
ACTION: @HaGuesto to send @pylipp table of seq changes and 'All ages' sizes to add
ACTION: @pylipp to ask @aerinsol regarding removing "mixed" size option from "one size"

@HaGuesto
Copy link
Copy Markdown
Member

HaGuesto commented May 13, 2026

ACTION: @HaGuesto to functional test query updates.

DONE. passed

ACTION: @HaGuesto to test if removed "All ages" size was removed correctly.

Done. Yes.

ACTION: @HaGuesto to send @pylipp table of seq changes and 'All ages' sizes to add

Done

@pylipp
Copy link
Copy Markdown
Contributor

pylipp commented May 13, 2026

@copilot I need another migration to clean-up inconsistencies in the sizes data. It should run fourth.

  • update seq for sizes of sizegroup 1. It should be 1-6 for XS, S, ..., XXL and 999 for Mixed
  • update seq for sizes of sizegroup 23. It should be 200-206 for 2-3y, 4-5y, ..., 14-15y, 207 for All ages and 999 for Mixed
  • add "All ages" size for sizegroups 17, 18, 22, 25
  • implement the up() and the corresponding down migration

Copilot AI and others added 2 commits May 13, 2026 16:45
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 13, 2026

@copilot I need another migration to clean-up inconsistencies in the sizes data. It should run fourth.

  • update seq for sizes of sizegroup 1. It should be 1-6 for XS, S, ..., XXL an...

Done in 04d0dfc — added migration 20260421150000_FixSizesData:

  • Sizegroup 1: seq corrected to XS=1, S=2, M=3, L=4, XL=5, XXL=6, Mixed=999
  • Sizegroup 23: seq corrected to 2-3y=200, 4-5y=201, 6-7y=202, 8-9y=203, 10-11y=204, 12-13y=205, 14-15y=206, All ages=207, Mixed=999
  • Sizegroups 17, 18, 22, 25: "All ages" (id=97) added with seq 13, 22, 182, 246 respectively

down() removes the added "All ages" entries and restores the original seq values. Both up() and down() verified on the dev database.

Copilot finished work on behalf of pylipp May 13, 2026 16:49
@pylipp
Copy link
Copy Markdown
Contributor

pylipp commented May 20, 2026

@copilot I need another migration to remove the sizegroup 20 ("Children by year (2-5)"). It should run last.
In the up-function:

  • replace sizegroup 20 by 17 in the products table
  • remove rows with sizegroup 20 from the sizes_sizegroup table
  • remove ID 20 from the sizegroup table
    In the down function:
  • add ID 20 back to sizegroup table
  • add rows back to sizes_sizegroup table

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 20, 2026

@copilot I need another migration to remove the sizegroup 20 ("Children by year (2-5)"). It should run last.
In the up-function:

  • replace sizegroup 20 by 17 in the products table
    ...

Done in 7067a15 — added migration 20260421160000_RemoveSizegroup20:

  • up(): reassigns products with sizegroup_id=20 to sizegroup_id=17, deletes sizes_sizegroup rows for sizegroup 20 (sizes 116 "2-5 years" and 52 "Mixed"), then deletes the sizegroup 20 row.
  • down(): re-inserts the sizegroup 20 row and its two sizes_sizegroup entries (product reassignments are not reversed — partial rollback).

Verified both up() and down() on the dev database.

Copilot finished work on behalf of pylipp May 20, 2026 06:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread db/migrations/20260421140000_drop_audit_columns_from_sizes.php
Comment thread db/migrations/20260421130000_deduplicate_sizes.php
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Philipp Metzner <10617122+pylipp@users.noreply.github.com>
@HaGuesto HaGuesto merged commit 4cf6252 into master May 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants