1 00:00:00,650 --> 00:00:01,819 Welcome back. 2 00:00:02,210 --> 00:00:09,050 I am so excited for this section because we're finally combining everything we know into one place by 3 00:00:09,050 --> 00:00:15,470 the end of this, we have a unified understanding of how everything works and the world of web development. 4 00:00:17,650 --> 00:00:22,000 We have our front end smart brain here with the sign in page. 5 00:00:23,760 --> 00:00:27,120 And we have our app, Balton React. 6 00:00:28,130 --> 00:00:36,500 We also have our server running on three thousand, listening to requests, but now we don't need this 7 00:00:36,500 --> 00:00:37,380 database anymore. 8 00:00:37,880 --> 00:00:41,660 We can create our own PostgreSQL database now. 9 00:00:42,770 --> 00:00:46,490 And have the server interacting with it through school. 10 00:00:47,660 --> 00:00:53,240 Updating everything and then responding to express back to the front end. 11 00:00:54,140 --> 00:00:55,280 It's going to be so much fun. 12 00:00:55,400 --> 00:01:02,210 I'm so excited, but before we actually start to coat anything, we have to design our database. 13 00:01:03,780 --> 00:01:05,160 Let's create. 14 00:01:07,120 --> 00:01:08,770 A database. 15 00:01:11,310 --> 00:01:13,920 And we'll call it smart brain. 16 00:01:19,310 --> 00:01:20,210 All right, perfect. 17 00:01:20,810 --> 00:01:26,600 Now that we have our database created, I want you to think of these three separate things as their 18 00:01:26,600 --> 00:01:31,790 own individual computers that when we deploy is going to be different parts. 19 00:01:33,090 --> 00:01:42,390 We have our server living on a computer, we have our database leaving on a computer, and we can actually. 20 00:01:43,640 --> 00:01:44,690 Connected to it. 21 00:01:47,560 --> 00:01:51,900 And we also have our app in a separate computer as well. 22 00:01:55,740 --> 00:02:03,390 So let's close this quickly and connect to our database, to our local host, and we called it Smart 23 00:02:03,390 --> 00:02:03,660 Brain. 24 00:02:07,740 --> 00:02:15,660 And there you go, but no tables yet to get started, as we did when we created our API design for our 25 00:02:15,660 --> 00:02:16,090 server. 26 00:02:16,290 --> 00:02:19,200 We really want to think about how our database would look. 27 00:02:20,820 --> 00:02:27,030 And we're using relational database here because in my opinion and in moving forward, relational databases 28 00:02:27,030 --> 00:02:28,140 are really, really good. 29 00:02:29,320 --> 00:02:34,420 Although databases like Mongo DB are really easy to get started with and they're dynamic, you don't 30 00:02:34,420 --> 00:02:36,720 have to think too much about when you're starting off. 31 00:02:37,240 --> 00:02:44,890 I think relational databases offer a really strong way to think about how your app should be structured 32 00:02:44,890 --> 00:02:48,500 and how everything and all the pieces come together. 33 00:02:49,390 --> 00:02:55,090 It's a really, really powerful tool that I see the industry shifting back to more and more. 34 00:02:57,100 --> 00:03:04,900 Whether you use PostgreSQL or Maisky well, or sequel light, all these databases are pretty much the 35 00:03:04,900 --> 00:03:05,280 same. 36 00:03:05,290 --> 00:03:11,650 They're super powerful and we're going to do the exact same thing with our app because we're not necessarily 37 00:03:11,650 --> 00:03:16,530 storing information like LinkedIn or Facebook, where everything is a document model. 38 00:03:16,540 --> 00:03:19,720 We have users that are interacting with each other. 39 00:03:19,720 --> 00:03:22,120 But within our app, we can have different things. 40 00:03:22,120 --> 00:03:23,740 We can have login information. 41 00:03:23,860 --> 00:03:28,990 If we expand our app, we can have maybe information about the type of images that they've submitted. 42 00:03:29,860 --> 00:03:36,730 Now, looking at what we've built, there's definitely a few things that we want to create. 43 00:03:38,140 --> 00:03:44,680 If we go back to our database example here, we have our user stable, which we're going to have to 44 00:03:44,680 --> 00:03:45,060 create. 45 00:03:45,220 --> 00:03:48,300 But remember what I said about passwords in the way we store passwords. 46 00:03:49,330 --> 00:03:54,130 We don't necessarily want to create a user object or a user table. 47 00:03:54,130 --> 00:03:59,440 With all these columns, we want to separate things out and connect them through four keys. 48 00:04:00,880 --> 00:04:04,630 So we're going to create a user stable and then a log in table. 49 00:04:06,460 --> 00:04:12,010 And have those cables connected through perhaps the email field. 50 00:04:12,460 --> 00:04:17,410 Let's go back to our gooey and create these tables now going to open up the KORIE. 51 00:04:17,860 --> 00:04:23,680 Let's remove this from now our old query and let's create our users table. 52 00:04:24,550 --> 00:04:29,080 As you remember, it's create table users. 53 00:04:30,630 --> 00:04:33,060 I have brackets around here just so it's clean. 54 00:04:35,630 --> 00:04:42,950 And within here, I'll say it is going to be serial and this will be our primary key. 55 00:04:46,290 --> 00:04:48,360 We will also have name. 56 00:04:49,880 --> 00:04:57,530 And the name will give it a variable character of a hundred, we'll just assume that nobody's name is 57 00:04:57,530 --> 00:05:02,390 going to be more than one hundred characters, which again, I don't think we will. 58 00:05:02,640 --> 00:05:04,870 Otherwise our database will give us an error. 59 00:05:05,330 --> 00:05:09,980 We can also create a email field and this will be a text. 60 00:05:10,340 --> 00:05:12,650 We also want to make sure that this is a unique email. 61 00:05:13,520 --> 00:05:16,580 Otherwise we don't want to register the same user over and over. 62 00:05:16,970 --> 00:05:18,650 And it cannot be not. 63 00:05:19,370 --> 00:05:20,600 It must always be. 64 00:05:22,060 --> 00:05:26,680 There because this is where we're going to use in our log-in table. 65 00:05:28,190 --> 00:05:30,050 We also know that we want to entrées. 66 00:05:32,370 --> 00:05:38,730 And the entries can really be a quite a big number if we have a really dedicated user, well, then 67 00:05:38,760 --> 00:05:41,190 that person can keep submitting those photos. 68 00:05:41,580 --> 00:05:44,250 So let's just do a large hint here. 69 00:05:44,490 --> 00:05:44,790 Oops. 70 00:05:44,790 --> 00:05:48,080 And instead of large, it's big. 71 00:05:48,090 --> 00:05:49,580 And there you. 72 00:05:50,530 --> 00:05:57,520 With big and we will also say that we want the default and this might be new for us, but default value 73 00:05:57,520 --> 00:05:58,480 should be zero. 74 00:06:00,020 --> 00:06:07,580 Unless we somehow insert with entries and a number, if we don't specify what we're inserting the number 75 00:06:07,580 --> 00:06:09,290 with, it should be default to zero. 76 00:06:10,840 --> 00:06:17,500 Finally, we also want to get the time that they joined our app and we can use a timestamp. 77 00:06:18,630 --> 00:06:24,330 Data type for that and again, we want to make sure that this is not null either. 78 00:06:25,920 --> 00:06:27,590 All right, let's run this and see if it works. 79 00:06:30,010 --> 00:06:35,120 And I get an error at or near, and that's because I added a comma at the end here. 80 00:06:35,230 --> 00:06:35,950 Let's try that again. 81 00:06:37,730 --> 00:06:38,220 There you go. 82 00:06:38,480 --> 00:06:46,910 If I refresh, we have our user stable, amazing, so we have the user stable, which we're going to 83 00:06:46,910 --> 00:06:47,450 store. 84 00:06:48,790 --> 00:06:55,510 All this information, and we also want to make sure that we store our login information, the email 85 00:06:55,510 --> 00:07:00,850 and the hashes, because remember, we're never storing plaintext passwords. 86 00:07:04,260 --> 00:07:05,550 I'm going to go back to the query. 87 00:07:08,200 --> 00:07:10,000 Remove this and change it to. 88 00:07:11,610 --> 00:07:21,750 Log in and this log in will now have an ID once again of cereal and the cereal data type will just increment, 89 00:07:22,650 --> 00:07:24,930 it'll be a primary key. 90 00:07:28,290 --> 00:07:36,810 And we'll have a column hash that has a variable character of a hundred once again, because we know 91 00:07:36,810 --> 00:07:43,760 that B Crypt always gives us a certain length hash and it'll never be over one hundred characters not 92 00:07:43,770 --> 00:07:44,150 no. 93 00:07:44,190 --> 00:07:46,170 We absolutely need this information. 94 00:07:46,770 --> 00:07:52,190 And then finally email, which will be the same as the users table. 95 00:07:52,410 --> 00:07:54,120 And this email would be a text. 96 00:07:54,690 --> 00:07:58,950 It must be unique and definitely not. 97 00:07:59,460 --> 00:07:59,820 No. 98 00:08:08,210 --> 00:08:15,080 All right, we got ourselves our tables designed, so now that we have these tables. 99 00:08:16,100 --> 00:08:24,020 We understand what our data is going to look like, this is going to be a database that will persist 100 00:08:24,320 --> 00:08:29,630 no matter if the server goes down, it's going to make sure that this data stays put. 101 00:08:30,930 --> 00:08:39,299 Now that we have these three pieces running, we can start to work with the server, remove the database 102 00:08:40,169 --> 00:08:43,600 variable and actually connect to our database. 103 00:08:44,550 --> 00:08:45,090 I'm excited. 104 00:08:45,090 --> 00:08:47,730 Show you how we're going to do that in the next video.