Using different postgres user for application db request and migration #538
-
Hello there. I am currently working on a Flask application with Flask==2.2.5, Flask-SQLAlchemy==3.1.1 and Flask-Migrate==4.0.5. This app use a postgres db with two different users:
Currently, I am creating my projet like that :
With that configuration, the migration process will use the app_user. The process will fail because the user has no right to alter table. Thanks for your answer. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
First of all, it is a very bad idea to enter credentials directly in the code. You should import your database URL from an environment variable: api.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL'] And now that you have an environment variable, you can set it to different values depending on your needs. When using Flask-Migrate you can set |
Beta Was this translation helpful? Give feedback.
First of all, it is a very bad idea to enter credentials directly in the code. You should import your database URL from an environment variable:
And now that you have an environment variable, you can set it to different values depending on your needs. When using Flask-Migrate you can set
DATABASE_URL
to your admin credentials, and when using the web app you can set your regular user's URL.