Building data-driven web apps with Pyramid and SQLAlchemy Transcripts
Chapter: Database migrations with Alembic
Lecture: Getting started with Alembic
0:00 Before we actually get started here
0:01 I want to just do a quick sync up on where we are
0:04 on the GitHub Repo and the source code
0:06 that you get for this course.
0:08 So over here in the GitHub Repo, we are now moving on
0:11 to Chapter 11, Migrations.
0:12 We'll be working in Final.
0:14 Start of course, is where we're starting
0:16 final, whatever we're going to do in the end
0:18 that's what it's going to turn out to be.
0:22 Now in order to use Alembic we need it installed.
0:26 We need to make sure that we have the right
0:27 virtual directory, which I've already created
0:30 for this version of our website.
0:33 We need to make sure that it's active.
0:34 So I'm going to say . venv/bin/activate, remember
0:39 forget the dot, scripts not bin, on Windows.
0:42 Alright, so now looks like we're using
0:46 the one in PyPI_migrations. Great.
0:49 In order to use Alembic we have to, well, have it installed.
0:52 So pip install alembic.
0:57 Boom, looks like it's installed. Excellent.
1:01 Now down here you need to make sure that
1:03 you are in the folder that has your PyPI folder
1:07 and the two ini. So this right here is our web app.
1:11 We're going to put this next to our web app
1:13 not actually deployed within the sort of request space
1:17 of our web app. So we have Alembic installed.
1:20 The next thing to do is to
1:21 build some basic project structure.
1:24 And this structure is going to allow us to configure Alembic
1:27 and it will keep track of the various versions
1:29 and how to evolve from one to the other.
1:31 So the way we do that is we invoke Alembic.
1:35 We tell it to init, and we have to give it
1:37 a folder to create
1:38 and the convention is to use the same name Alembic
1:41 so you will see the Alembic folder.
1:45 Here we go, it's gone and created that
1:47 and it's done a couple of things.
1:49 It's created the folder and an Alembic.ini.
1:53 Excellent, so it says we're going to need to edit that
1:57 and that's true, we're going to need to edit that.
1:59 But now if we look over here, we'll see
2:02 an Alembic folder and we'll see an Alembic.ini
2:05 and if we tree Alembic, you can see
2:08 it just has a couple of things.
2:09 It has a read.me, it has a mako
2:13 which is a template it uses
2:14 to generate the SQL statements, actually
2:17 that it's going to run.
2:18 It has an environment, which allows us to plug in
2:21 our SQLAlchemy models
2:23 and it has a versions folder
2:25 which is going to keep track of where things are.
2:28 So as we use Alembic, we'll start to build up things there.