diff --git a/db/mysql/FileMigration.php b/db/mysql/FileMigration.php index 40f2ad0..438ff74 100755 --- a/db/mysql/FileMigration.php +++ b/db/mysql/FileMigration.php @@ -15,7 +15,7 @@ /** - * Class MysqlFileMigration + * Class FileMigration * @package common\components * @author Tobias Munk */ @@ -79,4 +79,4 @@ public function down() return false; } -} +} diff --git a/db/mysql/FileOverConnectionMigration.php b/db/mysql/FileOverConnectionMigration.php new file mode 100755 index 0000000..ded296d --- /dev/null +++ b/db/mysql/FileOverConnectionMigration.php @@ -0,0 +1,56 @@ + + */ +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; + } +}