Last active
May 19, 2020 16:38
-
-
Save fbouliane/32b08153c71b830a44de0289411f3622 to your computer and use it in GitHub Desktop.
sqlalchemy programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from alembic.runtime.environment import EnvironmentContext | |
from alembic.script import ScriptDirectory | |
from sqlalchemy import create_engine | |
connectable = create_engine("postgresql+pg8000://some_url".format(connect_args={'ssl_context': True}) | |
alembic_script = ScriptDirectory.from_config(alembic_cfg) | |
alembic_env = EnvironmentContext(alembic_cfg, alembic_script) | |
def upgrade_db_to_script_head(revision, context): | |
return alembic_script._upgrade_revs(alembic_script.get_heads(), revision) | |
with connectable.connect() as conn: | |
alembic_env.configure(connection=conn, target_metadata=None, fn=upgrade_db_to_script_head) | |
with alembic_env.begin_transaction(): | |
alembic_env.run_migrations() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment