#100DaysOfWeb in Python Transcripts
Chapter: Days 61-64: Database migrations
Lecture: Concept: Review configuring Alembic

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's review getting started.
0:01 You can follow along on Mike Bayer's tutorial
0:04 which you can see the link at the bottom.
0:05 But the short version is we're going to get started
0:07 by installing Alembic.
0:09 So here, we're just typing pip install alembic.
0:11 In our example, we actually put it
0:14 into the setup requirements.
0:15 That didn't go so well
0:16 so we put it into our requirements file.
0:18 So, we'd run this, it's going to install Alembic
0:19 and then we're going to run the init command.
0:22 Alembic init, and then we give it a folder.
0:24 The convention is also to call the folder
0:26 it's going to create alembic, does a bunch of stuff.
0:28 See it creates these alembic folders
0:31 it creates the versions and so on
0:33 and then finally says, hey you need to edit
0:35 the alembic.ini before you get going.
0:37 Alright, we'll come back to that
0:38 but let's first talk about the project structure.
0:41 So, as we work with it, you'll see it starts
0:43 to develop a structure that looks like this.
0:45 So we have our alembic folder
0:46 that's the folder that we specified in the init command
0:49 and it has versions.
0:51 These are, the change that take our base model
0:54 our base schema, and then migrate
0:57 through the various changes over time.
0:59 Each one of these changes, or levels
1:01 is recorded in the database, as we'll see.
1:03 So, Alembic can look at your database
1:05 look at the various changes, and it says
1:07 well I'm starting from here
1:08 and I want to get to the latest.
1:10 What path do I have to take?
1:11 What set of changes do I apply to do that?
1:14 That's what's in these files, and we'll see
1:15 how to work with them in a minute.
1:16 We have some more setup we can do here.
1:19 We're going to mess with this env.py in just a second
1:22 and we also have our alembic.ini.
1:24 That's where we specify the configuration settings.
1:26 Most importantly, how do we talk to the database?
1:29 What's the connection string?
1:30 Speaking of which, in that alembic.ini
1:32 we're going to say sqlalchemy.url is a relative path
1:36 in this case maybe a server name
1:38 in more production type of cases, over to our database.
1:42 So we said it's in the bill tracker directory
1:45 db/buildtracker.sqlite, and of course
1:48 we use the sqlite schema; this is
1:49 a sqlalchemy connection string
1:51 not a pure sqlite connection string.
1:54 So we specify that there so we let Alembic know
1:56 how to connect to our database
1:59 and of course if you have authentication
2:01 that has to go here, all that kind of stuff.