Maintnance domains

1193
5
08-09-2021 03:40 AM
by Anonymous User
Not applicable

Hello,
I am thinking about how I could use a python script to audit my domains in the sde database.
I would like to be able to:
- make an inventory of the existing domains
-Identify duplicates in the domains
-Identify domains used in services
-identify the owners of the domains
- extract domains in CSV format
-remove duplicate domains not in use
- automate this script to run every month
Has anyone thought about this problem or has a script to do this?
Thank you in advance.

0 Kudos
5 Replies
by Anonymous User
Not applicable

Hello,
I am thinking about how I could use a python script to audit my domains in the sde database.
I would like to be able to:
- make an inventory of the existing domains
-Identify duplicates in the domains
-Identify domains used in services
-identify the owners of the domains
- extract domains in CSV format
-remove duplicate domains not in use
- automate this script to run every month
Has anyone thought about this problem or has a script to do this?
Thank you in advance

0 Kudos
chrisjordan9
New Contributor

Hi, I'm thinking about how I could audit my domains in the SDE database using a python script.
I'd like to be able to: - create an inventory of existing domains - identify duplicates in domains - identify domains used in services - identify domain owners - extract domains in CSV format - remove duplicate domains not in use - automate this script to run once a month Has anyone thought about this problem or has a script that can do this check?
Thank you in advance for your consideration.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

@Anonymous User,

Here is a script that will list which domains are no longer in use.  This can be a good starting point to perform some of the other maintenance tasks you're looking to do.

import arcpy, os, sys

# Variables
report = r"C:\Temp\Python\list_unused_domains.csv"
gdbConnection = r"C:\DBConnection\SQL SERVER - DBO@VECTOR.sde"

# Create report of domains not in use
with open(report, "w") as f:
    f.write("Domains not in use\n")

    # create list of domains
    domains = arcpy.da.ListDomains(gdbConnection)
    lst_names = [domain.name for domain in domains]

    # list featureclasses
    arcpy.env.workspace = gdbConnection
    lst_fds = arcpy.ListDatasets(feature_type="feature")
    lst_fds.append("")
    lst_doms = []
    for fds in lst_fds:
        lst_fc = arcpy.ListFeatureClasses(feature_dataset=fds)
        for fc in lst_fc:
            try:
                flds = arcpy.ListFields(os.path.join(gdbConnection, fds, fc))
                for fld in flds:
                    if fld.domain != "":
                        lst_doms.append(fld.domain)
            except:
                pass


    # process tables
    lst_tbl = arcpy.ListTables()
    for tbl in lst_tbl:
         try:
             flds = arcpy.ListFields(tbl)
             for fld in flds:
                 if fld.domain != "":
                    lst_doms.append(fld.domain)
         except:
             pass

    # create list of domains not in use
    lst_notinuse = list(set(lst_names) - set(lst_doms))

    # write to file
    for dom in lst_notinuse:
        f.write(f"{dom}\n")
print("Finished")
0 Kudos
by Anonymous User
Not applicable

Thank you @JakeSkinner 
this will get me started.

0 Kudos
BlakeTerhune
MVP Regular Contributor

I also came up with a script that will delete unused domains. It should be a good starting point for doing the other things you mentioned.

Delete Unused Domains - Esri Community

0 Kudos