WEBVTT

00:00.150 --> 00:00.660
All right.

00:00.690 --> 00:05.640
So this is the first video of basically talking about the tables need and implementing the tables you

00:05.650 --> 00:07.950
need for Instagram clone.

00:08.250 --> 00:14.220
And the first thing we'll start with is users users is a pretty obvious place to start.

00:14.280 --> 00:17.890
I guess another one might be photos but users is at the core of everything.

00:17.910 --> 00:23.640
If you think about it because users are connected to you know photos are connected to comments they're

00:23.640 --> 00:31.050
connected to likes they're not connected to hashtags but pretty much everything else relates to users.

00:31.050 --> 00:35.800
So what I'm going to do here is something super simple like I said in the last video.

00:35.860 --> 00:37.520
There's a lot more we can store here.

00:37.530 --> 00:39.270
Email password.

00:39.330 --> 00:41.300
Like 20 different things.

00:41.550 --> 00:43.950
Location city IP address.

00:43.950 --> 00:45.240
All that stuff.

00:45.240 --> 00:51.960
We're just going to focus on the basics so when Id a user name and it created it and created that will

00:51.960 --> 00:56.210
just be you know the day that user or the time stamp when the user signs up.

00:56.370 --> 01:00.600
It will have a default value of now or current time stamp username.

01:00.600 --> 01:07.410
It's just going to be of our Chaar of our car and ID will be a primary key and we'll be referencing

01:07.410 --> 01:11.070
this ID in other places for example when we're talking about photos.

01:11.130 --> 01:15.340
Photos will have a foreign key referencing the user ID.

01:15.480 --> 01:19.640
So we'll go ahead and the first thing I have is just an empty directory.

01:19.650 --> 01:20.820
I may add just to store this.

01:20.820 --> 01:25.980
And I'm just going to make a new file and I'll just call it Instagram underscore and clone underscore

01:25.990 --> 01:26.520
clone.

01:26.550 --> 01:29.390
Eskew will open that up.

01:29.700 --> 01:31.160
And this is where all work.

01:31.170 --> 01:41.010
So this is where I'll do a create table users and like we said we're going to have an ID we have a username

01:41.640 --> 01:48.120
and a created at so id is going to be integer or just.

01:48.150 --> 01:52.460
And I'll do integer just because I've been doing it.

01:52.600 --> 01:54.510
But it's an alias for integer.

01:54.520 --> 01:55.840
Good to see both.

01:56.140 --> 01:59.350
And we'll have it autoincrement.

01:59.350 --> 02:02.460
And it's a primary key.

02:02.620 --> 02:04.780
Great comma.

02:05.050 --> 02:06.850
Come back to your name in just a second.

02:06.850 --> 02:15.730
Created that will do time stamp with a default of now and you can also do current time stamp and remember

02:15.790 --> 02:17.720
you could do date time aswell time stamp.

02:17.720 --> 02:21.010
It's just smaller it's easier to store.

02:21.020 --> 02:26.910
OK so then we've got username and we know it's just going to be a VAR char to 5:5.

02:27.300 --> 02:32.460
There's another constraint that we could add though which is we want user to be unique.

02:32.460 --> 02:36.920
We don't want anyone to be able to sign up with another with the same user name essentially.

02:37.080 --> 02:39.470
So we can add unique.

02:39.480 --> 02:43.830
And you might be wondering Well then why would we have him Id be the primary key.

02:43.830 --> 02:46.080
Why not make user name a primary key.

02:46.080 --> 02:47.910
You absolutely could do that.

02:47.910 --> 02:53.670
But if you're going to have foreign keys somewhere referencing username and you're working with a long

02:53.670 --> 03:01.270
string of someone to use your name is you know something massive like that because we could do 255 characters.

03:01.630 --> 03:07.820
That's going to be slower and more annoying to search potential while not potentially definitely slower.

03:07.830 --> 03:14.480
If you have thousands and thousands of entries compared to a smaller integer so it's good to have a

03:14.490 --> 03:16.050
primary keeping an integer.

03:16.140 --> 03:20.760
We can still have this unique constraint and we can also add not no we don't want anyone to be able

03:20.760 --> 03:23.100
to sign up without a username.

03:23.640 --> 03:24.150
OK.

03:24.420 --> 03:28.240
I'm going to go ahead and make a new database to put this in but I'm going to do it in this file.

03:28.500 --> 03:36.960
So I'll do a create database and also just called Instagram or IGY clone and then I'll use IGY clone

03:36.960 --> 03:38.390
just like that.

03:38.400 --> 03:44.970
So now every time I run this file it's going to make this database use Instagram clone the new database

03:45.030 --> 03:46.430
and create the table.

03:46.440 --> 03:51.000
And the reason I'm doing that it's just one to show you that you can we haven't really seen using these

03:51.000 --> 03:59.280
commands in a file but also as we go we may want to rerun this and recreate the users table or another

03:59.280 --> 04:01.110
table if we realize we missed something up.

04:01.110 --> 04:02.450
We need to change something.

04:02.520 --> 04:04.200
We're not going to have any data in there yet.

04:04.230 --> 04:07.690
So it's super easy just to create the database again.

04:07.710 --> 04:11.720
Drop it then create it and then use it and then create a table of users.

04:11.990 --> 04:12.270
OK.

04:12.330 --> 04:22.500
So with that said let's try this then to do source and I need to reference this directory slash Instagram

04:22.530 --> 04:23.990
clone as well.

04:25.150 --> 04:25.700
Okay.

04:26.000 --> 04:30.300
And just to double check the describe users.

04:30.670 --> 04:31.650
That looks good.

04:31.940 --> 04:32.180
OK.

04:32.180 --> 04:35.210
So if you are good with that go ahead move on.

04:35.210 --> 04:36.840
Next step we're going to talk about photos.

04:36.930 --> 04:41.690
But I will spend a minute or two just adding one or two users so that we can work with them in this

04:41.690 --> 04:42.350
section.

04:42.350 --> 04:46.960
Remember in the next section we're going to have a massive data set that I'm going to give you but if

04:46.970 --> 04:55.310
we want we can just play around with some data so I'll do an insert into users and we'll just insert

04:55.310 --> 04:59.360
user name and let's just do two or three.

04:59.360 --> 05:11.630
So we'll have to that cat and we could also have I don't know Charlie Brown and then I'll just put myself

05:11.630 --> 05:14.520
in there just like that.

05:14.960 --> 05:15.590
OK.

05:16.290 --> 05:24.030
So what we can do now if I just do free resource this whole thing I'll get an error because it tells

05:24.030 --> 05:25.270
me I can't create this database.

05:25.270 --> 05:34.320
Instagram it already exists so I could either drop the database first and I'm going to do that for now.

05:34.320 --> 05:36.520
You typically don't want to do that.

05:36.550 --> 05:39.330
You know you don't want to drop database ever if you can avoid it.

05:39.390 --> 05:45.420
But if there's no data in there yet or if the only data that will be in there is in the same file like

05:45.420 --> 05:47.510
we're doing here just testing it out.

05:47.580 --> 05:53.610
This makes it easy because I can just run this one command it will erase the database recreate it and

05:53.610 --> 05:56.620
get all the new table set I need in there as well as the new data.

05:56.830 --> 05:59.230
It's now it can do a select star from users.

05:59.580 --> 06:05.730
And that Rigaud we've got created that and there automatically IDs automatic and our 3 user names.

06:06.060 --> 06:06.580
OK.

06:06.810 --> 06:07.970
Next up photos.
