def createAccessMaps(db):
    commit = False
    cu = db.cursor()
    # permissions by group. This only expresses/implies read
    # permissions; for write and remove the acls in Permissions are
    # controlling
    if "UserGroupTroves" not in db.tables:
        assert("UserGroups" in db.tables)
        assert("Instances" in db.tables)
        cu.execute("""
        CREATE TABLE UserGroupTroves(
            ugtId           %(PRIMARYKEY)s,
            userGroupId     INTEGER NOT NULL,
            instanceId      INTEGER NOT NULL,
            recursive       INTEGER NOT NULL DEFAULT 0,
            changed         NUMERIC(14,0) NOT NULL DEFAULT 0,
            CONSTRAINT UserGroupTroves_ugid_fk
                FOREIGN KEY (userGroupId) REFERENCES UserGroups(userGroupId)
                ON DELETE CASCADE ON UPDATE CASCADE,
            CONSTRAINT UserGroupTroves_instanceId_fk
                FOREIGN KEY (instanceId) REFERENCES Instances(instanceId)
                ON DELETE CASCADE ON UPDATE CASCADE
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tables["UserGroupTroves"] = []
        commit = True
    db.createIndex("UserGroupTroves", "UserGroupTroves_userGroupIdIdx",
                   "userGroupId,instanceId", unique=True)
    db.createIndex("UserGroupTroves", "UserGroupTroves_instanceId_fk", "instanceId")
    if createTrigger(db, "UserGroupTroves"):
        commit = True

    # this is a flattened version of UserGroupTroves
    if "UserGroupAllTroves" not in db.tables:
        assert("UserGroups" in db.tables)
        assert("Instances" in db.tables)
        assert("UserGroupTroves" in db.tables)
        cu.execute("""
        CREATE TABLE UserGroupAllTroves(
            ugtId           INTEGER NOT NULL,
            userGroupId     INTEGER NOT NULL,
            instanceId      INTEGER NOT NULL,
            CONSTRAINT UGAT_ugtId_fk
                FOREIGN KEY (ugtId) REFERENCES UserGroupTroves(ugtId)
                ON DELETE CASCADE ON UPDATE CASCADE,
            CONSTRAINT UGAT_userGroupId_fk
                FOREIGN KEY (userGroupId) REFERENCES UserGroups(userGroupId)
                ON DELETE CASCADE ON UPDATE CASCADE,
            CONSTRAINT UGAT_instanceId_fk
                FOREIGN KEY (instanceId) REFERENCES Instances(instanceId)
                ON DELETE CASCADE ON UPDATE CASCADE
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tables["UserGroupAllTroves"] = []
        commit = True
    db.createIndex("UserGroupAllTroves", "UGAT_ugtId_fk", "ugtId")
    db.createIndex("UserGroupAllTroves", "UGAT_userGroupId_fk", "userGroupId")
    db.createIndex("UserGroupAllTroves", "UGAT_instanceId_fk", "instanceId")

    # this holds in a flat structure the expansion of the Permissions table
    if "UserGroupAllPermissions" not in db.tables:
        assert("UserGroups" in db.tables)
        assert("Instances" in db.tables)
        assert("Permissions" in db.tables)
        cu.execute("""
        CREATE TABLE UserGroupAllPermissions(
            permissionId    INTEGER NOT NULL,
            userGroupId     INTEGER NOT NULL,
            instanceId      INTEGER NOT NULL,
            canWrite        INTEGER NOT NULL DEFAULT 0,
            CONSTRAINT UGAP_permissionId_fk
                FOREIGN KEY (permissionId) REFERENCES Permissions(permissionId)
                ON DELETE CASCADE ON UPDATE CASCADE,
            CONSTRAINT UGAP_userGroupId_fk
                FOREIGN KEY (userGroupId) REFERENCES UserGroups(userGroupId)
                ON DELETE CASCADE ON UPDATE CASCADE,
            CONSTRAINT UGAP_instanceId_fk
                FOREIGN KEY (instanceId) REFERENCES Instances(instanceId)
                ON DELETE CASCADE ON UPDATE CASCADE
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tables["UserGroupAllPermissions"] = []
        commit = True
    db.createIndex("UserGroupAllPermissions", "UGAP_permissionId_fk", "permissionId")
    db.createIndex("UserGroupAllPermissions", "UGAP_userGroupId_fk", "userGroupId")
    db.createIndex("UserGroupAllPermissions", "UGAP_instanceId_fk", "instanceId")

    # cache of what troves a usergroup can see. Summarizes the stuff from
    # UserGroupAllTroves and UserGroupAllPermissions
    if "UserGroupInstancesCache" not in db.tables:
        assert("UserGroups" in db.tables)
        assert("Instances" in db.tables)
        cu.execute("""
        CREATE TABLE UserGroupInstancesCache(
            userGroupId     INTEGER NOT NULL,
            instanceId      INTEGER NOT NULL,
            canWrite        INTEGER NOT NULL DEFAULT 0,
            CONSTRAINT UGIC_userGroupId_fk
                FOREIGN KEY (userGroupId) REFERENCES UserGroups(userGroupId)
                ON DELETE CASCADE ON UPDATE CASCADE,
            CONSTRAINT UGIC_instanceId_fk
                FOREIGN KEY (instanceId) REFERENCES Instances(instanceId)
                ON DELETE CASCADE ON UPDATE CASCADE
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tables["UserGroupInstancesCache"] = []
        commit = True
    db.createIndex("UserGroupInstancesCache", "UGIC_userGroupIdIdx", "userGroupId,instanceId",
                   unique=True)
    db.createIndex("UserGroupInstancesCache", "UGIC_instanceId_fk", "instanceId")

    if commit:
        db.loadSchema()
dataset/ETHPy150Open sassoftware/conary/conary/server/schema.py/createAccessMaps/original