#100DaysOfWeb in Python Transcripts
Chapter: Days 61-64: Database migrations
Lecture: Where is the DB version stored?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw the we can go to the terminal and we can ask Alembic for the current. And when you run that it says, "this is the head."
0:08 We could actually run a downgrade on this to get to another one then this little head part would be gone but this is the latest.
0:14 So how does it know what version the database has? How does it know whether that's the head or not? All these things are interesting questions.
0:21 Well, the way it knows which is the head is it parses all the files here and figures out how to order them based on their dependencies
0:28 so it knows what one is the last one there. But how does it know what number it's on? So we're going to look at that real quick.
0:34 So if we go over to our database here and we go to our DB file, and we open this up Oh, we already have it open. So we go over here to the schemas.
0:43 Make sure you refresh this. And now we have a new column called alembic_version and it has just the version number. It's super, super simple.
0:50 So we can open this in a console and say select * from alembic_version. We run this, we get a very impressive one row, one column in this table
1:00 but it is not surprising that it is this 99977 which we saw right there. It's that version. So there's simply a table in our database
1:11 that has a single row in a single column that is a varchar32 which is this. So we just, that is the stored version of the database
1:20 and then these are all the possible versions and Alembic syncs those too and figures out what changes it should apply what changes already apply.
1:27 It's important you don't make changes to the database directly, but that you always use Alembic because it doesn't completely analyze the database
1:36 I don't think. I think it just looks at a number and go okay we're going to apply those changes that are tracked in Alembic.
1:42 So that's where this is stored and how you can find it.

Talk Python's Mastodon Michael Kennedy's Mastodon