Skip to content

how to call sync_trigger in Alembic env.py to keep the Native versioning up-to-date #236

Open

Description

@scil

I'd like an example to implement these code in alembic env.py

from sqlalchemy_continuum.dialects.postgresql import sync_trigger

sync_trigger(conn, 'article_version')

It's from Native versioning

Activity

  1. austospumanto commented on May 2, 2020

    @austospumanto

    Bump. Same issue. New triggers are not added when I migrate my schemas via Alembic.

  2. sp-schoen commented on Sep 7, 2022

    @sp-schoen

    I found a working solution. After the autogenerated alembic commands in the migration script I added the following lines in the upgrade function:

    conn = op.get_bind()
    sync_trigger(conn, 'article_version')
    

    First line just gets you to connection used by alembic. The trigger will be created, but I didn't test the whole thing. On downgrade I tried the same, but the trigger will not be removed.

  3. schanjr commented on Nov 14, 2024

    @schanjr

    DIdn't work for me. I used synchronous engine and async engine, both returned

      File "/Users/schan/Library/Caches/pypoetry/virtualenvs/leads-v2-iIKbbH54-py3.12/lib/python3.12/site-packages/sqlalchemy_continuum/dialects/postgresql.py", line 480, in sync_trigger
        autoload_with=session.connection()
                      ^^^^^^^^^^^^^^^^^^^^
    TypeError: '_ConnectionFairy' object is not callable
    
    
    

    Using below versions
    psycopg2 = "^2.9.10"
    asyncpg = "^0.29.0"
    alembic = "^1.13.2"
    sqlalchemy-continuum = "^1.4.2"

  4. luca-eiq commented on Sep 25, 2025

    @luca-eiq

    Like this

    from sqlalchemy.orm import Session
    session = Session(bind=op.get_bind())
    sync_trigger(session, 'article_version')
  5. added
    pinned
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pinned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions