xpgdiff.py
def print_table_migration_ddl(source_table, target_table):
    """
    Prints DDL to migrate a table in one schema to the structure in
    another schema, including columns, constraints, indexes, triggers
    and permissions.

    N.B. The migration does not enforce identical column ordering.

    :param source_table: The source table.
    :param target_table: The target table.
    """
    next_source_column = next_or_none(sorted(source_table.columns, key=lambda c: c.name))
    next_target_column = next_or_none(sorted(target_table.columns, key=lambda c: c.name))

    source_column = next_source_column()
    target_column = next_target_column()

    while source_column or target_column:
        if not target_column:
            print(source_column.dropstr())
            source_column = next_source_column()
            continue

        if not source_column:
            print(target_column.addstr())
            target_column = next_target_column()
            continue

        if source_column.name < target_column.name:
            print(source_column.dropstr())
            source_column = next_source_column()
            continue

        if source_column.name > target_column.name:
            print(target_column.addstr())
            target_column = next_target_column()
            continue

        print_column_migration_ddl(source_table, source_column, target_column)
        source_column = next_source_column()
        target_column = next_target_column()

    if source_table.primary_key is None and target_table.primary_key is not None:
        print(f'{str(target_table.primary_key)};')
    elif source_table.primary_key is not None and target_table.primary_key is None:
        print(source_table.primary_key.dropstr())
    elif source_table.primary_key is not None and target_table.primary_key is not None:
        if source_table.primary_key != target_table.primary_key:
            print(source_table.primary_key.dropstr())
            print(target_table.primary_key.addstr())

    print_dropadd_migration_ddl(source_table.unique_keys, target_table.unique_keys)
    print_dropadd_migration_ddl(source_table.checks, target_table.checks)
    print_dropadd_migration_ddl(source_table.get_non_constraint_indexes(), target_table.get_non_constraint_indexes())
    print_dropadd_migration_ddl(source_table.get_non_constraint_triggers(), target_table.get_non_constraint_triggers())

    print_grants_migration_ddl(source_table, target_table)
    if (source_table.owner != target_table.owner):
        print(target_table.ownerstr())

    Prints DDL to migrate a table in one schema to the structure in
    another schema, including columns, constraints, indexes, triggers
    and permissions.

    N.B. The migration does not enforce identical column ordering.

    :param source_table: The source table.
    :param target_table: The target table.
    
Prints DDL to migrate a table in one schema to the structure in
another schema, including columns, constraints, indexes, triggers
and permissions.


Prints DDL to migrate a table in one schema to the structure in another schema including columns constraints indexes triggers and permissions .
def print_table_migration_ddl(source_table, target_table):
    next_source_column = next_or_none(sorted(source_table.columns, key=lambda c: c.name))
    next_target_column = next_or_none(sorted(target_table.columns, key=lambda c: c.name))
    source_column = next_source_column()
    target_column = next_target_column()
    while source_column or target_column:
        if not target_column:
            print(source_column.dropstr())
            source_column = next_source_column()
            continue
        if not source_column:
            print(target_column.addstr())
            target_column = next_target_column()
            continue
        if source_column.name < target_column.name:
            print(source_column.dropstr())
            source_column = next_source_column()
            continue
        if source_column.name > target_column.name:
            print(target_column.addstr())
            target_column = next_target_column()
            continue
        print_column_migration_ddl(source_table, source_column, target_column)
        source_column = next_source_column()
        target_column = next_target_column()
    if source_table.primary_key is None and target_table.primary_key is not None:
        print(f'{str(target_table.primary_key)};')
    elif source_table.primary_key is not None and target_table.primary_key is None:
        print(source_table.primary_key.dropstr())
    elif source_table.primary_key is not None and target_table.primary_key is not None:
        if source_table.primary_key != target_table.primary_key:
            print(source_table.primary_key.dropstr())
            print(target_table.primary_key.addstr())
    print_dropadd_migration_ddl(source_table.unique_keys, target_table.unique_keys)
    print_dropadd_migration_ddl(source_table.checks, target_table.checks)
    print_dropadd_migration_ddl(source_table.get_non_constraint_indexes(), target_table.get_non_constraint_indexes())
    print_dropadd_migration_ddl(source_table.get_non_constraint_triggers(), target_table.get_non_constraint_triggers())
    print_grants_migration_ddl(source_table, target_table)
    if (source_table.owner != target_table.owner):
        print(target_table.ownerstr())
def print_table_migration_ddl ( source_table , target_table ) : next_source_column = next_or_none ( sorted ( source_table . columns , key = lambda c : c . name ) ) next_target_column = next_or_none ( sorted ( target_table . columns , key = lambda c : c . name ) ) source_column = next_source_column ( ) target_column = next_target_column ( ) while source_column or target_column : if not target_column : print ( source_column . dropstr ( ) ) source_column = next_source_column ( ) continue if not source_column : print ( target_column . addstr ( ) ) target_column = next_target_column ( ) continue if source_column . name < target_column . name : print ( source_column . dropstr ( ) ) source_column = next_source_column ( ) continue if source_column . name > target_column . name : print ( target_column . addstr ( ) ) target_column = next_target_column ( ) continue print_column_migration_ddl ( source_table , source_column , target_column ) source_column = next_source_column ( ) target_column = next_target_column ( ) if source_table . primary_key is None and target_table . primary_key is not None : print ( f'{str(target_table.primary_key)};' ) elif source_table . primary_key is not None and target_table . primary_key is None : print ( source_table . primary_key . dropstr ( ) ) elif source_table . primary_key is not None and target_table . primary_key is not None : if source_table . primary_key != target_table . primary_key : print ( source_table . primary_key . dropstr ( ) ) print ( target_table . primary_key . addstr ( ) ) print_dropadd_migration_ddl ( source_table . unique_keys , target_table . unique_keys ) print_dropadd_migration_ddl ( source_table . checks , target_table . checks ) print_dropadd_migration_ddl ( source_table . get_non_constraint_indexes ( ) , target_table . get_non_constraint_indexes ( ) ) print_dropadd_migration_ddl ( source_table . get_non_constraint_triggers ( ) , target_table . get_non_constraint_triggers ( ) ) print_grants_migration_ddl ( source_table , target_table ) if ( source_table . owner != target_table . owner ) : print ( target_table . ownerstr ( ) )
Prints DDL to migrate a table in one schema to the structure in
another schema, including columns, constraints, indexes, triggers
and permissions.
Prints DDL to migrate a table in one schema to the structure in another schema including columns constraints indexes triggers and permissions .
"""
    Prints DDL to migrate a table in one schema to the structure in
    another schema, including columns, constraints, indexes, triggers
    and permissions.

    N.B. The migration does not enforce identical column ordering.

    :param source_table: The source table.
    :param target_table: The target table.
    """
source_table
The source table.
The source table .
target_table
The target table.
The target table .