Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Database migrations with Alembic
Lecture: Concept: Getting started
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Let's take a moment and review the core concepts of using Alembic and I think the place to get started is getting started.
0:07
The way we're going to get started is we have to make sure we have Alembic. We simply get that by pip install alembic
0:13
make sure this is the virtual environment that you want it to be in, okay? So that works great; let's go install
0:20
then we need to initialize the project structure just once, so we say, alembic init alembic first one is a command, last one is the folder
0:28
and then it's going to go through and create all the structure and says don't forget you have to set your connection string
0:32
in Alembic.ini or this isn't going to work. Afterwards, you have a project that looks a little bit different;
0:39
you've got an Alembic folder and here we have versions. They're going to be initially empty but as you apply
0:45
as you create revisions they're going to be stored in here and chained together as we saw. Some scripts that are used to generate the SQL
0:55
and run Alembic so environment does things like tells Alembic what your sqlalchemy models are the script.py.mako is actually going to generate
1:06
the SQL structure that's going to be sent to the database things like that. And finally, we have our Alembic.ini that configures how Alembic runs.
1:15
In order to use Alembic, you have to configure it so there's a whole bunch of settings in Alembic.ini but the one that you probably care about first
1:23
is sqlalchemy.url and then you just set it to whatever your connection string is. We're using SQLite so it's sqlite:/// the name of the file
1:32
and we're able to use a relative path I think this may only work if you run Alembic from the right location
1:38
so do that. Turns out that's pretty easy from PyCharm cuz the terminal always opens in the right place.