Closed dan-tang-ssd closed 1 year ago
Interesting that it loses continents too, but not always...
I wonder if it's a mismatch between ID types. The IDs in the continents and regions tables are strings, because some are 0-padded. (E.g. South America is "005", not "5"). Could that be an issue, if the relationship tables are ints?
One test - does Central Asia and Western Asia get kept in regions? (Their IDs are 143 and 145).
Interesting that it loses continents too, but not always...
I wonder if it's a mismatch between ID types. The IDs in the continents and regions tables are strings, because some are 0-padded. (E.g. South America is "005", not "5"). Could that be an issue, if the relationship tables are ints?
One test - does Central Asia and Western Asia get kept in regions? (Their IDs are 143 and 145).
Wow, you found the root cause!
Performed testing and proved that your suspection is correct.
The solution is to change column type from big unsigned to string for continent_id and region_id columns in mapping tables. We also need to run UPDATE SQL to add padding zero for these two columns in existing mapping table records.
Deployment in staging env is completed. Performed testing with positive result.
Continent, region, country can be saved and retrieved properly. It works properly when I edit an existing initiative and creating a new initiative.
Also checked database tables contenient_project, country_project, project_region. The migration file has updated contentient_id, country_id, region_id with padding 0 format.
Screen shots:
Edit an existing initiative
Create a new initiative
Check database existing records
Note: This is a status update rather than a PR.
Update: This is now ready for review. This PR fixes #153
The region issue is being investigated with below items:
Reviewed Project, Continent, Region, Country model and their relationships. They look normal.
Some or all regions may disappear after editing an existing initiative. Number of regions removed is not fixed each time.
Problem occurs only when editing existing initiative. Problem does not occur when creating new initiative.
Similar issue also happened for continent, it is easier to replicate when we have multiple continents.
[2023-07-28 09:13:42] local.DEBUG: ProjectCrudController.setupUpdateOperation()
[2023-07-28 09:13:42] local.DEBUG: Project (573) - retrieved(): 1
[2023-07-28 09:13:42] local.DEBUG: Eastern Asia
[2023-07-28 09:13:42] local.DEBUG: 1 region(s)
[2023-07-28 09:13:42] local.DEBUG: Eastern Asia
[2023-07-28 09:13:43] local.DEBUG: Project (573) - retrieved(): 1
[2023-07-28 09:13:43] local.DEBUG: Eastern Asia
[2023-07-28 09:13:43] local.DEBUG: Project (573) - retrieved(): 1
[2023-07-28 09:13:43] local.DEBUG: Eastern Asia
[2023-07-28 09:13:43] local.DEBUG: Project (573) - saving(): 1
[2023-07-28 09:13:43] local.DEBUG: Project (573) - updating(): 1
[2023-07-28 09:13:43] local.DEBUG: Project (573) - updated(): 1
[2023-07-28 09:13:43] local.DEBUG: Project (573) - saved(): 1
[2023-07-28 09:13:43] local.DEBUG: Eastern Asia
[2023-07-28 09:13:43] local.DEBUG: Project (573) - retrieved(): 0
[2023-07-28 09:13:43] local.DEBUG: Portfolio (1008) - retrieved()
[2023-07-28 09:23:02] local.DEBUG: ProjectRegion (1) - retrieved():
[2023-07-28 09:23:02] local.DEBUG: {"id":"1","project_id":1,"region_id":154,"created_at":null,"updated_at":null}
I removed ProjectRegion model then perform testing, I got same testing result.
Checked that there is no database level trigger defined. SQL: show triggers;