The main problem here is sync all the databases, to do that by using phinx
, you should decide which is the most complete database and do the following:
Option 1:
Create a "master" migration with each table that should exist, "complete database, one per table.
<?PHP
public function up()
{
$exists = $this->hasTable('xxx');
if (!$exists) {
$this->execute("CREATE TABLE `xxx` (`xxx_id` int(10) NOT NULL AUTO_INCREMENT);");
}
}
public function down()
{
$exists = $this->hasTable('xxx');
if ($exists) {
$table = $this->table('xxx');
if (!$table->hasColumn('name')) {
$table->addColumn("name", "string", ["limit" => 255])->save();
}
$table->drop();
}
}
but creating one migration per table could be a hard job, then ...
Option 2:: You could create the database scripts dynamically by listing tables and adding them into an array:
<?PHP
public function up()
{
$tables = ['xxx', 'yyy'];
foreach ($tables as $curTable) {
$exists = $this->hasTable($curTable);
if (!$exists) {
$this->execute($this->getCreateTable($curTable));
}
}
}
but then you should generate a method called getCreateTable
that receives the table
name and get the structure from the master database.
after that create a routine to do the same with fields but you can get them for each table and nested loop for each field.
DESCRIBE
on each table and pipe that through a diff. – Shandy