Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
Already have an account? Sign In »
9 hours 41 minutes
I welcome back to muzzle five. This is less than 5.6 the logging table. This is a common table found in databases.
They typically log important application actions, such as the leading accounts, creating accounts, various user actions and system airs. There are always a good idea to include in your application,
and one reason to do so is because accidental deletes are often blamed on vanishing application data or application airs,
and that can cause an application to lose trust. So that's just one of the few reasons that you want to include a logging table in general. It's a good idea to be able to know and understand how certain actions occurred in your database and this lesson. We're gonna create a logging table, so let's go ahead and get started.
All right, let's get started with creating that logging table.
I'm going to create a model and a migration together. Recall that model log and plural off that model will be logs,
and it's not as important to get on our E. R D diagram
our entity relationship diagram because it's not actually going to be related to any of our other tables. It's going to be a table that sits out there by itself and catches various logging data. But that said, Let's go ahead and get started. So I'm in a as a safe session, my Bagram machine. I'm gonna see the into my level directory where all my files are.
Do PSP artists in
and dash migration
just ash in my brain.
I could probably have spelled it out as well
times that works. Okay, it looks like we have created it
now. We needed to find what columns are in that table.
So I'm going to my shared database migrations.
There's my logs table,
Andi big increments. I. D Time stamps. That is completely fine.
Let's go ahead and put a couple of fields in a string, will be titled,
and then let's use a text field so we can have long strings of text. So attacks
and let's also put a code in there as well. So we'll say
in a juror
I'm gonna make
because errors and logging can include a whole bunch of different types of data where it doesn't make sense to fill in
everything. For example, if we're not logging in air. We're not gonna have an air code.
save that one. Run my migration,
which you know will make it so my database that doesn't have any exceeded data. So if you want to see is your database will, of course, need to see your database after you run this refresh,
And we need to use refresh because we have a trigger or not a trigger. But I function in here
and fresh doesn't run the down part of the files and that will cause
on air when it goes to. Instead, she ate that function. So
okay, the migration has completed. Let's go ahead and take a look at our database to make sure the file exists.
And it certainly does.
Actually, we probably want to add it. The school I d. So that we know
which school the log belongs to.
So let's go ahead and do that.
So we're actually going to need to change this. So it's a big manager,
I d and we'll make it unsigned
Then I'm going to copy it.
Okay. I need to make this say school I d.
So big manager on Sinai D in school, i d. And now we need the primary key. We'll go ahead and make that a primary key. It will.
Thats symbols, right? Need an array? I d
school. I d
Don't forget my semi colon. Save it.
Let's go ahead and run that migration again with a refresh
before I got that. All right, otherwise, we'll get in the air.
Looks like it worked. Let's go check art
and in the relationship diagram again. Going to hit. Refresh.
And there we go. We got that composite primary key,
all right, that completes this lesson. Let's go ahead and head over to the summer and discuss what we did.
And that brings us to the 5.6 logging table summary And this lesson. We discussed the merits of a logging table, and we also implemented a logging table in our migration falls. And that brings this lesson to a close. I hope to see you in the next Thank you