/**
  * {@inheritdoc}
  */
 public function createTables(...$additional_tables)
 {
     $table_names = $this->connection->getTableNames();
     try {
         if (!in_array(self::BATCHES_TABLE_NAME, $table_names)) {
             if ($this->log) {
                 $this->log->info('Creating {table_name} MySQL queue table', ['table_name' => self::BATCHES_TABLE_NAME]);
             }
             $this->connection->execute('CREATE TABLE IF NOT EXISTS `' . self::BATCHES_TABLE_NAME . "` (\n                    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n                    `name` varchar(191) NOT NULL DEFAULT '',\n                    `jobs_count` int(10) unsigned NOT NULL DEFAULT '0',\n                    `created_at` datetime DEFAULT NULL,\n                    PRIMARY KEY (`id`),\n                    KEY (`created_at`)\n                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
         }
         if (!in_array(self::JOBS_TABLE_NAME, $table_names)) {
             if ($this->log) {
                 $this->log->info('Creating {table_name} MySQL queue table', ['table_name' => self::JOBS_TABLE_NAME]);
             }
             $this->connection->execute('CREATE TABLE IF NOT EXISTS `' . self::JOBS_TABLE_NAME . "` (\n                    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n                    `type` varchar(191) CHARACTER SET utf8 NOT NULL DEFAULT '',\n                    `channel` varchar(191) CHARACTER SET utf8 NOT NULL DEFAULT 'main',\n                    `batch_id` int(10) unsigned,\n                    `priority` int(10) unsigned DEFAULT '0',\n                    `data` longtext CHARACTER SET utf8 NOT NULL,\n                    `available_at` datetime DEFAULT NULL,\n                    `reservation_key` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,\n                    `reserved_at` datetime DEFAULT NULL,\n                    `attempts` smallint(6) DEFAULT '0',\n                    `process_id` int(10) unsigned DEFAULT '0',\n                    PRIMARY KEY (`id`),\n                    UNIQUE KEY `reservation_key` (`reservation_key`),\n                    KEY `type` (`type`),\n                    KEY `channel` (`channel`),\n                    KEY `batch_id` (`batch_id`),\n                    KEY `priority` (`priority`),\n                    KEY `reserved_at` (`reserved_at`)\n                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
         }
         if (!in_array(self::FAILED_JOBS_TABLE_NAME, $table_names)) {
             if ($this->log) {
                 $this->log->info('Creating {table_name} MySQL queue table', ['table_name' => self::FAILED_JOBS_TABLE_NAME]);
             }
             $this->connection->execute('CREATE TABLE IF NOT EXISTS `' . self::FAILED_JOBS_TABLE_NAME . "` (\n                    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n                    `type` varchar(191) CHARACTER SET utf8 NOT NULL DEFAULT '',\n                    `channel` varchar(191) CHARACTER SET utf8 NOT NULL DEFAULT 'main',\n                    `batch_id` int(10) unsigned,\n                    `data` longtext CHARACTER SET utf8 NOT NULL,\n                    `failed_at` datetime DEFAULT NULL,\n                    `reason` varchar(191) CHARACTER SET utf8 NOT NULL DEFAULT '',\n                    PRIMARY KEY (`id`),\n                    KEY `type` (`type`),\n                    KEY `channel` (`channel`),\n                    KEY `batch_id` (`batch_id`),\n                    KEY `failed_at` (`failed_at`)\n                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
         }
         foreach ($additional_tables as $additional_table) {
             $this->connection->execute($additional_table);
         }
     } catch (\Exception $e) {
         throw new Exception('Error on create table execute. MySql error message:' . $e->getMessage());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function tearDown()
 {
     $this->connection->execute('SET FOREIGN_KEY_CHECKS = 0');
     foreach ($this->connection->getTableNames() as $table_name) {
         $this->connection->dropTable($table_name);
     }
     $this->connection->execute('SET FOREIGN_KEY_CHECKS = 1');
     $this->connection->disconnect();
     parent::tearDown();
 }
 /**
  * Return name of the table where we store info about executed migrations.
  *
  * @return string
  */
 public function getTableName()
 {
     if ($this->table_exists === null && !in_array($this->table_name, $this->connection->getTableNames())) {
         $this->connection->execute('CREATE TABLE ' . $this->connection->escapeTableName($this->table_name) . ' (
             `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
             `migration` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
             `executed_at` datetime NOT NULL,
             PRIMARY KEY (`id`),
             UNIQUE KEY `migration` (`migration`),
             KEY `executed_on` (`executed_at`)
         ) ENGINE=InnoDB CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;');
         $this->table_exists = true;
     }
     return $this->table_name;
 }
Exemple #4
0
 /**
  * @param ConnectionInterface $connection
  * @param LoggerInterface     $log
  */
 public function __construct(ConnectionInterface &$connection, LoggerInterface &$log)
 {
     $this->connection = $connection;
     $this->log = $log;
     $this->existing_tables = $this->connection->getTableNames();
 }