1

I have a flask app connected to a local postgres db with SQlAlchemy for dev purposes. I also have a live version of the app running on Google App Engine which is connected to a postgres db on CloudSQL

I am trying to use flask-migrate (which builds upon alembic) to manage database migrations. I can run the migrations fine locally but I am unsure how to manage the migrations for the deployed version?

this answer has a couple of useful answers. One suggesting getting an IP address and being able to connect directly but I don't know where I would use that URI for migrations?

The other answer suggests running the code as an endpoint in the app itself.

Any pointers would be greatly appreciated

Charlie Morton
  • 737
  • 1
  • 7
  • 17
  • in this link you can find information about how to configure the URI on sqlalchemy https://docs.sqlalchemy.org/en/13/core/engines.html https://hackersandslackers.com/flask-sqlalchemy-database-models/ – Jan Hernandez Mar 19 '20 at 21:23
  • @JorgeHDZ thanks, I have the sqlalchemy URI functioning fine on localhost dev and prod. But I don't know how to run migrations on prod – Charlie Morton Mar 19 '20 at 21:25
  • you can perform the migrations using a local machine in order to prepare the database for the app engine service – Jan Hernandez Mar 19 '20 at 21:26
  • How should I perform migrations of the prod db on my local machine? – Charlie Morton Mar 19 '20 at 21:31
  • try to start the migrations like usual following the recommendations on the answer https://stackoverflow.com/a/36731280/11529321 pointing your database configurations to the cloud – Jan Hernandez Mar 19 '20 at 21:43
  • The answer you pointed suggests two different ways to do this. Did you have any issue implementing those? They both seem decent solutions in my opinion. – Miguel Grinberg Mar 20 '20 at 11:47
  • @Miguel the first answer tells me how to access cloud SQL with an IP and form a URI (which I already have) it doesn't tell me how to use that on my local machine. The second answer I couldn't get to work as it couldn't find the migrations directory – Charlie Morton Mar 20 '20 at 12:02
  • The first answer indicates that you set the URI to the remote database in your local machine, then run the the upgrade on your local machine. Regarding the 2nd answer, what do you mean you couldn't find the migrations directory? You have created a migrations repository, right? And you added it to your project as additional source files? If you did, then when you install the application on GCE you should have the migrations folder installed. – Miguel Grinberg Mar 20 '20 at 12:17
  • Does this answer your question? [Run Alembic migrations on Google App Engine](https://stackoverflow.com/questions/35391120/run-alembic-migrations-on-google-app-engine) – Jan Hernandez Mar 23 '20 at 14:18
  • I currently have my flask app set to use environment variables so that on my local machine the URI references my local postgres db and on prod (GAE) it references the live db on Cloud SQL. Where should I be changing the URI? The other part: I get an error 'Error: Path doesn't exist: 'migrations'. Please use the 'init' command to create a new scripts folder.' despite having run init andmigrations folder existing. If I hard code in the directory it functions and it returns 'migrated' but doesn't actually do anything to the db – Charlie Morton Mar 23 '20 at 14:48
  • @JorgeHDZ that is the answer I reference in my question, but I can't quite get it to function. Not sure what I'm doing wrong – Charlie Morton Mar 23 '20 at 14:52
  • @CharlieMorton did you ever solve this? – mrp Nov 04 '21 at 13:17

0 Answers0