cambis / silverstripe-pruner
A simple developer utility to clear database tables.
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 2
Type:silverstripe-vendormodule
Requires
- php: ^7.4 || ^8.0
- silverstripe/framework: ^4.0 || ^5.0
README
A simple developer utility to clear database tables. This module provides a configurable task that truncates database tables inside of a transaction.
Prerequisites 🦺
php ^7.4 || ^8.0 silverstripe/framework ^4.0 || ^5.0
Installation 👷♀️
Install via composer.
composer require --dev cambis/silverstripe-pruner
Configuration 🚧
Create a configuration file.
--- Name: app_pruner --- Cambis\SilverstripePruner\Task\PruneSelectedORMTablesTask: # List the fqn names of the DataObjects you want to truncate truncated_classes: - My\Record\To\Truncate # Any extra tables such as those from silverstripe/versioned etc. truncated_tables: - Truncate_Live - Truncate_Versions # Defaults to false, add this line if you want to run the task in a production environment can_run_in_production: true
You can also dynamically update the truncated tables using an extension hook. This library provides traits to with the hook method definitions.
<?php namespace App\Extension; use Cambis\SilverstripePruner\Concern\UpdateTruncatedClasses; use Cambis\SilverstripePruner\Concern\UpdateTruncatedTables; use Cambis\SilverstripePruner\Task\PruneSelectedORMTablesTask; use SilverStripe\Core\Extension; /** * @extends Extension<PruneSelectedORMTablesTask> */ final class MyPrunerExtension extends Extension { use UpdateTruncatedClasses; use UpdateTruncatedTables; protected function updateTruncatedClasses(array &$truncatedClasses): void { $truncatedClasses[] = \My\Record\To\Truncate::class; } protected function updateTruncatedTables(array &$truncatedTables): void { $truncatedTables[] = 'Truncate_Live'; $truncatedTables[] = 'Truncate_Versions'; } }
Usage 🏃🏃🏃
vendor/bin/sake dev/tasks/prune-selected-orm-tables confirm=1