def createInstances(db):
    cu = db.cursor()
    commit = False
    if "Instances" not in db.tables:
        cu.execute("""
        CREATE TABLE Instances(
            instanceId      %(PRIMARYKEY)s,
            itemId          INTEGER NOT NULL,
            versionId       INTEGER NOT NULL,
            flavorId        INTEGER NOT NULL,
            clonedFromId    INTEGER,
            troveType       INTEGER NOT NULL DEFAULT 0,
            isPresent       INTEGER NOT NULL DEFAULT 0,
            fingerprint     %(BINARY20)s,
            changed         NUMERIC(14,0) NOT NULL DEFAULT 0,
            CONSTRAINT Instances_itemId_fk
                FOREIGN KEY (itemId) REFERENCES Items(itemId)
                ON DELETE RESTRICT ON UPDATE CASCADE,
            CONSTRAINT Instances_versionId_fk
                FOREIGN KEY (versionId) REFERENCES Versions(versionId)
                ON DELETE CASCADE ON UPDATE CASCADE,
            CONSTRAINT Instances_flavorId_fk
                FOREIGN KEY (flavorId) REFERENCES Flavors(flavorId)
                ON DELETE RESTRICT ON UPDATE CASCADE,
            CONSTRAINT Instances_clonedfromid_fk
                FOREIGN KEY (clonedFromId) REFERENCES Versions(versionId)
                ON DELETE RESTRICT ON UPDATE CASCADE
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tables["Instances"] = []
        commit = True
    # this also serves in place of a fk index for itemId
    db.createIndex("Instances", "InstancesIdx", "itemId,versionId,flavorId",
                   unique = True)
    db.createIndex("Instances", "InstancesVersionId_fk", "versionId, instanceId")
    db.createIndex("Instances", "InstancesFlavorId_fk", "flavorId, instanceId")
    db.createIndex("Instances", "InstancesClonedFromIdx", "clonedFromId,instanceId")
    db.createIndex("Instances", "InstancesChangedIdx", "changed,instanceId")
    db.createIndex("Instances", "InstancesPresentIdx", "isPresent,instanceId")
    if createTrigger(db, "Instances"):
        commit = True

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