Left Icon Right Icon
Squehub SqueHub

๐Ÿ“ค Dumper in Squehub

The Dumper system in Squehub helps you populate your database with test or fake data using clean PHP logic. It is useful for development, staging, demos, or local testing environments.

๐Ÿ“ Directory Structure

All Dumper classes must be created inside the database/dumper/ directory. Each Dumper must extend the base class App\Core\Dumper.

database/
โ””โ”€โ”€ dumper/
    โ””โ”€โ”€ UsersDumper.php

๐Ÿงฉ Example Dumper File

This example generates 10 users using the User model.

<?php

namespace Database\Dumper;

use App\Core\Dumper;             // โœ… Always required
use Project\Models\User;          // โœ… Only needed if interacting with the User model

class UsersDumper extends Dumper
{
    public function run()
    {
        for ($i = 1; $i <= 10; $i++) {
            User::create([
                'name' => "User $i",
                'username' => "user$i",
                'email' => "user$i@example.com",
                'password' => password_hash("password", PASSWORD_DEFAULT),
                'country' => 'USA',
                'status' => 'active',
            ]);
        }
    }
}

๐Ÿš€ Running a Dumper

To run your Dumper class from the CLI:

$ php squehub dump:run UsersDumper

This will call the run() method and insert the data.

โšก Generate One Automatically

You can use the CLI to scaffold a new Dumper file:

$ php squehub make:Dumper UsersDumper

This creates a file under database/dumper/ with the correct structure.

๐Ÿ“˜ Important Notes

  • โœ… Always include use App\Core\Dumper; at the top โ€” it powers the Dumper system.
  • โœ… Only include use Project\Models\XYZ; when the dumper interacts with that model (e.g. User).
  • ๐Ÿง  All Dumper classes must have a valid namespace โ€” e.g. namespace Database\Dumper;.
  • ๐Ÿงช Dumper files are for inserting fake/test data into real database tables.
  • ๐Ÿ“‚ Keep logic simple: create one dumper per dataset type (users, products, orders, etc).

โœ… Summary

  • ๐Ÿ“ Dumper files live in database/dumper/.
  • ๐Ÿงฑ They must extend App\Core\Dumper.
  • ๐Ÿ“ฆ Use model classes like use Project\Models\User; only when needed.
  • ๐Ÿ” The run() method contains the data-insertion logic.
  • ๐Ÿ’ป Run with: php squehub dump:run YourDumperName.
๐Ÿ’ก Tip: You can also group related Dumper files under subdirectories inside database/dumper/. Just ensure the namespace reflects the folder structure.
;