Time
9 hours 41 minutes
Difficulty
Intermediate
CEU/CPE
10

Video Transcription

00:00
I welcome back to muzzle five. This is less than 5.6 the logging table. This is a common table found in databases.
00:07
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,
00:19
and one reason to do so is because accidental deletes are often blamed on vanishing application data or application airs,
00:27
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.
00:45
All right, let's get started with creating that logging table.
00:48
I'm going to create a model and a migration together. Recall that model log and plural off that model will be logs,
00:56
and it's not as important to get on our E. R D diagram
01:00
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.
01:19
Do PSP artists in
01:22
make model
01:25
log
01:26
and dash migration
01:29
just ash in my brain.
01:32
I could probably have spelled it out as well
01:34
times that works. Okay, it looks like we have created it
01:40
now. We needed to find what columns are in that table.
01:44
So I'm going to my shared database migrations.
01:49
There's my logs table,
01:52
Andi big increments. I. D Time stamps. That is completely fine.
01:57
Let's go ahead and put a couple of fields in a string, will be titled,
02:05
and then let's use a text field so we can have long strings of text. So attacks
02:13
description
02:16
and let's also put a code in there as well. So we'll say
02:23
table
02:24
in a juror
02:29
code.
02:30
I'm gonna make
02:32
these knowable
02:36
because errors and logging can include a whole bunch of different types of data where it doesn't make sense to fill in
02:43
everything. For example, if we're not logging in air. We're not gonna have an air code.
02:49
And
02:50
right,
02:52
save that one. Run my migration,
02:54
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,
03:06
be artisan,
03:07
my great.
03:09
And we need to use refresh because we have a trigger or not a trigger. But I function in here
03:15
and fresh doesn't run the down part of the files and that will cause
03:21
on air when it goes to. Instead, she ate that function. So
03:25
okay, the migration has completed. Let's go ahead and take a look at our database to make sure the file exists.
03:37
And it certainly does.
03:42
Actually, we probably want to add it. The school I d. So that we know
03:46
which school the log belongs to.
03:49
So let's go ahead and do that.
03:53
So we're actually going to need to change this. So it's a big manager,
03:59
I d and we'll make it unsigned
04:03
like so.
04:06
Then I'm going to copy it.
04:10
Okay. I need to make this say school I d.
04:15
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.
04:27
Thats symbols, right? Need an array? I d
04:33
Come on
04:34
school. I d
04:40
Don't forget my semi colon. Save it.
04:44
Let's go ahead and run that migration again with a refresh
04:48
before I got that. All right, otherwise, we'll get in the air.
04:56
Looks like it worked. Let's go check art
04:59
and in the relationship diagram again. Going to hit. Refresh.
05:02
And there we go. We got that composite primary key,
05:06
all right, that completes this lesson. Let's go ahead and head over to the summer and discuss what we did.
05:14
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

Up Next

Intermediate SQL

This free course introduces the student to intermediate concepts found in the implementation and application of Structured Query Language (SQL) within professional business environments.

Instructed By

Instructor Profile Image
Kitt Parker
Instructor