Quickly mark tables as temporary

PHOTO EMBED

Mon Apr 11 2022 17:10:55 GMT+0000 (UTC)

Saved by @mzhaaao #python #gdpr #stitchfix #database

from sfgdpr import client

BBC = BumblebeeClient()
KPC = client.KeyLimePIIClient()


def set_table_temporary(namespace, table):
    resource = f"{namespace}.{table}"
    print(f"Marking {resource} temporary...")
    perm_result = KPC.set_table_permanence(resource, is_permanent=False)
    status = KPC.get_compliance_status(resource)
    assert status['success'] == True
    assert status['result'][0] == 'compliant'
    
    
def set_namespace_temporary(namespace):
    ns = BBC.get_database(namespace)
    tables = [t["table_name"] for t in ns["tables"]]
    
    for table in tables:
        set_table_temporary(namespace, table)
        
    print("Done! 🎉")

    
def set_tables_temporary(namespace, tables):
    for table in tables:
        set_table_temporary(namespace, table)
        
set_namespace_temporary('mercury_dev_mzhao')
content_copyCOPY