Example #1
0
 public function run($options = array())
 {
     Yentu::greet();
     $this->db = DatabaseManipulator::create();
     $this->initializeCodeWriter();
     $files = scandir(Yentu::getPath("migrations"));
     if (count($files) > 2) {
         throw new \yentu\exceptions\CommandException("Cannot run imports. Your migrations directory is not empty");
     }
     $description = $this->db->getDescription();
     $this->code->add('begin()');
     if (isset($description['schemata'])) {
         $this->importSchemata($description['schemata']);
     }
     if (isset($description['tables'])) {
         $this->importTables($description['tables']);
     }
     if (isset($description['views'])) {
         $this->importViews($description['views']);
     }
     $this->importForeignKeys();
     $this->code->add('->end();');
     $this->newVersion = date('YmdHis', time());
     $path = Yentu::getPath("migrations/{$this->newVersion}_import.php");
     file_put_contents($path, $this->code);
     \clearice\ClearIce::output("Created `{$path}`\n");
     if (!$this->db->getAssertor()->doesTableExist('yentu_history')) {
         $this->db->createHistory();
     }
     $this->db->setVersion($this->newVersion);
     $this->db->disconnect();
     return $description;
 }
Example #2
0
 public function setUp()
 {
     $this->testDatabase = 'yentu_rollback_test';
     parent::setup();
     $this->createDb($GLOBALS['DB_NAME']);
     $this->initDb($GLOBALS['DB_FULL_DSN'], file_get_contents("tests/sql/{$GLOBALS['DRIVER']}/pre_rollback.sql"));
     $this->connect($GLOBALS['DB_FULL_DSN']);
     $this->setupStreams();
     $init = new \yentu\commands\Init();
     $init->createConfigFile(array('driver' => $GLOBALS['DRIVER'], 'host' => $GLOBALS['DB_HOST'], 'dbname' => $GLOBALS["DB_NAME"], 'user' => $GLOBALS['DB_USER'], 'password' => $GLOBALS['DB_PASSWORD'], 'file' => $GLOBALS['DB_FILE']));
     Config::readPath(\yentu\Yentu::getPath('config'), 'yentu');
 }
Example #3
0
 public function __construct($message)
 {
     parent::__construct($message);
     foreach ($this->getTrace() as $item) {
         if (!isset($item['file'])) {
             continue;
         }
         if (realpath(Yentu::getPath('migrations')) === dirname($item['file'])) {
             $this->message .= ". Exception was thrown by action on line {$item['line']} of {$item['file']}";
             break;
         }
     }
 }
Example #4
0
 public function createFile($name)
 {
     $this->checkExisting($name);
     $this->checkName($name);
     $this->checkPermission();
     $timestamp = date('YmdHis', time());
     $code = new \yentu\CodeWriter();
     $code->add('');
     $code->add('begin()');
     $code->add('');
     $code->add('->end();');
     $path = Yentu::getPath("migrations/{$timestamp}_{$name}.php");
     file_put_contents($path, $code);
     \clearice\ClearIce::output("Added {$path} for new migration.\n");
 }
Example #5
0
 /**
  * Returns information about all migration paths.
  * Yentu can be configured to use multiple migration homes, for multiple
  * database configurations. This makes it possible to use a single command
  * to run multiple migrations accross multiple databases.
  * @return array
  */
 public static function getMigrationPathsInfo()
 {
     $variables = Config::get('default.variables', []);
     $otherMigrations = Config::get('default.other_migrations', []);
     return array_merge(array(array('home' => Yentu::getPath('migrations'), 'variables' => $variables)), $otherMigrations);
 }
Example #6
0
File: cli.php Project: codogh/yentu
ClearIce::setFootnote("Report bugs to jainooson@gmail.com");
ClearIce::setUsage("[command] [options]");
ClearIce::addHelp();
ClearIce::setStrict(true);
$options = ClearIce::parse();
if (isset($options['verbose'])) {
    ClearIce::setOutputLevel($options['verbose']);
}
try {
    if (isset($options['__command__'])) {
        if (isset($options['home'])) {
            Yentu::setDefaultHome($options['home']);
        }
        $class = "\\yentu\\commands\\" . ucfirst($options['__command__']);
        unset($options['__command__']);
        Config::readPath(Yentu::getPath('config'), 'yentu');
        $command = new $class();
        $command->run($options);
    } else {
        ClearIce::output(ClearIce::getHelpMessage());
    }
} catch (\yentu\exceptions\CommandException $e) {
    ClearIce::resetOutputLevel();
    ClearIce::error("Error! " . $e->getMessage() . "\n");
} catch (\ntentan\atiaa\exceptions\DatabaseDriverException $e) {
    ClearIce::resetOutputLevel();
    ClearIce::error("Database driver failed: " . $e->getMessage() . "\n");
    Yentu::reverseCommand($command);
} catch (\yentu\exceptions\DatabaseManipulatorException $e) {
    ClearIce::resetOutputLevel();
    ClearIce::error("Failed to perform database action: " . $e->getMessage() . "\n");
Example #7
0
 public function run($options = array())
 {
     Yentu::greet();
     if (file_exists(Yentu::getPath(''))) {
         throw new CommandException("Could not initialize yentu. Your project has already been initialized with yentu.");
     } else {
         if (!is_writable(dirname(Yentu::getPath('')))) {
             throw new CommandException("Your current directory is not writable.");
         }
     }
     $params = $this->getParams($options);
     if (count($params) == 0 && defined('STDOUT')) {
         global $argv;
         throw new CommandException("You didn't provide any parameters for initialization. Please execute " . "`{$argv[0]} init -i` to initialize yentu interractively. " . "You can also try `{$argv[0]} init --help` for more information.");
     }
     $this->createConfigFile($params);
     Config::readPath(Yentu::getPath('config'), 'yentu');
     $db = \yentu\DatabaseManipulator::create($params);
     if ($db->getAssertor()->doesTableExist('yentu_history')) {
         throw new CommandException("Could not initialize yentu. Your database has already been initialized with yentu.");
     }
     $db->createHistory();
     $db->disconnect();
     ClearIce::output("Yentu successfully initialized.\n");
 }