/**
  * 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);
         }
     }
 }
 /**
  * @param \Phalcon\Config $database
  * @throws DbException
  */
 public static function connSetup($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::$_connection = new $adapter($configArray);
     if ($database->adapter == 'Mysql') {
         self::$_connection->query('SET FOREIGN_KEY_CHECKS=0');
     }
     if (!self::$_connection->tableExists('phalcon_migrations')) {
         self::$_connection->execute('CREATE TABLE `phalcon_migrations` (`version` VARCHAR(14) NOT NULL, `start_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `end_time` TIMESTAMP NOT NULL DEFAULT "0000-00-00 00:00:00" ) DEFAULT CHARSET = utf8;');
     }
 }
 /**
  * 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('phalcon_migrations')) {
             self::$_storage->execute("CREATE TABLE `phalcon_migrations` (`version` VARCHAR(255), `start_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `end_time` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' NOT NULL)");
         }
     } 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';
     }
 }