(self, table)
dumps a readable comparison between 2 tables
dumps a readable comparison between 2 tables
dumps a readable comparison between 2 tables
def compare_table_schema(self, table):
        '''dumps a readable comparison between 2 tables'''
        target_data = self.target.get_data(table)
        standard_data = self.standard.get_data(table)

        columns = target_data.columns
        columns2 = standard_data.columns

        diffs = []
        pattern = "%-18s%-45s%-45s"

        for column, schema in columns.items():

            if column not in columns2:
                database = "x"
            else:
                database = columns2[column]
                if schema != database:
                    database = database
                else:
                    #schema = "-"
                    #database = "-"
                    continue

            diffs.append( pattern % (column,schema,database) )


        for column2, database in columns2.items():
            if column2 not in columns:
                schema = "x"
                diffs.append( pattern % (column2,schema,database) )

        extras = []
        new_mods = []

        # print constraints
        target_constraints = target_data.constraints
        standard_constraints = standard_data.constraints

        if target_constraints != standard_constraints:
            # go through the standard constraints and print the ones
            # that are not in the target
            for standard_constraint in standard_constraints:
                if standard_constraint not in target_constraints:
                    new_mods.append(standard_constraint)

            for target_constraint in target_constraints:
                if target_constraint not in standard_constraints:
                    extras.append(target_constraint)

        # print indexes
        target_indexes = target_data.indexes
        standard_indexes = standard_data.indexes

        if target_indexes != standard_indexes:
            for standard_index in standard_indexes:
                if standard_index not in target_indexes:
                    new_mods.append(standard_index)

            for target_index in target_indexes:
                if target_index not in standard_indexes:
                    extras.append(target_index)


        # print everything out
        if not diffs and not extras and not new_mods:
            return
        print
        print
        print("Table: ", table)
        print("-"*20)

        if diffs:
            print(pattern % ("column","target schema","standard schema"))
            print("-"*110)

            for diff in diffs:
                print(diff)

            print("-"*110)


        for new in new_mods:
            print(new)
        # print all of the extras
        if extras:
            print("Not in standard:")
            for extra in extras:
                print("\t", extra)
def compare_table_schema ( self , table ) : target_data = self . target . get_data ( table ) standard_data = self . standard . get_data ( table ) columns = target_data . columns columns2 = standard_data . columns diffs = [ ] pattern = "%-18s%-45s%-45s" for column , schema in columns . items ( ) : if column not in columns2 : database = "x" else : database = columns2 [ column ] if schema != database : database = database else : #schema = "-" #database = "-" continue diffs . append ( pattern % ( column , schema , database ) ) for column2 , database in columns2 . items ( ) : if column2 not in columns : schema = "x" diffs . append ( pattern % ( column2 , schema , database ) ) extras = [ ] new_mods = [ ] # print constraints target_constraints = target_data . constraints standard_constraints = standard_data . constraints if target_constraints != standard_constraints : # go through the standard constraints and print the ones # that are not in the target for standard_constraint in standard_constraints : if standard_constraint not in target_constraints : new_mods . append ( standard_constraint ) for target_constraint in target_constraints : if target_constraint not in standard_constraints : extras . append ( target_constraint ) # print indexes target_indexes = target_data . indexes standard_indexes = standard_data . indexes if target_indexes != standard_indexes : for standard_index in standard_indexes : if standard_index not in target_indexes : new_mods . append ( standard_index ) for target_index in target_indexes : if target_index not in standard_indexes : extras . append ( target_index ) # print everything out if not diffs and not extras and not new_mods : return print print print ( "Table: " , table ) print ( "-" * 20 ) if diffs : print ( pattern % ( "column" , "target schema" , "standard schema" ) ) print ( "-" * 110 ) for diff in diffs : print ( diff ) print ( "-" * 110 ) for new in new_mods : print ( new ) # print all of the extras if extras : print ( "Not in standard:" ) for extra in extras : print ( "\t" , extra )