Closed jmbrunskill closed 4 days ago
One issue with invoice_lines, requisition_lines, but should be solvable (needs name_id, which come from related record, but when we update we usually have that record in memory)
Can potentially also use this refactor as an opportunity to remove differences in upsert methods (postgres version should work for sqlite now)
The suggestion
Currently we use database triggers to record when changes are made to records that we need to sync. This has some advantages (particularly that manual database interventions will be automatically captured), however it also has disadvantages such as the need to re-create triggers when some kinds of database changes are made, making it harder to see where and when triggers are used, and work arounds such as db manipulation to skip changelog for db migrations.
A new pattern was established with the asset sync work, that would allow the rust code to manage the changelog entries using the Upsert Trait.
Example use case
Currently we have an Upsert Trait like this used for sync. We should remove the
upsert_sync
function from this trait and refactor the associated_row.rs
file to insert the changelog record.Example code to inserting changelog in rust code.
Why should we invest time in this?
Certain types of migrations such as Name & Store merge have required re-creating all triggers in the system which creates a high risk of something being missed. Rust's code checking will ensure Allow more flexibility and logic to be managed around when and how changelog entries are created (e.g. related entries might need to be referenced to find the associated name, or store) Makes code most consistent and maintainable.
Are there any risks associated with this change?
I think it should ultimately reduce risk, but the risks of the change would be removing changelog triggers but not creating the associated
insert_changelog
functions. We also have a risk that manual changes to the database (most likely at central) wouldn't automatically be synced as we'd need a changelog record to trigger syncHow much effort is required?
Quite a bit as there's a lot of tables with change log that need to be considered and some testing would be required to make sure things are working correctly. Maybe 2-3 days?
Agreed Solution