#100DaysOfWeb in Python Transcripts
Chapter: Days 61-64: Database migrations
Lecture: Concept: Review configuring Alembic
0:00 Let's review getting started. You can follow along on Mike Bayer's tutorial which you can see the link at the bottom.
0:06 But the short version is we're going to get started by installing Alembic. So here, we're just typing pip install alembic.
0:12 In our example, we actually put it into the setup requirements. That didn't go so well so we put it into our requirements file.
0:19 So, we'd run this, it's going to install Alembic and then we're going to run the init command. Alembic init, and then we give it a folder.
0:25 The convention is also to call the folder it's going to create alembic, does a bunch of stuff. See it creates these alembic folders
0:32 it creates the versions and so on and then finally says, hey you need to edit the alembic.ini before you get going. Alright, we'll come back to that
0:39 but let's first talk about the project structure. So, as we work with it, you'll see it starts to develop a structure that looks like this.
0:46 So we have our alembic folder that's the folder that we specified in the init command and it has versions.
0:52 These are, the change that take our base model our base schema, and then migrate through the various changes over time.
1:00 Each one of these changes, or levels is recorded in the database, as we'll see. So, Alembic can look at your database
1:06 look at the various changes, and it says well I'm starting from here and I want to get to the latest. What path do I have to take?
1:12 What set of changes do I apply to do that? That's what's in these files, and we'll see how to work with them in a minute.
1:17 We have some more setup we can do here. We're going to mess with this env.py in just a second and we also have our alembic.ini.
1:25 That's where we specify the configuration settings. Most importantly, how do we talk to the database? What's the connection string?
1:31 Speaking of which, in that alembic.ini we're going to say sqlalchemy.url is a relative path in this case maybe a server name
1:39 in more production type of cases, over to our database. So we said it's in the bill tracker directory db/buildtracker.sqlite, and of course
1:49 we use the sqlite schema; this is a sqlalchemy connection string not a pure sqlite connection string. So we specify that there so we let Alembic know
1:57 how to connect to our database and of course if you have authentication that has to go here, all that kind of stuff.