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

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now as we get started in our Alembic chapter we've moved to another section of our source control.
0:05 So, let's just talk about that real quick and sync up. So now we're over in Chapter 11, migrations and we're going to be working on final
0:14 and we're leaving you this copy of starter. Right now they're the same as always but in the end they're going to be different.
0:20 And the way we got that was just taking the final code from the SQLAlchemy chapter. So, that's where we are.
0:26 And I've already loaded this up in PyCharm. Here is our migrations project that we're going to work on.
0:32 And if we run it, everything should be running just fine. Here you can see we have our new data driven version that we got from SQLAlchemy.
0:40 Everything's working great. Now in order to use Alembic, we have to first install it. So, let's go over here and put it in
0:48 as a development requirement. So, this is actually our first one that we're going to have. The idea is we take all the run time dependencies
0:56 plus one more so we have Alembic. Here is another one so that's good. And then we're just going to go to our terminal
1:03 make sure the virtual environment is active. And we saypip install -r requirements-dev.txt Uou can see we're downloading everything
1:11 we need to run Alembic. Now, the next thing we need to do is we need to run an Alembic command to create the initial structure
1:21 kind of a scaffolding type thing. So it's going to generate a configuration file some scripts that we can run some scripts that will be generated
1:29 in particular for our application and so on. So, what we want to do is make sure that we're in the folder that contains our web app.
1:38 So, we're basically in the top level folder next to this one. And the way we do this is we're going to run alembic
1:44 and we're going to tell it to initialize the project. We do this once and only once then we store what is generated into source control.
1:50 And we're going to set a folder here and the convention is, this is also alembic. So we say alembic init alembic.
1:57 We run that, a bunch of stuff happens. It says, hey, before you can do anything you're going to need to edit this ini file.
2:04 We will do that in a moment. Let's just look at what happened over here in the left. So now we got an alembic folder and we got an alembic.ini.
2:12 And within the alembic folder, we've got a script some other details and these versions. As we make revisions to our database
2:20 they're going to be stored as scripts as Python files in there. So, that's how it's going to work. We're going to edit this thing to get started
2:27 and then also we actually need to work with this if we want to take full advantage of what we can do with Alembic.


Talk Python's Mastodon Michael Kennedy's Mastodon