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