-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from myaghobi/2.0
2.0
- Loading branch information
Showing
14 changed files
with
12,389 additions
and
922 deletions.
There are no files selected for viewing
This file contains 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 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 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,47 @@ | ||
<?php | ||
|
||
/** | ||
* @package F3 Migrations, MigrationCase | ||
* @version 2.0.1 | ||
* @link http://github.com/myaghobi/F3-Migrations Github | ||
* @author Mohammad Yaghobi <[email protected]> | ||
* @copyright Copyright (c) 2021, Mohammad Yaghobi | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 | ||
*/ | ||
|
||
namespace DB\MIGRATIONS; | ||
|
||
class MigrationCase { | ||
/** | ||
* this method will call on upgrade | ||
* | ||
* @param object $f3 | ||
* @param object $db | ||
* @param object $schema | ||
* @return bool | ||
*/ | ||
public function up($f3, $db, $schema) { | ||
// your cods here | ||
|
||
// return TRUE when the upgrade be successful | ||
return true; | ||
} | ||
|
||
|
||
/** | ||
* this method will call on upgrade | ||
* | ||
* @param object $f3 | ||
* @param object $db | ||
* @param object $schema | ||
* @return bool | ||
*/ | ||
public function down($f3, $db, $schema) { | ||
// your cods here | ||
|
||
// return TRUE when the downgrade be successful | ||
return true; | ||
} | ||
} | ||
|
||
?> |
This file contains 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,94 @@ | ||
<?php | ||
|
||
/** | ||
* @package F3 Migrations, MigrationCaseItem | ||
* @version 2.0.1 | ||
* @link http://github.com/myaghobi/F3-Migrations Github | ||
* @author Mohammad Yaghobi <[email protected]> | ||
* @copyright Copyright (c) 2021, Mohammad Yaghobi | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 | ||
*/ | ||
|
||
namespace DB\MIGRATIONS; | ||
|
||
use DB\MIGRATIONS\Migrations; | ||
|
||
class MigrationCaseItem { | ||
public $file; | ||
public $name; | ||
public $version; | ||
public $timestamp; | ||
public $content; | ||
public $valid; | ||
|
||
private $casePrefix; | ||
private $f3; | ||
|
||
|
||
/** | ||
* constructor | ||
* | ||
* @param string $path | ||
* @return void | ||
*/ | ||
function __construct($path=null) { | ||
$this->f3 = \Base::instance(); | ||
|
||
$this->casePrefix = $this->f3->get('migrations.CASE_PREFIX') ?: 'migration_case_'; | ||
|
||
$this->valid = false; | ||
$this->parsByFile($path); | ||
} | ||
|
||
|
||
/** | ||
* pars attrs with path | ||
* | ||
* @param string $path | ||
* @return void | ||
*/ | ||
function parsByFile($path=null) { | ||
$this->valid = false; | ||
|
||
if (!$path || !file_exists($path)) { | ||
return; | ||
} | ||
|
||
$this->file = $path; | ||
|
||
$fileName = pathinfo($path)['basename']; | ||
preg_match('/' . $this->casePrefix . '(.*?)(\d+(\.\d+)*)?_(\d+).php/', $fileName, $matches); | ||
if ($matches) { | ||
$this->name = $matches[1]; | ||
$this->version = $matches[2]; | ||
$this->timestamp = $matches[4]; | ||
} | ||
|
||
$fileContent = file_get_contents($path); | ||
|
||
if (preg_match('/class\s+(\w+)\s+extends/', $fileContent, $matches)) { | ||
$str = str_replace($matches[0], 'new class() extends', $fileContent) . ';'; | ||
$this->content = $str; | ||
} | ||
|
||
$this->valid = true; | ||
} | ||
|
||
|
||
/** | ||
* find a migration case by timestamp | ||
* | ||
* @param string $path | ||
* @return void | ||
*/ | ||
function findByTimestamp($timestamp) { | ||
$this->valid = false; | ||
|
||
$result = glob(Migrations::$path.$this->casePrefix.'*_'.$timestamp.'.php'); | ||
if (count($result)==1) { | ||
$this->parsByFile($result[0]); | ||
} | ||
} | ||
} | ||
|
||
?> |
This file contains 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,29 @@ | ||
<?php | ||
|
||
namespace DB\MIGRATIONS; | ||
// the class name can be duplicate | ||
class MigrationCaseSample extends \DB\MIGRATIONS\MigrationCase { | ||
// this method will call on upgrade | ||
public function up($f3, $db, $schema) { | ||
// your cods here | ||
|
||
// e.g. https://github.com/ikkez/f3-schema-builder#create-tables | ||
// $table = $schema->createTable('products'); | ||
// $table->addColumn('title')->type($schema::DT_VARCHAR128); | ||
// $table->addColumn('description')->type($schema::DT_TEXT); | ||
// $table->build(); | ||
|
||
// return TRUE when the upgrade be successful | ||
return true; | ||
} | ||
|
||
// this method will call on downgrade | ||
public function down($f3, $db, $schema) { | ||
// your cods here | ||
// $schema->dropTable('products'); | ||
|
||
// return TRUE when the downgrade be successful | ||
return true; | ||
} | ||
} | ||
?> |
Oops, something went wrong.