All right.
So this is the first video of basically talking about the tables need and implementing the tables you
need for Instagram clone.
And the first thing we'll start with is users users is a pretty obvious place to start.
I guess another one might be photos but users is at the core of everything.
If you think about it because users are connected to you know photos are connected to comments they're
connected to likes they're not connected to hashtags but pretty much everything else relates to users.
So what I'm going to do here is something super simple like I said in the last video.
There's a lot more we can store here.
Email password.
Like 20 different things.
Location city IP address.
All that stuff.
We're just going to focus on the basics so when Id a user name and it created it and created that will
just be you know the day that user or the time stamp when the user signs up.
It will have a default value of now or current time stamp username.
It's just going to be of our Chaar of our car and ID will be a primary key and we'll be referencing
this ID in other places for example when we're talking about photos.
Photos will have a foreign key referencing the user ID.
So we'll go ahead and the first thing I have is just an empty directory.
I may add just to store this.
And I'm just going to make a new file and I'll just call it Instagram underscore and clone underscore
clone.
Eskew will open that up.
And this is where all work.
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
and a created at so id is going to be integer or just.
And I'll do integer just because I've been doing it.
But it's an alias for integer.
Good to see both.
And we'll have it autoincrement.
And it's a primary key.
Great comma.
Come back to your name in just a second.
Created that will do time stamp with a default of now and you can also do current time stamp and remember
you could do date time aswell time stamp.
It's just smaller it's easier to store.
OK so then we've got username and we know it's just going to be a VAR char to 5:5.
There's another constraint that we could add though which is we want user to be unique.
We don't want anyone to be able to sign up with another with the same user name essentially.
So we can add unique.
And you might be wondering Well then why would we have him Id be the primary key.
Why not make user name a primary key.
You absolutely could do that.
But if you're going to have foreign keys somewhere referencing username and you're working with a long
string of someone to use your name is you know something massive like that because we could do 255 characters.
That's going to be slower and more annoying to search potential while not potentially definitely slower.
If you have thousands and thousands of entries compared to a smaller integer so it's good to have a
primary keeping an integer.
We can still have this unique constraint and we can also add not no we don't want anyone to be able
to sign up without a username.
OK.
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.
So I'll do a create database and also just called Instagram or IGY clone and then I'll use IGY clone
just like that.
So now every time I run this file it's going to make this database use Instagram clone the new database
and create the table.
And the reason I'm doing that it's just one to show you that you can we haven't really seen using these
commands in a file but also as we go we may want to rerun this and recreate the users table or another
table if we realize we missed something up.
We need to change something.
We're not going to have any data in there yet.
So it's super easy just to create the database again.
Drop it then create it and then use it and then create a table of users.
OK.
So with that said let's try this then to do source and I need to reference this directory slash Instagram
clone as well.
Okay.
And just to double check the describe users.
That looks good.
OK.
So if you are good with that go ahead move on.
Next step we're going to talk about photos.
But I will spend a minute or two just adding one or two users so that we can work with them in this
section.
Remember in the next section we're going to have a massive data set that I'm going to give you but if
we want we can just play around with some data so I'll do an insert into users and we'll just insert
user name and let's just do two or three.
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
in there just like that.
OK.
So what we can do now if I just do free resource this whole thing I'll get an error because it tells
me I can't create this database.
Instagram it already exists so I could either drop the database first and I'm going to do that for now.
You typically don't want to do that.
You know you don't want to drop database ever if you can avoid it.
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
we're doing here just testing it out.
This makes it easy because I can just run this one command it will erase the database recreate it and
get all the new table set I need in there as well as the new data.
It's now it can do a select star from users.
And that Rigaud we've got created that and there automatically IDs automatic and our 3 user names.
OK.
Next up photos.