c3g / freezeman_server

A freezer management and sample tracking system for C3G
GNU Lesser General Public License v3.0
4 stars 1 forks source link

Primary key changes #112

Closed UlysseFG closed 3 years ago

UlysseFG commented 3 years ago

This changes the primary key for individuals from using a string identifier submitted by the user to a automatically generated internal id. This moves the content of the id field (current id) to label.

zxenia commented 3 years ago

Hi @UlysseFG , I tested it locally: run migrations successfully on a database with the test data, everything works great.

One thing I noticed: when I go to Individuals (/fms_core/individual/) and click Recover Deleted Individuals, it lists all Individuals with old IDs as deleted. I guess it happens because Individuals with such primary keys don't exist anymore. Anyway, when I select an Individual from this list I get an error e.g. ValueError: Field 'id' expected a number but got 'SampleTest_022'. This is expected and will throw Error 500 in production.

To fix this you can look into switching IDs also in the Version object which tracks history for each Individual. An example of how it was done with Containers before I found here: https://github.com/c3g/freezeman_server/blob/master/fms_core/migrations/0005_v2_0_0.py#L32

Another option will be just to clear (delete) Version objects for old Individuals, but I think in that case we will lose the data when the individuals were imported into the database.

davidlougheed commented 3 years ago

Yeah, this was the part of the main work put into changing the primary keys for container in an effort to not break version history links at stuff

UlysseFG commented 3 years ago

Yeah you are right i missed this i could not figure what was that version thing ... I'll try to update the version ids so the links are not broken ... if it is possible... (i never worked with that i need to read some more)