-
Notifications
You must be signed in to change notification settings - Fork 892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#703 - Add table truncate method #978
Conversation
nice, just needs unit tests. |
cc @edsonmedina |
and documentation.
|
I've added the unit test for MySQLAdapter, but didn't add for PostgreSQL or SQL Server as none of them have a unit test file (only integration tests? not really sure how they work). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks sensible to me.
Re your comment about unit tests for the other database types, maybe that should be ticketed up as a future improvement @robmorgan?
Thanks for doing this @edsonmedina.
It probably wants documenting after this before merging...
https://github.com/edsonmedina/phinx/blob/0.6.x-dev/docs/migrations.rst#inserting-data.
I guess I could fork your PR and add that then submit a PR to you if you want a bit of help? I'm going to be spending a lot of time waiting for things to run over the next week or so I think, so I'll have little windows for things like that.
I'll handle the docs and tests. Accepting this one for v0.7.1. |
@@ -389,7 +389,6 @@ public function insert(Table $table, $row) | |||
$stmt->execute(array_values($row)); | |||
$this->endCommandTimer(); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: will re-add new line.
src/Phinx/Db/Table.php
Outdated
@@ -655,6 +655,15 @@ public function saveData() | |||
} | |||
|
|||
/** | |||
* Truncates the table | |||
* @return void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new line required
public function truncateTable($tableName) | ||
{ | ||
$sql = sprintf( | ||
"TRUNCATE TABLE %s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQLite doesn't support TRUNCATE
. Using DELETE FROM %s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
*/ | ||
public function truncate() | ||
{ | ||
$this->getAdapter()->truncateTable($this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AdapterInterface::truncateTable
requires a string
.
I fixed a couple of problems. Please be sure to test your code as much as possible in the future. cc @edsonmedina |
No description provided.