Phinx: Add Table::truncate() && AdapterInterface::truncateTable() methods

Created on 3 Dec 2015  路  9Comments  路  Source: cakephp/phinx

According to the wiki: It was officially introduced in the SQL:2008 standard.
And supported by all main database vendors / drivers.
Do Phinx need this feature?

feature

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.

<?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();

All 9 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joshribakoff picture joshribakoff  路  15Comments

JamesTheHacker picture JamesTheHacker  路  15Comments

jeremylivingston picture jeremylivingston  路  20Comments

wpillar picture wpillar  路  97Comments

SergeC picture SergeC  路  13Comments