msupply-foundation / msupply-cold-chain

Android application for viewing and monitoring temperatures of fridges
GNU General Public License v3.0
3 stars 3 forks source link

Re-order temperature_log and temperature_breach integration sync #291

Closed jmbrunskill closed 4 months ago

jmbrunskill commented 4 months ago

Fixes #290

Sends the temperature breach records first, then temperature logs, which means the temperature logs changes won't fail with a foreign key constraint.

Note: Accidentally committed this to the develop branch 🫣

See: https://github.com/msupply-foundation/open-msupply/pull/2901 for more context if required

mark-prins commented 4 months ago

I had removed the FK on the temperature log table to prevent this issue without changing CCA. Odd that the FK is still there. I was concerned that older versions of CCA would sync with OMS and have issues - how would you work around that? A version check for the API?

jmbrunskill commented 4 months ago

how would you work around that?

I have a suggestion PR which creates a temporary record here? https://github.com/msupply-foundation/open-msupply/pull/2913

I had removed the FK on the temperature log table to prevent this issue without changing CCA. Odd that the FK is still there.

CREATE TABLE temperature_log (
id TEXT NOT NULL PRIMARY KEY,
temperature {DOUBLE} NOT NULL,
sensor_id TEXT NOT NULL REFERENCES sensor(id),
store_id TEXT NOT NULL REFERENCES store(id),
location_id TEXT REFERENCES location(id),
datetime {DATETIME} NOT NULL,
temperature_breach_id TEXT REFERENCES temperature_breach(id)
);   

I discussed the same idea with Andrei yesterday (e.g. removing the Foreign key, but he was concerned about it) I put some other thoughts here in the OMS PR https://github.com/msupply-foundation/open-msupply/pull/2901