Building data-driven web apps with Pyramid and SQLAlchemy Transcripts
Chapter: Database migrations with Alembic
Lecture: Concept: Getting started
0:00 Let's take a moment and review
0:01 the core concepts of using Alembic
0:03 and I think the place to get started is getting started.
0:06 The way we're going to get started is we have to make sure
0:08 we have Alembic. We simply get that by pip install alembic
0:12 make sure this is the virtual environment
0:14 that you want it to be in, okay?
0:16 So that works great; let's go install
0:19 then we need to initialize the project structure
0:21 just once, so we say, alembic init alembic
0:24 first one is a command, last one is the folder
0:27 and then it's going to go through and create all the structure
0:29 and says don't forget you have to set your connection string
0:31 in Alembic.ini or this isn't going to work.
0:35 Afterwards, you have a project that looks a little bit different;
0:38 you've got an Alembic folder and here we have versions.
0:42 They're going to be initially empty but as you apply
0:44 as you create revisions they're going to be stored in here
0:47 and chained together as we saw.
0:49 Some scripts that are used to generate the SQL
0:54 and run Alembic so environment does things like tells Alembic
0:59 what your sqlalchemy models are
1:01 the script.py.mako is actually going to generate
1:05 the SQL structure that's going to be sent to the database
1:08 things like that. And finally, we have our Alembic.ini
1:12 that configures how Alembic runs.
1:14 In order to use Alembic, you have to configure it
1:17 so there's a whole bunch of settings in Alembic.ini
1:20 but the one that you probably care about first
1:22 is sqlalchemy.url and then you just set it
1:25 to whatever your connection string is.
1:27 We're using SQLite so it's sqlite:/// the name of the file
1:31 and we're able to use a relative path
1:33 I think this may only work
1:34 if you run Alembic from the right location
1:37 so do that. Turns out that's pretty easy from PyCharm
1:41 cuz the terminal always opens in the right place.