Effective PyCharm Transcripts
Chapter: Databases
Lecture: Database diagrams

Login or purchase this course to watch this video and the rest of the course contents.
0:00 If we want to understand the relationship between all the tables,
0:03 we can look at our SQLAlchemy classes over here.
0:06 And yeah, you can see there is a relationship from releases,
0:09 to packages. That's a pretty limited view.
0:12 You kinda gotta go through all these files and the more complicated that your database gets
0:15 the harder it is to keep that all in your mind.
0:18 Wouldn't it be cool if we had a picture?
0:20 Well, let's make one So PyCharm is actually really good at creating pictures and
0:25 graphs that show us how this works.
0:27 So go over here to our tables and we right click,
0:30 we go to this diagram and we can either see a visualization or a visualization pop
0:34 up. The only difference one is like a separate window.
0:38 The other one is a tab.
0:39 So let's just look at this visualization here check that out.
0:42 You can see all the tables,
0:43 all their relationships. Again, you can even see where the indexes are,
0:48 where the relationships are, where the foreign keys are.
0:51 All the good stuff that you might want.
0:53 Now, the layout might not be exactly what you're hoping for.
0:56 For example, I don't really want SQLite Master ever.
0:59 This is like something that SQLite uses to maintain itself.
1:02 We can just highlight that and hit delete also let's put these sort of separate stand
1:10 alone tables over here like this.
1:13 And yeah, this looks all right.
1:14 We can kind of move that over over like this or so and then we can
1:18 say a round edges and it'll actually fix things up a little bit that allow us
1:23 to put this here. Maybe do one more time,
1:27 nope, didn't like that. Let's put this back.
1:31 There we go. We've got things organized the way we like,
1:34 we can say fit content, so it's a little bit bigger.
1:37 Close it and if we come back and ask for the diagram again,
1:41 remember how I put it so you can organize these things just like you like.
1:45 So it's easy to understand and yeah,
1:47 that's a really, really good.
1:49 The next thing that we can do That you might want to focus on on a
1:53 real complex database is if you had 50 or 100 tables,
1:58 you don't want them all just piled on here.
2:01 Maybe you're focused specifically on a certain use case.
2:05 And for that we can come over and say,
2:06 let's say we're focused on packages,
2:09 releases and maintainers. You just highlight those right click generated diagram and now we have
2:18 a new visualization that just has those pieces.
2:22 Let's put this in the middle,
2:23 put this on the side, it wants to put it like that,
2:29 doesn't it? There we go.
2:31 I got to organize but see how we can just focus on a little part of
2:35 our application. And somehow we got users in here,
2:38 I don't really even need users so we can just have a nice clean model here
2:45 that shows us the relationship between packages releases and maintainers If you want to focus in
2:51 on a subset of your database,
2:53 this is, like I said,
2:54 especially useful when you've got a ton of tables in real world applications that have been
2:59 around for a long time, 50, 100 tables entirely possible.
3:03 Right? So you don't want to try to understand it all at once.
3:05 Take little pieces, little use cases and so on.
3:09 So if you're working with databases,
3:10 be sure to use the diagrams to visualize them and understand them better.