Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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.")
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
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
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