Skip to content
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

Merged
merged 4 commits into from
Feb 11, 2017
Merged

#703 - Add table truncate method #978

merged 4 commits into from
Feb 11, 2017

Conversation

edsonmedina
Copy link
Contributor

No description provided.

@robmorgan
Copy link
Member

nice, just needs unit tests.

@robmorgan
Copy link
Member

cc @edsonmedina

@robmorgan robmorgan changed the base branch from 0.6.x-dev to master January 21, 2017 17:28
@robmorgan
Copy link
Member

robmorgan commented Jan 21, 2017

and documentation.

  • unit tests
  • documentation

@edsonmedina
Copy link
Contributor Author

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).

Copy link

@WillGibson WillGibson left a 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.

@robmorgan
Copy link
Member

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

Copy link
Member

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.

@@ -655,6 +655,15 @@ public function saveData()
}

/**
* Truncates the table
* @return void
Copy link
Member

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",
Copy link
Member

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

Copy link
Contributor Author

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);
Copy link
Member

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.

@robmorgan
Copy link
Member

robmorgan commented Feb 11, 2017

I fixed a couple of problems. Please be sure to test your code as much as possible in the future.

cc @edsonmedina

@robmorgan robmorgan merged commit 4a6b487 into cakephp:master Feb 11, 2017
@edsonmedina edsonmedina deleted the truncate branch February 11, 2017 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants