Building Data-Driven Web Apps with Pyramid 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
Before we actually get started here I want to just do a quick sync up on where we are on the GitHub Repo and the source code
0:07
that you get for this course. So over here in the GitHub Repo, we are now moving on to Chapter 11, Migrations. We'll be working in Final.
0:15
Start of course, is where we're starting final, whatever we're going to do in the end that's what it's going to turn out to be.
0:23
Now in order to use Alembic we need it installed. We need to make sure that we have the right virtual directory, which I've already created
0:31
for this version of our website. We need to make sure that it's active. So I'm going to say . venv/bin/activate, remember
0:40
forget the dot, scripts not bin, on Windows. Alright, so now looks like we're using the one in PyPI_migrations. Great.
0:50
In order to use Alembic we have to, well, have it installed. So pip install alembic. Boom, looks like it's installed. Excellent.
1:02
Now down here you need to make sure that you are in the folder that has your PyPI folder and the two ini. So this right here is our web app.
1:12
We're going to put this next to our web app not actually deployed within the sort of request space of our web app. So we have Alembic installed.
1:21
The next thing to do is to build some basic project structure. And this structure is going to allow us to configure Alembic
1:28
and it will keep track of the various versions and how to evolve from one to the other. So the way we do that is we invoke Alembic.
1:36
We tell it to init, and we have to give it a folder to create and the convention is to use the same name Alembic so you will see the Alembic folder.
1:46
Here we go, it's gone and created that and it's done a couple of things. It's created the folder and an Alembic.ini.
1:54
Excellent, so it says we're going to need to edit that and that's true, we're going to need to edit that. But now if we look over here, we'll see
2:03
an Alembic folder and we'll see an Alembic.ini and if we tree Alembic, you can see it just has a couple of things. It has a read.me, it has a mako
2:14
which is a template it uses to generate the SQL statements, actually that it's going to run. It has an environment, which allows us to plug in
2:22
our SQLAlchemy models and it has a versions folder which is going to keep track of where things are.
2:29
So as we use Alembic, we'll start to build up things there.