Custom Connection Creators #941
-
With SQLAlchemy it's possible to connect to a server using a custom connection creator like so: def getconn():
conn = connector.connect(
"project:region:instance",
"pg8000",
user="postgres-iam-user@gmail.com",
db="my_database",
enable_iam_auth=True,
)
return conn
engine = sqlalchemy.create_engine(
"postgres+pg8000://",
creator=getconn,
) This enables functionality such as connecting to a Google Cloud SQL server with Automatic IAM using the cloud-sql-python-connector library (shown above). Is it possible to configure the same in Alembic? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
the create_engine logic is editable within your env.py file that's local to your environment, after running "alembic init". Go in there and set up the create_engine logic that you need. in this case the code you would be augmenting is at: alembic/alembic/templates/generic/env.py Lines 59 to 64 in d95e15c that is the engine object. you'd replace this with your create_engine() code above. https://alembic.sqlalchemy.org/en/latest/tutorial.html#the-migration-environment |
Beta Was this translation helpful? Give feedback.
the create_engine logic is editable within your env.py file that's local to your environment, after running "alembic init". Go in there and set up the create_engine logic that you need.
in this case the code you would be augmenting is at:
alembic/alembic/templates/generic/env.py
Lines 59 to 64 in d95e15c
that is the engine object. you'd replace this with your create_engine() code above.
https://alembic.sqlalchemy.org/en/latest/tutorial.html#the-migration-environment