wasabee-project / Wasabee-Server

The Server-Side component for the Wasabee Project tools for Enlightened Agents.
MIT License
11 stars 5 forks source link

Some assignments are lost on update #25

Open le-jeu opened 2 years ago

le-jeu commented 2 years ago

Describe the bug On update, assignments that are already synced before are dropped by the server.

To Reproduce Steps to reproduce the behavior:

  1. Create an draw, sync and add a team
  2. Create two task, assign one
  3. Update
  4. Assign the other task
  5. Update
  6. Open WebUI to see the result
  7. Repeat (5) and see only one (alternating) task with an assignment

Related lines https://github.com/wasabee-project/Wasabee-Server/blob/76a7f79135ee33e7c20dca34e14066b2934c3a9c/model/database.go#L59

CREATE TABLE assignments (
  opID char(40) NOT NULL, 
  taskID char(40) NOT NULL, 
  gid char(21) NOT NULL, 
  KEY opID (opID), 
  KEY gid (gid), 
  CONSTRAINT fk_assignments_gid FOREIGN KEY (gid) REFERENCES agent (gid) ON DELETE CASCADE, 
  CONSTRAINT fk_assignments_opid FOREIGN KEY (opID) REFERENCES operation (ID) ON DELETE CASCADE, 
  KEY taskID (taskID,opID),
  CONSTRAINT fk_assignments_taskid FOREIGN KEY (taskID,opID) REFERENCES task (ID, opID) ON DELETE CASCADE
);

https://github.com/wasabee-project/Wasabee-Server/blob/76a7f79135ee33e7c20dca34e14066b2934c3a9c/model/markers.go#L118

I suspect we get the correct list here: https://github.com/wasabee-project/Wasabee-Server/blob/76a7f79135ee33e7c20dca34e14066b2934c3a9c/model/task.go#L200 so, already synced assignments are not "replaced", but the data is deleted following the cascade deletion due to the REPLACE INTO query.