Commit f9eba123 authored by Dan McGee's avatar Dan McGee Committed by Lukas Fleischer
Browse files

Ensure users can be deleted when foreign keys are present



This change is necessary to prevent this:
    mysql> delete from Users where ID = 112;
    ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`aur`.`Packages`, CONSTRAINT `Packages_ibfk_2` FOREIGN KEY (`SubmitterUID`) REFERENCES `Users` (`ID`) ON DELETE NO ACTION)

As a bonus, due to foreign keys, orphaning of packages will be
automatic.
Signed-off-by: default avatarDan McGee <dan@archlinux.org>
Signed-off-by: default avatarLukas Fleischer <archlinux@cryptocrack.de>
parent abd41bbb
......@@ -114,8 +114,9 @@ CREATE TABLE Packages (
INDEX (SubmitterUID),
INDEX (MaintainerUID),
FOREIGN KEY (CategoryID) REFERENCES PackageCategories(ID) ON DELETE NO ACTION,
FOREIGN KEY (SubmitterUID) REFERENCES Users(ID) ON DELETE NO ACTION,
FOREIGN KEY (MaintainerUID) REFERENCES Users(ID) ON DELETE NO ACTION
-- deleting a user will cause packages to be orphaned, not deleted
FOREIGN KEY (SubmitterUID) REFERENCES Users(ID) ON DELETE SET NULL,
FOREIGN KEY (MaintainerUID) REFERENCES Users(ID) ON DELETE SET NULL
) ENGINE = InnoDB;
......
......@@ -801,7 +801,6 @@ function user_suspended( $id )
/*
* This should be expanded to return something
* TODO: Handle orphaning of user's packages
*/
function user_delete( $id )
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment