Skip to content

Use alembic with sqlalchemy-aurora-data-api #41

Open

Description

@tomeszmh

Hey!

Is it possible to use alembic migration with this tool? I have an Aurora serverless cluster with generated secret, but serverless clusters are not public. It would be a huge step to migrate my db using alembic and data api.

Thanks, Tamas

Activity

  1. mikeluby commented on Jul 3, 2022

    @mikeluby

    Hey @tomeszmh - I was able to get alembic working, below are the steps I followed.

    Currently I manage the revisions/migrations from my local machine. This assumes your machine is configured with the proper aws credentials. My goal is to get this into an automated CI/CD pipeline but haven't had an opportunity to tackle that yet.

    1. Install & initialize alembic
    pip install alembic
    alembic init alembic
    
    1. Update alembic.ini and set sqlalchemy.url to the correct connection string (e.g. sqlalchemy.url = postgresql+auroradataapi://:@/DATABASE)
    2. env.py, update run_migrations_online to set connectable with create_engine instead of engine_from_config
    def run_migrations_online() -> None:
        ...
        connectable = create_engine(f"postgresql+auroradataapi://:@/DATABASE", echo=True,
                                    connect_args=dict(aurora_cluster_arn=os.environ.get("AURORA_CLUSTER_ARN"), secret_arn=os.environ.get("SECRET_ARN")))
        ...
    
    1. When running revision or upgrade I pass environment variables of the aurora_cluster_arn and secret_arn
    AURORA_CLUSTER_ARN=XXX SECRET_ARN=XXX .env/bin/alembic revision -m "First commit" --autogenerate
    AURORA_CLUSTER_ARN=XXX SECRET_ARN=XXX .env/bin/alembic upgrade head
    
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions