Esempio n. 1
0
def createDBTroveFiles(db):
    if "DBTroveFiles" in db.tables:
        return
    cu = db.cursor()
    _createVersions(db, cu)
    cu.execute("""
    CREATE TABLE DBTroveFiles(
        streamId            %(PRIMARYKEY)s,
        pathId              BINARY(16),
        versionId           INTEGER,
        path                %(STRING)s,
        fileId              BINARY(20),
        instanceId          INTEGER,
        isPresent           INTEGER,
        stream              BLOB
    )""" % db.keywords)
    cu.execute("CREATE INDEX DBTroveFilesIdx ON DBTroveFiles(fileId)")
    cu.execute("CREATE INDEX DBTroveFilesInstanceIdx2 ON DBTroveFiles(instanceId, pathId)")
    cu.execute("CREATE INDEX DBTroveFilesPathIdx ON DBTroveFiles(path)")

    idtable.createIdTable(db, "Tags", "tagId", "tag")

    cu.execute("""
    CREATE TABLE DBFileTags(
        streamId            INTEGER,
        tagId               INTEGER
    )""")
    db.commit()
    db.loadSchema()
Esempio n. 2
0
def createSchema(db):
    db.loadSchema()
    cu = db.cursor()
    commit = False
    if "Commits" not in db.tables:
        cu.execute("""
        create table Commits(
            commitId    %(PRIMARYKEY)s,
            username    %(STRING)s,
            cfgtext     %(STRING)s,
            changed     %(CHANGED)s
        ) %(TABLEOPTS)s """ % db.keywords)
        db.tables["Commits"] = []
        commit = True
    db.createTrigger("Commits", "changed", "INSERT")
    db.createTrigger("Commits", "changed", "UPDATE")

    if idtable.createIdTable(db, "Items", "itemId", "item"):
        commit = True
    if idtable.createIdTable(db, "Versions", "versionId", "version"):
        commit = True
    if idtable.createIdTable(db, "Flavors", "flavorId", "flavor"):
        commit = True

    if "CommitList" not in db.tables:
        cu.execute("""
        create table CommitList(
            id          %(PRIMARYKEY)s,
            commitId    INTEGER NOT NULL,
            itemId      INTEGER NOT NULL,
            versionid   INTEGER NOT NULL,
            flavorId    INTEGER,
            changed     %(CHANGED)s,
            constraint CommitList_commitId_fk
                foreign key(commitId) references Commits(commitId)
                on delete cascade on update cascade,
            constraint CommitList_itemId_fk
                foreign key(itemId) references Items(itemId)
                on delete cascade on update cascade,
            constraint CommitList_versionId_fk
                foreign key(versionId) references Versions(versionId)
                on delete cascade on update cascade,
            constraint CommitList_flavorId_fk
                foreign key(flavorId) references Flavors(flavorId)
                on delete cascade on update cascade
        ) %(TABLEOPTS)s """ % db.keywords)
        db.tables["CommitList"] = []
        commit = True
    db.createTrigger("CommitList", "changed", "INSERT")
    db.createTrigger("CommitList", "changed", "UPDATE")
    db.createIndex("CommitList", "CommitList_commitId_idx", "commitId")
    db.createIndex("CommitList", "CommitList_itemId_idx", "itemId")
    db.createIndex("CommitList", "CommitList_version_idx", "versionId")
    if commit:
        db.commit()
    db.setVersion(DB_VERSION)
    return commit
Esempio n. 3
0
def createSchema(db):
    db.loadSchema()
    cu = db.cursor()
    commit = False
    if "Commits" not in db.tables:
        cu.execute("""
        create table Commits(
            commitId    %(PRIMARYKEY)s,
            username    %(STRING)s,
            cfgtext     %(STRING)s,
            changed     %(CHANGED)s
        ) %(TABLEOPTS)s """ % db.keywords)
        db.tables["Commits"] = []
        commit = True
    db.createTrigger("Commits", "changed", "INSERT")
    db.createTrigger("Commits", "changed", "UPDATE")

    if idtable.createIdTable(db, "Items", "itemId", "item"):
        commit = True
    if idtable.createIdTable(db, "Versions", "versionId", "version"):
        commit = True
    if idtable.createIdTable(db, "Flavors", "flavorId", "flavor"):
        commit = True

    if "CommitList" not in db.tables:
        cu.execute("""
        create table CommitList(
            id          %(PRIMARYKEY)s,
            commitId    INTEGER NOT NULL,
            itemId      INTEGER NOT NULL,
            versionid   INTEGER NOT NULL,
            flavorId    INTEGER,
            changed     %(CHANGED)s,
            constraint CommitList_commitId_fk
                foreign key(commitId) references Commits(commitId)
                on delete cascade on update cascade,
            constraint CommitList_itemId_fk
                foreign key(itemId) references Items(itemId)
                on delete cascade on update cascade,
            constraint CommitList_versionId_fk
                foreign key(versionId) references Versions(versionId)
                on delete cascade on update cascade,
            constraint CommitList_flavorId_fk
                foreign key(flavorId) references Flavors(flavorId)
                on delete cascade on update cascade
        ) %(TABLEOPTS)s """ % db.keywords)
        db.tables["CommitList"] = []
        commit = True
    db.createTrigger("CommitList", "changed", "INSERT")
    db.createTrigger("CommitList", "changed", "UPDATE")
    db.createIndex("CommitList", "CommitList_commitId_idx", "commitId")
    db.createIndex("CommitList", "CommitList_itemId_idx", "itemId")
    db.createIndex("CommitList", "CommitList_version_idx", "versionId")
    if commit:
        db.commit()
    db.setVersion(DB_VERSION)
    return commit
Esempio n. 4
0
def _createFlavors(db):
    if "Flavors" in db.tables:
        return
    cu = db.cursor()
    idtable.createIdTable(db, "Flavors", "flavorId", "flavor")
    cu.execute("SELECT FlavorID from Flavors")
    if cu.fetchone() == None:
        # reserve flavor 0 for "no flavor information"
        cu.execute("INSERT INTO Flavors VALUES (0, NULL)")
    idtable.createMappingTable(db, "DBFlavorMap", "instanceId", "flavorId")
    db.commit()
    db.loadSchema()
Esempio n. 5
0
def _createVersions(db, cu = None):
    if "Versions" in db.tables:
        return
    if cu is None:
        cu = db.cursor()
    if idtable.createIdTable(db, "Versions", "versionId", "version"):
        cu.execute("INSERT INTO Versions (versionId, version) VALUES (0, NULL)")
        db.commit()
        db.loadSchema()
Esempio n. 6
0
 def __init__(self, db):
     if 'TestItems' not in db.tables:
         idtable.createIdTable(db, 'TestItems', 'itemId', 'item')
     idtable.CachedIdTable.__init__(self, db, 'TestItems', 'itemId', 'item')
Esempio n. 7
0
 def __init__(self, db):
     if 'TestItems' not in db.tables:
         idtable.createIdTable(db, 'TestItems', 'itemId', 'item')
     idtable.CachedIdTable.__init__(self, db, 'TestItems', 'itemId', 'item')