本文介绍了在Google App Engine上运行Alembic迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用SQLAlchemy(Flask-SQLAlchemy)和Alembic(Flask-Migrate)的Flask应用程序。该应用在Google App Engine上运行。我想使用Google Cloud SQL。在我的机器上运行 python manage.py db upgrade
来运行我的本地数据库迁移。由于GAE不允许运行任何shell命令,我如何在其上运行迁移?
解决方案
SQLALCHEMY_DATABASE_URI ='mysql:// user:pw @ ip:3306 / DBNAME'
I have a Flask app that uses SQLAlchemy (Flask-SQLAlchemy) and Alembic (Flask-Migrate). The app runs on Google App Engine. I want to use Google Cloud SQL.
On my machine, I run python manage.py db upgrade
to run my migrations against my local database. Since GAE does not allow arbitrary shell commands to be run, how do I run the migrations on it?
解决方案
- Whitelist your local machine's IP: https://console.cloud.google.com/sql/instances/INSTANCENAME/access-control/authorization?project=PROJECTNAME
- Create an user: https://console.cloud.google.com/sql/instances/INSTANCENAME/access-control/users?project=PROJECTNAME
- Assign an external IP address to the instance: https://console.cloud.google.com/sql/instances/INSTANCENAME/access-control/ip?project=PROJECTNAME
- Use the following SQLAlchemy connection URI:
SQLALCHEMY_DATABASE_URI = 'mysql://user:pw@ip:3306/DBNAME'
- Remember to release the IP later as you are charged for every hour it's not used
这篇关于在Google App Engine上运行Alembic迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!