Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Database migrations with Alembic
Lecture: Concept: Getting started

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's take a moment and review the core concepts of using Alembic. And I think the place to get started is getting started.
0:07 The way we're going to get started is we have to make sure we have Alembic. We simply get that by pip installing Alembic.
0:13 Make sure this is the virtual environment that you want it to be in, okay? So that works great, let's go into install.
0:19 Then we need to initialize the project structure just once. So we say alembic init alembic. First one is the command, last one is the folder.
0:27 And then it's going to go through and create all the structure. And says, don't forget you have to set your connection string
0:32 in alembic.ini or this isn't going to work. Afterwards, you have a project that looks a little bit different.
0:39 You've got an alembic folder, and here we have versions. It's going to be initially empty but as you apply as you create revisions
0:47 they're going to be stored in here and chained together as we saw. Some scripts that are used to generate the SQL and run Alembic.
0:56 So environment does things like tells Alembic what your SQLalchemy models are the scripts stop.py and .mako is actually
1:04 going to generate the SQL structure that's going to be sent to the database. Things like that. Then finally we have our alembic.ini
1:12 that configures how Alembic runs. In order to use Alembic you have to configure it. So there's a whole bunch of settings
1:20 in Alembic.ini but the one that you probably care about first is sqlalchemy.url and then you just set it to whatever your connection string is.
1:28 We're using SQLite so it's sqlite/// the name of the file and were able to use a relative path. I think this may only work if you run
1:36 Alembic from the right location, so do that. Turns out that's pretty easy from PyCharm cause the terminal always opens in the right place.


Talk Python's Mastodon Michael Kennedy's Mastodon