-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add a code example on how to create corresponding tables for models in database #18
Comments
I'm looking for the same answers ! Funny time synchronisation :-) if (Schema::hasTable('payouts')) {
Schema::create('payouts', static function (Blueprint $table) {
$table->increments('id');
$table->decimal(Payout::AMOUNT, 8, 2);
});
} Trying that led me to an "A facade root has not been set." error for now |
So I guess the question could be: how can we configure Schema to work/access our wordpress db |
This package adds the following dependencies to your composer.json
I think If you want to use
you have to install one more package Support package but in my project I want to use minimum dependencies. Even this wp-orm is quite large but its a cost of using ORM with Wordpress |
|
Lol, chatGPT helped |
Need to add It's strange but this method is not added to the If such method will be added then we can set the connection in Facade
And then we will be able to use Scheme to generate sql quires for tables |
As indicated by @mrmoric , the package contains a dependency to This tool works very simply because you just need to create a If you use a tool other than Bedrock, I invite you to propose an MR to explain how to use the tool on another Framework than Bedrock so that other people can enjoy it:) Here is an example of a migration that adds a column: declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class V20210812221926 extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$table = $this->table(\MyModel::table());
if ($table->exists()) {
$table
->addColumn(\MyModel::MY_PROPERTY, 'string', ['null' => true])
->update();
}
}
} You can look this documentation for more information: https://book.cakephp.org/phinx/0/en/migrations.html# @axi The dependency to the This migration will take some time, I plan to work on this topic in April or May. I remain available if you need help using Phinx or if you have ideas to improve this package :) |
@dimitriBouteille thanks for that answer. Yes I thing the goal of removing the |
I close this issue, I opened the following issues :) |
Normally we use the following code to create tables in WordPress:
But how it should be done using your package? I guess we still need to use 'dbDelta' piece, but code for table creation should be done in a different way. Perhaps we have to use QueryBuilder or somehow get table schema from Models?
If we don't need to use WordPress approach but use migrations instead. Then anyway how to run these migrations only once, so it doesn't try to create tables on each page init
The text was updated successfully, but these errors were encountered: