Has anyone got a py script that will find, iterate and delete all versions within an Enterprise GDB?

3248
4
11-24-2014 09:30 PM
BenVan_Kesteren1
Occasional Contributor III

I am currently running the below code to delete all versions before doing a weekly compress. But as you can see it is very primative and the hard coding of the names is becoming annoying as I am having to edit it each time a GIS User starts or leaves our buisness.

Is there a simple tool that will find/list all versions? That way I can then go ahead and delete them once a list has been created.

# Name: DeleteAllVersion.py
# Description: Deletes all versions from our SDE
# By Ben Van Kesteren 22/07/2014

# Import system modules
import arcpy

# Set local variables
inWorkspace = r"Database Connections/GISADMIN@SDE_Spatial@Smithy.sde"
Nathan = "Nathan"
Ben = "Ben_Edit"
David = "David_Armstrong"
James = "James"
Patrick = "Patrick"
Rory = "Rory"
Josh = "Josh"
MrsBeer = "Mrs_Beer_Edit"
#Russell = "Muddy_Edit"
Patrea = "Patrea"
Kerrie = "Kerrie"
SteveM = "Steve_Edit"
Helen = "Helen"
MattJ = "Matt_Johnson"

# Execute DeleteVersion
arcpy.DeleteVersion_management(inWorkspace, Nathan)
arcpy.DeleteVersion_management(inWorkspace, Ben)
arcpy.DeleteVersion_management(inWorkspace, David)
arcpy.DeleteVersion_management(inWorkspace, James)
arcpy.DeleteVersion_management(inWorkspace, Patrick)
arcpy.DeleteVersion_management(inWorkspace, Rory)
arcpy.DeleteVersion_management(inWorkspace, Josh)
arcpy.DeleteVersion_management(inWorkspace, MrsBeer)
#arcpy.DeleteVersion_management(inWorkspace, Russell)
arcpy.DeleteVersion_management(inWorkspace, Patrea)
arcpy.DeleteVersion_management(inWorkspace, Kerrie)
arcpy.DeleteVersion_management(inWorkspace, SteveM)
arcpy.DeleteVersion_management(inWorkspace, Helen)
arcpy.DeleteVersion_management(inWorkspace, MattJ)
0 Kudos
4 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Ben,

Are you reconciling/posting the version before you delete it?  This is a step you will want to take to make sure you are not losing any of the user's edits.  You can use the Reconcile Versions tool to do this.  This tool has an option to delete the version after it's posted.

BenVan_Kesteren1
Occasional Contributor III

ah excellent, good point. Yes all the users are informed to reconcile or post each week prior to my weekly maintenance. This is generally successful, but as people are sometimes away at last minute we try to hold off the maintenance until everyone is at work.

One thing I would like to consider, is reconcile/post on everyone's behalf. It is very unusual for someone not to want to reconcile/post each week, so to elimate this user error possibility I would like to automate it, so this is something else I am looking at setting up during this process.

I have just had a quick look at the Reconcile Versions tool, and it is exactly what I am looking for, thanks for that Jake Skinner‌, greatly appreciated.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Which version of ArcGIS Desktop are you using?  Does ListVersions in the ArcPy Data Access (arcpy.da) not work for you?  Or, do you want to only work with a subset of all versions?  Or yet, do you not know how to iterate over a list?

BenVan_Kesteren1
Occasional Contributor III

No you are 100% correct, I have only just now re-looked at this problem I listed a couple of months ago and it has clicked (i'm slow thats for sure! haha).

I can simply list all versions, then reconcile said versions then delete. I will give this angle a go.

Thanks for your help all.

PS.

  1. Can someone confirm that if a user forgets to reconcile/post before I delete the version, all the add/deletes will be lost during a compress? Or are they lost as soon as the user is deleted?
  2. And secondly, if a user does forget, and I were to use reconcile version tool, do these two options achieve the exact same thing? There is no difference between me forcing the reconcile and the user remembering to?

Thanks for the help.

0 Kudos