Integrated Phinx DB migrations. Requires running composer install
This commit is contained in:
27
bin/phinx
Executable file
27
bin/phinx
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Wrapper to call phinx with configuration file in a folder which shuld
|
||||||
|
* not hold the "db" folder
|
||||||
|
*/
|
||||||
|
require_once(realpath(dirname(__FILE__)."/../config/config.php"));
|
||||||
|
|
||||||
|
$phinx_path = realpath(BASEDIR."/vendor/bin/phinx");
|
||||||
|
$config_path = realpath(BASEDIR."/config/phinx.php");
|
||||||
|
$default_args = ["--configuration=$config_path"];
|
||||||
|
|
||||||
|
$command = false;
|
||||||
|
$arguments = [];
|
||||||
|
|
||||||
|
if(count($argv) > 1) {
|
||||||
|
$command = $argv[1];
|
||||||
|
$arguments = array_slice($argv, 1);
|
||||||
|
|
||||||
|
//var_dump($arguments);
|
||||||
|
if(in_array($command, ["breakpoint", "create", "migrate", "rollback", "status", "test", "seed:create", "seed:run", "list:aliases"])) {
|
||||||
|
$arguments = array_merge($default_args, $arguments);
|
||||||
|
}
|
||||||
|
//var_dump($arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
pcntl_exec($phinx_path, $arguments);
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"phpoffice/phpspreadsheet": "^1.23"
|
"phpoffice/phpspreadsheet": "^1.23",
|
||||||
|
"robmorgan/phinx": "^0.13.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
config/phinx.php
Normal file
38
config/phinx.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once(realpath(dirname(__FILE__)."/../config/config.php"));
|
||||||
|
|
||||||
|
return
|
||||||
|
[
|
||||||
|
'paths' => [
|
||||||
|
'migrations' => BASEDIR."/db/migrations",
|
||||||
|
'seeds' => BASEDIR."/db/seeds"
|
||||||
|
],
|
||||||
|
'environments' => [
|
||||||
|
'default_migration_table' => 'phinxlog',
|
||||||
|
'default_environment' => 'thetool',
|
||||||
|
'thetool' => [
|
||||||
|
'adapter' => 'mysql',
|
||||||
|
'host' => FRONKDB_DBHOST,
|
||||||
|
'name' => FRONKDB_DBNAME,
|
||||||
|
'user' => FRONKDB_DBUSER,
|
||||||
|
'pass' => FRONKDB_DBPASS,
|
||||||
|
'port' => '3306',
|
||||||
|
'charset' => 'utf8',
|
||||||
|
],
|
||||||
|
'addressdb' => [
|
||||||
|
'adapter' => 'mysql',
|
||||||
|
'host' => ADDRESSDB_DBHOST,
|
||||||
|
'name' => ADDRESSDB_DBNAME,
|
||||||
|
'user' => ADDRESSDB_DBUSER,
|
||||||
|
'pass' => ADDRESSDB_DBPASS,
|
||||||
|
'port' => '3306',
|
||||||
|
'charset' => 'utf8',
|
||||||
|
],
|
||||||
|
|
||||||
|
],
|
||||||
|
'version_order' => 'creation',
|
||||||
|
'templates' => [
|
||||||
|
"file" => BASEDIR."/db/template/migrate.up_down.template"
|
||||||
|
]
|
||||||
|
];
|
||||||
88
db/migrations/20230905130832_add_can_permissions.php
Normal file
88
db/migrations/20230905130832_add_can_permissions.php
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class AddCanPermissions extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
// only run in thetool Env
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
$new_perms = [
|
||||||
|
"canBuilding",
|
||||||
|
"canPipework",
|
||||||
|
"canLinework",
|
||||||
|
"canPatching",
|
||||||
|
"canFilestore",
|
||||||
|
"canCpeprovisioning",
|
||||||
|
"canCpeshipping",
|
||||||
|
"canVoipnumbering",
|
||||||
|
"canPreorder",
|
||||||
|
"canOrder"
|
||||||
|
];
|
||||||
|
|
||||||
|
$table = $this->table("WorkerPermission");
|
||||||
|
|
||||||
|
$setAllTrue = "";
|
||||||
|
|
||||||
|
$after = "preorderaddressreporting";
|
||||||
|
foreach($new_perms as $p) {
|
||||||
|
$table->addColumn($p, "enum", ["values" => 'false,true', "default" => "false", "after" => $after]);
|
||||||
|
$after = $p;
|
||||||
|
$setAllTrue .= "`$p` = 'true', ";
|
||||||
|
}
|
||||||
|
$table->update();
|
||||||
|
|
||||||
|
$setAllTrue = substr($setAllTrue, 0, strlen($setAllTrue) -2);
|
||||||
|
|
||||||
|
//echo "$setAllTrue\n";
|
||||||
|
|
||||||
|
$builder = $this->getQueryBuilder();
|
||||||
|
$q = $builder->select("*")->from("WorkerPermission")->execute();
|
||||||
|
|
||||||
|
while($perm = $q->fetch('assoc')) {
|
||||||
|
$id = $perm["id"];
|
||||||
|
|
||||||
|
if($perm["admin"] == "true") {
|
||||||
|
$this->query("UPDATE WorkerPermission SET $setAllTrue WHERE id=$id");
|
||||||
|
} elseif($perm["preorderfront"] == "false" && $perm['preorderaddressreporting'] == "false") {
|
||||||
|
$this->query("UPDATE WorkerPermission SET $setAllTrue WHERE id=$id");
|
||||||
|
} else {
|
||||||
|
$this->query("UPDATE WorkerPermission SET `canPreorder` = 'true' WHERE id=$id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
// do nothing in addressdb Env
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
|
||||||
|
$table = $this->table("WorkerPermission");
|
||||||
|
$table->removeColumn("canOrder");
|
||||||
|
$table->removeColumn("canPreorder");
|
||||||
|
$table->removeColumn("canVoipnumbering");
|
||||||
|
$table->removeColumn("canCpeshipping");
|
||||||
|
$table->removeColumn("canCpeprovisioning");
|
||||||
|
$table->removeColumn("canFilestore");
|
||||||
|
$table->removeColumn("canPatching");
|
||||||
|
$table->removeColumn("canLinework");
|
||||||
|
$table->removeColumn("canPipework");
|
||||||
|
$table->removeColumn("canBuilding");
|
||||||
|
$table->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
db/template/migrate.change.template
Normal file
29
db/template/migrate.change.template
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
$namespaceDefinition
|
||||||
|
use $useClassName;
|
||||||
|
|
||||||
|
final class $className extends $baseClassName
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
db/template/migrate.up_down.template
Normal file
29
db/template/migrate.up_down.template
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
$namespaceDefinition
|
||||||
|
use $useClassName;
|
||||||
|
|
||||||
|
final class $className extends $baseClassName
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user