Ejemplo n.º 1
0
def validate(dbSchema, ormSchema):
    """
    Check DB versions against ORM versions, returning mismatches.
    If there are version mismatches, check DB schemas against cache,
    returning mismatches there.
    """

    mismatches = validator.findMismatches(dbSchema, ormSchema)

    if mismatches:
        raise errors.ORMValidationError(
            map(errors.ORMValidationMismatch, mismatches))

    schemaMismatches = list(validator.findSchemaMismatches(dbSchema))
    
    if schemaMismatches:
        raise errors.SchemaValidationError(
            map(errors.SchemaValidationMismatch, schemaMismatches))
Ejemplo n.º 2
0
def validate(dbSchema, ormSchema):
    """
    Check DB versions against ORM versions, returning mismatches.
    If there are version mismatches, check DB schemas against cache,
    returning mismatches there.
    """

    mismatches = validator.findMismatches(dbSchema, ormSchema)

    if mismatches:
        raise errors.ORMValidationError(
            map(errors.ORMValidationMismatch, mismatches))

    schemaMismatches = list(validator.findSchemaMismatches(dbSchema))

    if schemaMismatches:
        raise errors.SchemaValidationError(
            map(errors.SchemaValidationMismatch, schemaMismatches))
Ejemplo n.º 3
0
def upgrade(dbSchema, ormSchema):
    """
    Attempt to find upgrade paths for all out-of-sync tables,
     and run them.
    """    

    paths = [(tableName, upgraders.findUpgradePath(tableName, fromVersion, toVersion))
             for (tableName, fromVersion, toVersion)
             in validator.findMismatches(dbSchema, ormSchema)]

    if not paths:
        return

    for tableName, currentVersion in dbSchema.getTableVersions():
        paths.append((tableName, upgraders.pathToCurrent(tableName, currentVersion)))

    stepGraph = upgraders.UpgradeStepGraph()

    for tableName, path in paths:
        path.addToGraph(stepGraph)

    stepGraph.calculateEdges()

    dbSchema.begin()

    modifiedTables = []

    for upgrader in stepGraph.topologicalSort():
        upgrader.run(dbSchema)
        if upgrader.upgrader is not None:
            modifiedTables.append((upgrader.tableName, upgrader.toVersion))

    dbSchema.commit()

    for tableName, version in modifiedTables:
        dbSchema.setSchema(tableName, version)

    dbSchema.commit()

    return dbSchema.flushLog()
Ejemplo n.º 4
0
def upgrade(dbSchema, ormSchema):
    """
    Attempt to find upgrade paths for all out-of-sync tables,
     and run them.
    """

    paths = [(tableName,
              upgraders.findUpgradePath(tableName, fromVersion, toVersion))
             for (tableName, fromVersion,
                  toVersion) in validator.findMismatches(dbSchema, ormSchema)]

    if not paths:
        return

    for tableName, currentVersion in dbSchema.getTableVersions():
        paths.append(
            (tableName, upgraders.pathToCurrent(tableName, currentVersion)))

    stepGraph = upgraders.UpgradeStepGraph()

    for tableName, path in paths:
        path.addToGraph(stepGraph)

    stepGraph.calculateEdges()

    dbSchema.begin()

    modifiedTables = []

    for upgrader in stepGraph.topologicalSort():
        upgrader.run(dbSchema)
        if upgrader.upgrader is not None:
            modifiedTables.append((upgrader.tableName, upgrader.toVersion))

    for tableName, version in modifiedTables:
        dbSchema.setSchema(tableName, version)

    dbSchema.commit()

    return dbSchema.flushLog()