4 ms·
Flask by Example – Part 2 – Postgres, SQLAlchemy, and Alembic
- Killah911 13y agoCool, but can someone please add some context to this? Where's part one, what's the goal of this "Flask by Example" tutorial. I've recently started getting into Python and love Flask so far (spares newbies from having to buy into bullshit philosophies which are irrelevant to me). Would love to understand better what this project is trying to accomplish
- mjhea0 13y ago1. You can find the link to part 1 in the beginning of the tutorial - http://www.realpython.com/blog/python/flask-by-example-part-1-project-setup/ http://www.realpython.com/blog/python/flask-by-example-part-... 2. Context: We're going to build an app using Flask with a simple text box that you enter text into and the app processes and displays a count of how many times each word appears on the page. 3. Parts: In part one, we'll set up a local development environment and then deploy both a staging environment and a production environment on Heroku. In part two, we'll set up our PostgreSQL database along with SQLAlchemy as our ORM and Alembic to handle migrations. In part three, we'll be doing a bunch of backend processing to count the words of a web page so we’ll implement a request queue that will do the actual processing of the words. (coming soon!) Does that answer your questions? Best!
- noise 13y agoThat technique used for migrations will fail with a real production app where you want to avoid downtime. The process outlined is: 1. deploy new code to prod 2. run migration on prod via a one-off dyno instance However, in step 1 you are pushing code that relies on new tables/fields that don't yet exist, causing errors and likely downtime for the app. To avoid this, you can instead have Alembic generate SQL from the migration and then apply that SQL to the prod DB directly prior to deploying the updated code.
- mjhea0 13y agoGood points. This post is actually meant for the initial setup. You're right, though: - there will be downtown, albeit not much. But down time is down time. It may be beneficial to update the post to specify the initial setup vs. migrations after the production env is setup. Or we could just add that in the next post. Thanks!
- noise 13y agoYeah, it's more of an advanced topic for commercial prod sites, but worth mentioning as trying to do the migration prior to a code push is also not going to work (no migration to be done) and could confuse those new to these tools/libs. In any case, good job on a well written set of posts.
- malkia 13y agoLol... Everytime I see Alembic, I always think of this: http://en.wikipedia.org/wiki/Alembic_(Computer_Graphics) http://en.wikipedia.org/wiki/Alembic_(Computer_Graphics)