Phinx only needs this feature if it turns out to be increasingly popular amongst users. It might come in handy with Seeders, but i'll leave it for now.
@robmorgan I just found myself here because I need to truncate a table in a migration too. I'll hand roll mine for now, but could submit a PR for this feature if you wanted to reopen the issue?
@robmorgan nice work BTW. I'm here also as I need to truncate before running some seeders.
@WillGibson sure, feel free to contribute something! I think I have a use for this as well.
There is an active PR for this?
Still waiting for this.
For those stumbling upon this issue (while this MR is not accepted), use this:
It's essentially what the MR from @edsonmedina does.
<?php
/* ... seed stuff ... */
$tableName = 'seed_table_name';
$table = $this->table($tableName);
// truncate table
$table->getAdapter()->execute(
'TRUNCATE TABLE ' . $table->getAdapter()->quoteTableName($tableName)
);
// seed..
$table->insert($data)->save();
There is now a PR https://github.com/robmorgan/phinx/pull/978 for this feature.
Merged to master in a10918dbe6da3a5b19be1b89f0953d82b0adcb98
Most helpful comment
For those stumbling upon this issue (while this MR is not accepted), use this:
It's essentially what the MR from @edsonmedina does.