Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Fix ON DELETE CASCADE missing
Browse files Browse the repository at this point in the history
  • Loading branch information
DevElkami committed Dec 15, 2022
1 parent 6d3c54f commit d961176
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Code/Data/MySql/MySqlManagerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ id varchar(50) not null primary key,
service_id int not null,
FOREIGN KEY (service_id)
REFERENCES " + Data.ServiceRepository.TABLE_NAME + @"(id)
ON DELETE CASCADE
)");
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Code/Data/SQLite/SQLiteManagerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ id varchar(50) not null primary key,
service_id int not null,
FOREIGN KEY (service_id)
REFERENCES " + Data.ServiceRepository.TABLE_NAME + @"(id)
ON DELETE CASCADE
)");
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/Pages/Admin.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,13 @@ public IActionResult OnPostDeleteServiceAsync(int id)
{
Toolkit.Log(HttpContext, $"Suppression du service {Db.Instance.DataBase.ServiceRepository.Get(id).Name}");

Db.Instance.DataBase.ServiceRepository.Delete(new Service() { Id = id });

// On supprime aussi le manager du service si il existait
// On supprime le manager du service si il existait (sur les nouvelles versions: ON DELETE CASCADE)
Manager manager = Db.Instance.DataBase.ManagerRepository.GetByServiceId(id);
if (manager != null)
Db.Instance.DataBase.ManagerRepository.Delete(manager);

// Supression du service
Db.Instance.DataBase.ServiceRepository.Delete(new Service() { Id = id });
}
catch (Exception except)
{
Expand Down

0 comments on commit d961176

Please sign in to comment.