sherwinmdev's avatar

ideas to store record activity logs?

i need to store data whenever a record is created, updated, deleted. my migration file is as follows

Schema::create('record_logs', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')
                ->index()
                ->unsigned();
            $table->string('user_full_name');
            $table->string('user_email');
            $table->bigInteger('record_id')
                ->unsigned();
            $table->string('table_name')
                ->index();
            $table->string('record_action', 50)
                ->comment('created, updated, deleted')
                ->index();
            $table->text('record_before')
                ->nullable();
            $table->text('record_after')
                ->nullable();
            $table->string('environment', 50)
                ->nullable();
            $table->timestamps();
        });

no constraints or cascade actions needed. it just creates records in this table. i may need to query the table and display records that belong to the data being tracked. i'm using mysql database for the project and currently using the same db to store this log table.

should i store it in the same database? keep it in mysql but different database? use sqlite? use redis? i'd love to hear how some of you have this implemented. thanks.

0 likes
5 replies
sherwinmdev's avatar

@steveperrycreative thanks, i'll check the video out but i have it working. i just need some ideas on where to store it. it's really just for accountability. for instance, when a record is deleted, it can answer the question... "who deleted it and when?".

1 like
sherwinmdev's avatar

where are people storing this data is my question. same as the app db? is mysql? redis? sqlite?

HRcc's avatar

Generally, storing logs in the main DB is completely fine. However, if you need to build some complex analytics on top of that or the record count is huge, there might be better solutions available (InfluxDB, Cassandra, Couchbase,...).

3 likes

Please or to participate in this conversation.