Reversible views, triggers etc. [howto]
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 4.5k
- Forks
- 884
- PR merge metrics
- No merged PRs in 30d
Description
I'm new to phinx but it seems to be a rock solid tool that cover all my needs. I like that smart "change" method, but if I want to create some view or trigger an so, There is only way how to do by raw query. And that raw query not support reverse action in change method. So I make little investigation how to make it reversible.
-
Use that old methods up() and down(). In up method you can write query for "CREATE OR REPLACE VIEW my_view...." and in down method "DROP VIEW my_view" alongside with reversing other tables.
-
In my opinion is better to prefer smater "change" method because my lazyness to wrote code double if it is not necessary. So the same functionality you reach by this example:
public function change(): void
{
$tblA = $this->table("tableA"); //reversible by default in change method
$tblA->addColumn("name", "string", ["null" => false, "limit" => 255]);
$tblA->create();
$this->query("CREATE OR REPLACE VIEW my_view AS SELECT * FROM tableA");
if(!$this->isMigratingUp) //this is the key
{
$this->query("DROP VIEW my_view");
}
}
so it is simple and I hope that help someone to use it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the issue's examples using migration change(), up(), down(), query(), and isMigratingUp for views and triggers. Check the existing migration documentation to determine where reversible raw queries are described; done means the supported approach is documented clearly, including reversal behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- databases
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100