public function __construct($options)
 {
     $this->options = $options;
     $this->table = $options['table'];
     $this->db = Db::connection($options['connection']);
     $this->db->tableExists($this->table) or $this->createTable();
     Config::runningUnitTest() and $this->db->delete($this->table);
 }
 /**
  * Initialize migrations log storage
  *
  * @param array $options Applications options
  * @throws DbException
  */
 private static function connectionSetup($options)
 {
     if (self::$_storage) {
         return;
     }
     if (isset($options['migrationsInDb']) && (bool) $options['migrationsInDb']) {
         /** @var Config $database */
         $database = $options['config']['database'];
         if (!isset($database->adapter)) {
             throw new DbException('Unspecified database Adapter in your configuration!');
         }
         $adapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $database->adapter;
         if (!class_exists($adapter)) {
             throw new DbException('Invalid database Adapter!');
         }
         $configArray = $database->toArray();
         unset($configArray['adapter']);
         self::$_storage = new $adapter($configArray);
         if ($database->adapter === 'Mysql') {
             self::$_storage->query('SET FOREIGN_KEY_CHECKS=0');
         }
         if (!self::$_storage->tableExists(self::MIGRATION_LOG_TABLE)) {
             self::$_storage->createTable(self::MIGRATION_LOG_TABLE, null, ['columns' => [new Column('version', ['type' => Column::TYPE_VARCHAR, 'size' => 255, 'notNull' => true]), new Column('start_time', ['type' => Column::TYPE_TIMESTAMP, 'notNull' => true, 'default' => 'CURRENT_TIMESTAMP']), new Column('end_time', ['type' => 'TIMESTAMP NOT NULL DEFAULT NOW()'])], 'indexes' => [new Index('idx_' . self::MIGRATION_LOG_TABLE . '_version', ['version'])]]);
         }
     } else {
         $path = $options['directory'];
         if (is_file($path . '.phalcon')) {
             unlink($path . '.phalcon');
             mkdir($path . '.phalcon');
             chmod($path . '.phalcon', 0775);
         } elseif (!is_dir($path . '.phalcon')) {
             mkdir($path . '.phalcon');
             chmod($path . '.phalcon', 0775);
         }
         self::$_storage = $path . '.phalcon/migration-version';
         if (!file_exists(self::$_storage)) {
             touch(self::$_storage);
         }
     }
 }