Skip to content

Instantly share code, notes, and snippets.

@half-ogre
Created December 8, 2011 21:27
Show Gist options
  • Save half-ogre/1448679 to your computer and use it in GitHub Desktop.
Save half-ogre/1448679 to your computer and use it in GitHub Desktop.
Deleting a package registration directly in the database
use NuGetGallery
BEGIN TRAN
DECLARE @PackageRegistrationId nvarchar(max)
SET @PackageRegistrationId = '<id>'
ALTER TABLE GallerySettings NOCHECK CONSTRAINT ALL
DELETE FROM PackageStatistics
FROM PackageStatistics ps
JOIN Packages p ON p.[Key] = ps.PackageKey
JOIN PackageRegistrations pr ON pr.[Key] = p.PackageRegistrationKey
WHERE pr.Id = @PackageRegistrationId
ALTER TABLE GallerySettings CHECK CONSTRAINT ALL
DELETE FROM PackageDependencies
FROM PackageDependencies pd
JOIN Packages p ON p.[Key] = pd.PackageKey
JOIN PackageRegistrations pr ON pr.[Key] = p.PackageRegistrationKey
WHERE pr.Id = @PackageRegistrationId
DELETE FROM PackageAuthors
FROM PackageAuthors pa
JOIN Packages p ON p.[Key] = pa.PackageKey
JOIN PackageRegistrations pr ON pr.[Key] = p.PackageRegistrationKey
WHERE pr.Id = @PackageRegistrationId
DELETE FROM Packages
FROM Packages p
JOIN PackageRegistrations pr ON pr.[Key] = p.PackageRegistrationKey
WHERE pr.Id = @PackageRegistrationId
DELETE FROM PackageOwnerRequests
FROM PackageOwnerRequests por
JOIN PackageRegistrations pr ON pr.[Key] = por.PackageRegistrationKey
WHERE pr.Id = @PackageRegistrationId
DELETE FROM PackageRegistrationOwners
FROM PackageRegistrationOwners pro
JOIN PackageRegistrations pr ON pr.[Key] = pro.PackageRegistrationKey
WHERE pr.Id = @PackageRegistrationId
DELETE FROM PackageRegistrations WHERE Id = @PackageRegistrationId
COMMIT TRAN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment