How to use the migra.Migration function in migra

To help you get started, we’ve selected a few migra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github australianunions / results / results / migration.py View on Github external
def sync_db_structure_to_target_db(
    db_url, target_db_url, confirm=True, create_extensions_only=False, **kwargs
):
    log.info(f"syncing: {db_url} to {target_db_url}")

    with S(db_url, poolclass=NullPool) as s_current, S(
        target_db_url, poolclass=NullPool
    ) as s_target:
        m = Migration(s_current, s_target, **kwargs)
        m.set_safety(False)
        if create_extensions_only:
            log.info("Syncing extension creation only...")
            m.add_extension_changes(creates=True, drops=False)
        else:
            m.add_all_changes()

        if m.statements:
            if confirm:  # pragma: no cover
                print("THE FOLLOWING CHANGES ARE PENDING:", end="\n\n")
                print(m.sql)
                print()
            if not confirm or prompt("Apply these changes?"):
                log.info("Applying...")
                m.apply()
                log.info("Applied.")
github australianunions / results / results / migration.py View on Github external
def creation_statements(db_url, **kwargs):
    with S(db_url, poolclass=NullPool) as s:
        m = Migration(None, s, **kwargs)
        m.set_safety(False)
        m.add_all_changes()
        return m.sql
github australianunions / results / results / migration.py View on Github external
def drop_statements(db_url, **kwargs):
    with S(db_url, poolclass=NullPool) as s:
        m = Migration(s, None, **kwargs)
        m.set_safety(False)
        m.add_all_changes()
        return m.sql
github australianunions / results / results / migration.py View on Github external
def db_differences(db_url_a, db_url_b, **kwargs):
    with S(db_url_a, poolclass=NullPool) as a, S(db_url_b, poolclass=NullPool) as b:
        m = Migration(a, b, **kwargs)
        m.set_safety(False)
        m.add_all_changes()
        return m.sql

migra

Like `diff` but for PostgreSQL schemas

Unlicense
Latest version published 2 years ago

Package Health Score

55 / 100
Full package analysis

Popular migra functions