Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions db/mysql/FileMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


/**
* Class MysqlFileMigration
* Class FileMigration
* @package common\components
* @author Tobias Munk <tobias@diemeisterei.de>
*/
Expand Down Expand Up @@ -79,4 +79,4 @@ public function down()
return false;
}

}
}
56 changes: 56 additions & 0 deletions db/mysql/FileOverConnectionMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* @link http://www.diemeisterei.de/
* @copyright Copyright (c) 2014 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace dmstr\db\mysql;

use mikehaertl\shellcommand\Command;
use yii\base\Exception;
use yii\db\Migration;


/**
* Class FileOverConnectionMigration
* @package common\components
* @author Dmitry Derepko <xepozz@list.ru>
*/
class FileOverConnectionMigration extends Migration
{
public $file = null;
public $mysqlExecutable = 'mysql';

public function init()
{
parent::init();

if ($this->file === null) {
$reflection = new \ReflectionClass($this);
$this->file = str_replace('.php', '.sql', $reflection->getFileName());
} else {
$reflection = new \ReflectionClass($this);
$this->file = dirname($reflection->getFileName()).DIRECTORY_SEPARATOR.$this->file;
}

if (!is_file($this->file)) {
throw new Exception("File {$this->file} not found");
}
}

public function up()
{
$sql = file_get_contents($this->file);

$this->db->createCommand($sql)->execute();
}

public function down()
{
echo get_class($this) . " cannot be reverted.\n";
return false;
}
}