spatie / blender

The Laravel template used for our CMS like projects
https://freek.dev/on-open-sourcing-blender
877 stars 148 forks source link

Refactor seeders so all tables get dumped first #299

Closed freekmurze closed 7 years ago

freekmurze commented 7 years ago

Code to drop all tables:

Schema::disableForeignKeyConstraints();

collect(DB::select("SHOW FULL TABLES WHERE Table_Type = 'BASE TABLE'"))
    ->map(function (stdClass $tableProperties) {
        return get_object_vars($tableProperties)[key($tableProperties)];
    })
    ->each(function (string $tableName) {
        DB::table($tableName)->truncate();
    });

Schema::enableForeignKeyConstraints();
freekmurze commented 7 years ago

Could just the TableDropperFactory to perform this.

sebastiandedeyne commented 7 years ago

This should replace all manual truncate calls