Adding a CMS to Your Flask Web App Transcripts
Chapter: Advanced markdown
Lecture: Marking pages as shared in the DB

Login or purchase this course to watch this video and the rest of the course contents.
0:00 our pages are working great from a user perspective. Over here we can click on this page and hey, we see it. Look over here.
0:09 We've got our nice getting help with Pipi I And remember, it's super super fast. So that's cool as well, however, are back in admin side of things.
0:19 Not so much. What pages are the actual content of our site on what are there to be reused? Well,
0:27 you remember this one's reused, and these are part of the site. But how do you know? You've no idea by looking at this,
0:34 that that's the intention, or even that you can't directly go up here and just type suggest picks and get well,
0:44 that's not actually supposed to be a page, is it? All right, well, that's the problem. Now we gotta approach Solving it at several levels in order to
0:53 display this different ways is a hero of the pages and here the reusable bits.
0:57 We need to actually be able to indicate whether something is shared or not shared. So we're gonna be going and changing our page in the database.
1:07 Remember, here's our page, class or story in the database trash and seek Welcome a base, All that good stuff.
1:12 Here's the direct data is. So let's just let's take a shot. Let's just try to add is shared and that's gonna be a boule and this is
1:20 gonna be a Boolean. And while we're at it, let's say default value is false. We don't set it all right.
1:27 That seems reasonable. Let's run it again and go have a look and see how the sites working it works. Great.
1:33 Wait a minute. That's not as great as I was hoping. What is the problem? Sequel. Alchemy. Operational error, which is really sequel Light Error,
1:42 saying there is no column is shared. What just happened? Well, if you haven't used sequel community forums before,
1:49 the problem is we've changed the definition of what the program thinks the database should look
1:55 like. But the database itself didn't receive that change. Remember, sequel Alchemy will go.
2:01 If we were to write a new one of these classes with a new name, it would go and create that table perfectly.
2:07 But what it will not do is once a table is created and has data in it, it's not going to go back and change it. It's not gonna look at and go.
2:15 Oh, I see that this has changed. So here's how I'm going to do. That is a totally different tool for fixing that called Olympic.
2:22 So Olympic comes from the same folks that work on sequel alchemy. It's exactly for this job. It's job is to go look at these classes,
2:32 look at the data base and then, if you change the classes, convert or migrate the database over. So these air called migrations. Now,
2:42 in order to use Olympic, you have to make sure you have it installed. Its in the developer requirements, but not the runtime requirements.
2:48 Because this is only a developer thing. Don't really need it for production. Probably maybe do. Maybe don't you can decide on how you install it,
2:57 managed if it goes into the same virtual environment or somewhere else. But anyway, I put it over here.
3:02 Once we've have installed that, which is to be all done, have been doing that all along.
3:10 We'll be able to ask questions if we're in the top level directory. So for in this folder right here, where Olympic Olympic is right there,
3:21 contained within here, So in this case, we can ask questions like First, which a limbic or on Windows? You would say, Where? Olympic?
3:29 All right, well, that's good. It's the one out of our virtual environment. So chances, air looking good, it might might write. It might work.
3:35 So we go a limbic current and ask what current version is the database that we're talking to here versus some other one?
3:43 And we might point out, what is the version? It says it's seven to Devi, whatever that means. If we go open this up,
3:49 you'll see there's well, right now, there's only one version we've created. We've only had to apply one migration,
3:55 but you know, we're gonna do another one right now. So these files over here store all the changes that have to be applied and basically
4:03 Olympic will look at the data base, figure out what versions have been applied in in the right order. Apply the new ones. If it's not upgraded,
4:11 we would say Olympic upgrade head. And here you get no output, which is a little unfortunate, but what it really means,
4:19 I mean, other than these info messages is hate. It's already up to date. If it were not. You would see a message about how it upgraded stuff.
4:26 So in order to synchronize the database or say, look, look over at thes files and see the database and see how you gotta
4:35 change the database to adapt. We're gonna right at one simple line here. Olympic revision. Now, if I were to just type like there's a little message
4:46 this will be ad is shared to user the page. Sorry. If I were to run that, then it's my job to write how this upgrade is going to be done.
4:57 And if we're gonna undo the upgrade, how do we do? Vent. What? Here's the thing you want to do.
5:01 You want to say auto generate because you wanted to do the work. Not you would run that. And it says,
5:07 Okay, great. We've realized that we've detected a column that needs to be added pages that is shared, and we've added a second migration over here.
5:18 Well, look at that. You can see it's a previous version was that its current version is this and what it's gonna do if we upgraded is add.
5:28 This is shared. If we downgraded, it's gonna drop. Is shared. All right, well, this doesn't do anything.
5:35 I if I try to rerun this when I go back to the same page and refresh it still there, and nothing has been changed in the database.
5:44 So this generates basically the steps in order that we need in order to make those changes, but it doesn't do it.
5:51 So the final thing to do is this Olympic upgrade head. It goes, and it talks to the database and now over in our database. Had it open before. See,
6:01 there's no shared. But if I refresh it, there's now a bowling is shared. Yes. And without even in rerunning the app, our page now works. Cool,
6:12 huh? So now the database and the data models have been updated to have this
6:17 is shared concept, and we've created a migration to upgrade old databases that don't have

Talk Python's Mastodon Michael Kennedy's Mastodon