-
Notifications
You must be signed in to change notification settings - Fork 27
add function truncate #92
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
Open
stood
wants to merge
4
commits into
pomm-project:master
Choose a base branch
from
stood:feature-truncate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
| /* | ||
| * This file is part of the PommProject/ModelManager package. | ||
| * | ||
| * (c) 2014 - 2015 Grégoire HUBERT <hubert.greg@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| namespace PommProject\ModelManager\Test\Fixture; | ||
|
|
||
| use PommProject\ModelManager\Model\FlexibleEntity; | ||
|
|
||
| class ForeignKeyFixture extends FlexibleEntity | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
| /* | ||
| * This file is part of the PommProject/ModelManager package. | ||
| * | ||
| * (c) 2014 - 2015 Grégoire HUBERT <hubert.greg@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| namespace PommProject\ModelManager\Test\Fixture; | ||
|
|
||
| use PommProject\Foundation\Session\Session; | ||
| use PommProject\ModelManager\Model\ModelTrait\WriteQueries; | ||
|
|
||
| class ForeignKeyFixtureModel extends WriteFixtureModel | ||
| { | ||
| use WriteQueries; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $this->structure = new ForeignKeyFixtureStructure(); | ||
| $this->flexible_entity_class = '\PommProject\ModelManager\Test\Fixture\ForeignKeyFixture'; | ||
| $this->getStructure()->setRelation('foreign_key_fixture'); | ||
| } | ||
|
|
||
| protected function createTable() | ||
| { | ||
| $this->executeAnonymousQuery( | ||
| sprintf( | ||
| "create temporary table %s (id serial primary key, truncate_id int, CONSTRAINT fk_truncate FOREIGN KEY(truncate_id) REFERENCES truncate_fixture(id))", | ||
| $this->getStructure()->getRelation() | ||
| ) | ||
| ); | ||
|
|
||
| return $this; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
| /* | ||
| * This file is part of the PommProject/ModelManager package. | ||
| * | ||
| * (c) 2014 - 2015 Grégoire HUBERT <hubert.greg@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| namespace PommProject\ModelManager\Test\Fixture; | ||
|
|
||
| use PommProject\ModelManager\Model\RowStructure; | ||
|
|
||
| class ForeignKeyFixtureStructure extends RowStructure | ||
| { | ||
| public function __construct() | ||
| { | ||
| $this | ||
| ->addField('id', 'int4') | ||
| ->addField('truncate_id', 'int4') | ||
| ->primary_key = ['id'] | ||
| ; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
| /* | ||
| * This file is part of the PommProject/ModelManager package. | ||
| * | ||
| * (c) 2014 - 2015 Grégoire HUBERT <hubert.greg@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| namespace PommProject\ModelManager\Test\Fixture; | ||
|
|
||
| use PommProject\Foundation\Session\Session; | ||
| use PommProject\ModelManager\Model\ModelTrait\WriteQueries; | ||
|
|
||
| class TruncateFixtureModel extends WriteFixtureModel | ||
| { | ||
| use WriteQueries; | ||
|
|
||
| public function __construct() | ||
| { | ||
| parent::__construct(); | ||
| $this->getStructure()->setRelation('truncate_fixture'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I am not keen on
myFunc(true, false)It would make more sense to me to have->truncate("CASCADE AND MORE OPTIONS");This IMHO let the developer with full control of future Pg extensions to the truncate command. The only issue I see is a security concern, it would imply to cut everything after a semicolon character to ensure a brain dead developer that passes truncate options from an external environment would still be safe.
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.
Another option can be instead of "true, false" use some constant or bit like `truncate(PG_TRUNCATE_CASCADE | PG_TRUNCATE_RESTART)
If any extension is added, a simple define can be added.
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.
I'm ok with you for postgres developer, but for beginner developer, it's less easy. If you want to use an other syntax for truncate you could be to use
->query('TRUNCATE ....'). For me, the SQL is the best language but for the rest of the world is not a sexy language.it would be a shame not to help those developpers, no? I thinks our job is to help the rest of the world to discover all the postgresql functionalities :)
Postgresql developer keeps control of his actions and queries, and the junior developer is not afraid of sql
But I'm ok to change the method signature because bool is not a good practice
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.
ping @chanmix51