Пример #1
0
def sync_created_tables(from_tables,
                        to_tables,
                        sync_auto_inc=False,
                        sync_comments=False,
                        tables=[]):
    """Generate the SQL statements needed to CREATE Tables in the target
       schema (patch), and remove them (revert)

    Args:
        from_tables: A OrderedDict of SchemaObject.TableSchema Instances.
        to_tables: A OrderedDict of SchemaObject.TableSchema Instances.
        sync_auto_inc: Bool (default=False), sync auto increment for each table?
        sync_comments: Bool (default=False), sync the comment field for the table?

    Yields:
        A tuple (patch, revert) containing the next SQL statements
    """
    for t in from_tables:
        if len(tables) == 0 or len(tables) > 0 and tables.__contains__(t):
            if t not in to_tables:
                p, r = from_tables[t].create(), from_tables[t].drop()
                if not sync_auto_inc:
                    p = REGEX_TABLE_AUTO_INC.sub('', p)
                    r = REGEX_TABLE_AUTO_INC.sub('', r)
                if not sync_comments:
                    p = REGEX_TABLE_COMMENT.sub('', p)
                    r = REGEX_TABLE_COMMENT.sub('', r)

                yield p, r
Пример #2
0
def sync_dropped_tables(from_tables, to_tables,
                        sync_auto_inc=False, sync_comments=False):
    """Generate the SQL statements needed to DROP Tables in the target
       schema (patch), and restore them to their previous definition (revert)

    Args:
        from_tables: A OrderedDict of SchemaObject.TableSchema Instances.
        to_tables: A OrderedDict of SchemaObject.TableSchema Instances.
        sync_auto_inc: Bool (default=False), sync auto increment for each table?
        sync_comments: Bool (default=False), sync the comment field for the table?

    Yields:
        A tuple (patch, revert) containing the next SQL statements
    """
    for t in to_tables:
        if t not in from_tables:
            p, r = to_tables[t].drop(), to_tables[t].create()
            if not sync_auto_inc:
                p = REGEX_TABLE_AUTO_INC.sub('', p)
                r = REGEX_TABLE_AUTO_INC.sub('', r)
            if not sync_comments:
                p = REGEX_TABLE_COMMENT.sub('', p)
                r = REGEX_TABLE_COMMENT.sub('', r)

            yield p, r
Пример #3
0
def sync_dropped_tables(from_tables, to_tables,
                        sync_auto_inc=False, sync_comments=False):
    """Generate the SQL statements needed to DROP Tables in the target
       schema (patch), and restore them to their previous definition (revert)

    Args:
        from_tables: A OrderedDict of SchemaObject.TableSchema Instances.
        to_tables: A OrderedDict of SchemaObject.TableSchema Instances.
        sync_auto_inc: Bool (default=False), sync auto increment for each table?
        sync_comments: Bool (default=False), sync the comment field for the table?

    Yields:
        A tuple (patch, revert) containing the next SQL statements
    """
    for t in to_tables:
        if t not in from_tables:
            p, r = to_tables[t].drop(), to_tables[t].create()
            if not sync_auto_inc:
                p = REGEX_TABLE_AUTO_INC.sub('', p)
                r = REGEX_TABLE_AUTO_INC.sub('', r)
            if not sync_comments:
                p = REGEX_TABLE_COMMENT.sub('', p)
                r = REGEX_TABLE_COMMENT.sub('', r)

            yield p, r