Create Optimizer Query table.

@param \Magento\Framework\Setup\SchemaSetupInterface $setup Setup instance
193562
public function createOptimizerSearchContainerTable(SchemaSetupInterface $setup)
    {
        if (!$setup->getConnection()->isTableExists($setup->getTable(OptimizerInterface::TABLE_NAME_SEARCH_CONTAINER))) {
            $table = $setup->getConnection()
                ->newTable($setup->getTable(OptimizerInterface::TABLE_NAME_SEARCH_CONTAINER))
                ->addColumn(
                    OptimizerInterface::OPTIMIZER_ID,
                    \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                    null,
                    ['nullable' => false, 'primary' => true],
                    'Optimizer ID'
                )
                ->addColumn(
                    OptimizerInterface::SEARCH_CONTAINER,
                    \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                    255,
                    ['nullable' => false, 'primary' => true],
                    'Search Container'
                )
                ->addColumn(
                    'apply_to',
                    \Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN,
                    null,
                    ['nullable' => false, 'default' => 0],
                    'If this optimizer applies to specific entities or not.'
                )
                ->addIndex(
                    $setup->getIdxName(OptimizerInterface::TABLE_NAME, [OptimizerInterface::SEARCH_CONTAINER]),
                    [OptimizerInterface::SEARCH_CONTAINER]
                )
                ->addForeignKey(
                    $setup->getFkName(
                        OptimizerInterface::TABLE_NAME_SEARCH_CONTAINER,
                        OptimizerInterface::OPTIMIZER_ID,
                        OptimizerInterface::TABLE_NAME,
                        OptimizerInterface::OPTIMIZER_ID
                    ),
                    OptimizerInterface::OPTIMIZER_ID,
                    $setup->getTable(OptimizerInterface::TABLE_NAME),
                    OptimizerInterface::OPTIMIZER_ID,
                    \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
                )
                ->setComment('Query type per optimizer table');

            $setup->getConnection()->createTable($table);
        }
    }
1225919
protected function registerSetupCommand($binding)
    {
        $this->app->singleton($binding, function ($app) {
            return new Setup($app['config'], $app['db']);
        });
    }
468098
protected function createTable(SchemaAsset $schema, ModelInterface $model)
    {
        $table = $schema->createTable($this->quoteIdentifier($model->table()));

        foreach ($model->fields() as $field) {
            $table->addColumn(
                $this->quoteIdentifier($field->mappedName()),
                $field->type(),
                $field->attributes()
            );
        }

        foreach ($model->indexes() as $index) {
            switch ($index->type()) {
                case 'primary':
                    $table->setPrimaryKey(
                        $this->quoteIdentifier($index->fields()),
                        $this->quoteIdentifier($index->name())
                    );
                    break;
                case 'unique':
                    $table->addUniqueIndex(
                        $this->quoteIdentifier($index->fields()),
                        $this->quoteIdentifier($index->name())
                    );
                    break;
                case 'foreign':
                    $table->addForeignKeyConstraint(
                        $index->table(),
                        $this->quoteIdentifier(array_keys($index->fields())),
                        $this->quoteIdentifier(array_values($index->fields())),
                        ['onUpdate' => 'CASCADE', 'onDelete' => 'RESTRICT'],
                        $this->quoteIdentifier($index->name())
                    );
                    break;
                case 'index':
                default:
                    $table->addIndex(
                        $this->quoteIdentifier($index->fields()),
                        $this->quoteIdentifier($index->name())
                    );
            }
        }
    }
616073
public function createExpansionReferenceTable(SchemaSetupInterface $setup)
    {
        $table = $setup->getConnection()
            ->newTable($setup->getTable(ThesaurusInterface::REFERENCE_TABLE_NAME))
            ->addColumn(
                ThesaurusInterface::THESAURUS_ID,
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                null,
                ['unsigned' => true, 'nullable' => false, 'primary' => true],
                'Thesaurus Id'
            )->addColumn(
                'term_id',
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                null,
                ['unsigned' => true, 'nullable' => false, 'primary' => true],
                'Reference Term Id'
            )
            ->addColumn(
                'term',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                ['nullable' => false],
                'Reference Term'
            )->addForeignKey(
                $setup->getFkName(
                    ThesaurusInterface::REFERENCE_TABLE_NAME,
                    ThesaurusInterface::THESAURUS_ID,
                    ThesaurusInterface::TABLE_NAME,
                    ThesaurusInterface::THESAURUS_ID
                ),
                ThesaurusInterface::THESAURUS_ID,
                $setup->getTable(ThesaurusInterface::TABLE_NAME),
                ThesaurusInterface::THESAURUS_ID,
                \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
            )->setComment('Smile ElasticSuite Thesaurus Table for link between thesauri and reference terms');

        $setup->getConnection()->createTable($table);
    }
888856
private function upgradeTblSale($setup)
    {
        $conn = $setup->getConnection();
        $table = $setup->getTable(EPartSale::ENTITY_NAME);

        /* add columns */
        $conn->addColumn(
            $table,
            EPartSale::A_TRANS_REF,
            [
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                'length' => null,
                'unsigned' => true,
                'nullable' => false,
                'after' => EPartSale::A_SALE_ORDER_REF,
                'comment' => 'Transaction Reference.'
            ]
        );
        $conn->addColumn(
            $table,
            EPartSale::A_BASE_CURRENCY,
            [
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'length' => 3,
                'nullable' => false,
                'after' => EPartSale::A_BASE_PARTIAL_AMOUNT,
                'comment' => 'Currency code for base amount (stock/warehouse currency).'
            ]
        );
        $conn->addColumn(
            $table,
            EPartSale::A_CURRENCY,
            [
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'length' => 3,
                'nullable' => false,
                'after' => EPartSale::A_PARTIAL_AMOUNT,
                'comment' => 'Currency code for amount (payment??? currency).'
            ]
        );

        /* add foreign keys */
        $tbl = $setup->getTable(EPartSale::ENTITY_NAME);
        $tblRef = $setup->getTable(EAccTran::ENTITY_NAME);
        $fkName = $setup->getFkName($tbl, $tblRef, EPartSale::A_TRANS_REF, EAccTran::A_ID);
        $conn->addForeignKey($fkName, $tbl, EPartSale::A_TRANS_REF, $tblRef, EAccTran::A_ID);
    }
694586
public function createOptimizerLimitationTable(SchemaSetupInterface $setup)
    {
        if (!$setup->getConnection()->isTableExists($setup->getTable(OptimizerInterface::TABLE_NAME_LIMITATION))) {
            $categoryIdField = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\CategoryInterface::class)->getIdentifierField();

            $optimizerCategoryTable = $setup->getConnection()
                ->newTable($setup->getTable(OptimizerInterface::TABLE_NAME_LIMITATION))
                ->addColumn(
                    OptimizerInterface::OPTIMIZER_ID,
                    \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                    null,
                    ['nullable' => false],
                    'Optimizer ID'
                )
                ->addColumn(
                    'category_id',
                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    null,
                    ['unsigned' => true, 'nullable' => true, 'default' => null],
                    'Category ID'
                )
                ->addColumn(
                    'query_id',
                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    null,
                    ['unsigned' => true, 'nullable' => true, 'default' => null],
                    'Query ID'
                )
                ->addForeignKey(
                    $setup->getFkName(
                        OptimizerInterface::TABLE_NAME_LIMITATION,
                        OptimizerInterface::OPTIMIZER_ID,
                        OptimizerInterface::TABLE_NAME,
                        OptimizerInterface::OPTIMIZER_ID
                    ),
                    OptimizerInterface::OPTIMIZER_ID,
                    $setup->getTable(OptimizerInterface::TABLE_NAME),
                    OptimizerInterface::OPTIMIZER_ID,
                    \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
                )
                ->addForeignKey(
                    $setup->getFkName(
                        OptimizerInterface::TABLE_NAME_LIMITATION,
                        'category_id',
                        'catalog_category_entity',
                        $categoryIdField
                    ),
                    'category_id',
                    $setup->getTable('catalog_category_entity'),
                    $categoryIdField,
                    \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
                )
                ->addForeignKey(
                    $setup->getFkName(OptimizerInterface::TABLE_NAME_LIMITATION, 'query_id', 'search_query', 'query_id'),
                    'query_id',
                    $setup->getTable('search_query'),
                    'query_id',
                    \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
                )
                ->addIndex(
                    $setup->getIdxName(
                        OptimizerInterface::TABLE_NAME_LIMITATION,
                        [OptimizerInterface::OPTIMIZER_ID, 'category_id', 'query_id'],
                        \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
                    ),
                    [OptimizerInterface::OPTIMIZER_ID, 'category_id', 'query_id'],
                    ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
                )
                ->setComment('Search optimizer limitation Table');

            $setup->getConnection()->createTable($optimizerCategoryTable);
        }
    }
550495
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();
        $connection = $installer->getConnection();

        /**
         * Create table 'faonni_catalog_product_index_sale'
         */
        if (!$installer->tableExists('faonni_catalog_product_index_sale')) {
			$table = $connection
				->newTable($installer->getTable('faonni_catalog_product_index_sale'))
				->addColumn(
					'entity_id',
					Table::TYPE_INTEGER,
					null,
					['unsigned' => true, 'nullable' => false, 'primary' => true],
					'Entity Id'
				)
				->addColumn(
					'website_id',
					Table::TYPE_SMALLINT,
					null,
					['unsigned' => true, 'nullable' => false, 'primary' => true],
					'Website ID'
				)				
				->addIndex(
					$installer->getIdxName('faonni_catalog_product_index_sale', ['website_id']),
					['website_id']
				)				
				->addForeignKey(
					$installer->getFkName('faonni_catalog_product_index_sale', 'website_id', 'store_website', 'website_id'),
					'website_id',
					$installer->getTable('store_website'),
					'website_id',
					Table::ACTION_CASCADE
				)
				->addForeignKey(
					$installer->getFkName('faonni_catalog_product_index_sale', 'entity_id', 'catalog_product_entity', 'entity_id'),
					'entity_id',
					$installer->getTable('catalog_product_entity'),
					'entity_id',
					Table::ACTION_CASCADE
				)
				->setComment('Catalog Product Sale Index Table');

			$connection->createTable($table);		
		} 

        $installer->endSetup();
    }
69141
public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $statuses = [
            'pagseguro_iniciado',
            'pagseguro_aguardando_pagamento',
            'pagseguro_cancelada',
            'pagseguro_chargeback_debitado',
            'pagseguro_devolvida',
            'pagseguro_disponivel',
            'pagseguro_em_analise',
            'pagseguro_em_contestacao',
            'pagseguro_em_disputa',
            'pagseguro_paga'
        ];
        
        $paths = [
            'pagseguro/store/reference',
            'payment/pagseguro/active',
            'payment/pagseguro/title',
            'payment/pagseguro/email',
            'payment/pagseguro/token',
            'payment/pagseguro/redirect',
            'payment/pagseguro/notification',
            'payment/pagseguro/charset',
            'payment/pagseguro/log',
            'payment/pagseguro/log_file',
            'payment/pagseguro/checkout',
            'payment/pagseguro/environment',
            'payment/pagseguro/abandoned_active'
        ];

        $setup->startSetup();
        $this->dropPagSeguroOrdersTable($setup);
        $this->dropColumnsFromSalesOrderGrid($setup);
        $this->removeDataFromSalesOrderStatus($setup, $statuses);
        $this->removeDataFromSalesOrderStatusState($setup, $statuses);
        $this->removeDataFromCoreConfigData($setup, $paths);
        $setup->endSetup();
    }
765391
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();

        $setup->getConnection()->addColumn(
            $setup->getTable('quote'),
            'bolt_parent_quote_id',
            [
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                'nullable' => true,
                'default' => null,
                'unsigned' => true,
                'comment' => 'Original Quote ID'
            ]
        );

        $setup->getConnection()->addColumn(
            $setup->getTable('quote'),
            'bolt_reserved_order_id',
            [
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'length' => 64,
                'nullable' => true,
                'comment' => 'Bolt Reserved Order Id'
            ]
        );

        $setup->getConnection()->addIndex(
            $setup->getTable('quote'),
            $setup->getIdxName('quote', ['bolt_parent_quote_id']),
            ['bolt_parent_quote_id']
        );

        $setup->endSetup();
    }
937409
public static function create($table = null, $assignment = array(), $where = array())
    {
        return Injector::inst()->createWithArgs(__CLASS__, func_get_args());
    }
162651
public function appendIsActiveColumn(SchemaSetupInterface $setup)
    {
        $setup->getConnection()->addColumn(
            $setup->getTable(ThesaurusInterface::TABLE_NAME),
            ThesaurusInterface::IS_ACTIVE,
            [
                'type'     => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                'nullable' => false,
                'default'  => 1,
                'comment'  => 'If the Thesaurus is active',
            ]
        );
    }
513182
private function addIndexKeyForCatalog(
        SchemaSetupInterface $setup,
        \Magento\Framework\DB\Adapter\AdapterInterface $connection
    ) {
        $connection->addForeignKey(
            $setup->getFkName(
                Schema::EMAIL_CATALOG_TABLE,
                'product_id',
                'catalog_product_entity',
                'entity_id'
            ),
            $setup->getTable(Schema::EMAIL_CATALOG_TABLE),
            'product_id',
            $setup->getTable('catalog_product_entity'),
            'entity_id',
            \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
        );
    }
225833
protected function createQuery()
    {
        if (!$this->queryCreated) {
            $this->setBaseQuery();
            $this->filter('fvIsApproved', 1);
            $this->setupAttributeFilters("left join FileSearchIndexAttributes on (fv.fID = FileSearchIndexAttributes.fID)");
            $this->setupFilePermissions();
            $this->setupFileSetFilters();
            $this->queryCreated = 1;
        }
    }
203307
def _set_table(self, schema, **kwargs):
        
        query_str = []
        query_str.append("CREATE TABLE {} (".format(self._normalize_table_name(schema)))

        query_fields = []
        for field_name, field in schema.fields.items():
            query_fields.append('  {}'.format(self.get_field_SQL(field_name, field)))

        query_str.append(",{}".format(os.linesep).join(query_fields))
        query_str.append(')')
        query_str = os.linesep.join(query_str)
        ret = self._query(query_str, ignore_result=True, **kwargs)
635283
public function buildQuery(string $table, array $set, array $where): SqlParams
    {
        if (empty($set) || empty($where)) {
            throw new \Exception('Set and where arrays cannot be empty');
        }

        $params = [];
        $sql = "UPDATE {$table} SET ";

        foreach ($set as $column => $value) {
            $sql .= $this->options->escapeIdentifier($column) . ' = ?, ';
            $params[] = $value;
        }

        $sql = substr_replace($sql, '', -2); // remove trailing comma
        $whereClause = $this->buildWhereClause($where);
        $sql .= $whereClause->getSql();

        return new SqlParams($sql, array_merge($params, $whereClause->getParams()));
    }
485071
private function convertDataForConfig(SchemaSetupInterface $setup, $connection)
    {
        $configTable = $setup->getTable('core_config_data');
        //customer and order custom attributes from config
        $select = $connection->select()->from(
            $configTable
        )->where(
            'path IN (?)',
            [
                'connector_automation/order_status_automation/program',
                'connector_data_mapping/customer_data/custom_attributes'
            ]
        );
        $rows = $setup->getConnection()->fetchAssoc($select);

        $serializedRows = array_filter($rows, function ($row) {
            return $this->isSerialized($row['value']);
        });

        foreach ($serializedRows as $id => $serializedRow) {
            $convertedValue = $this->json->serialize($this->unserialize($serializedRow['value']));
            $bind = ['value' => $convertedValue];
            $where = [$connection->quoteIdentifier('config_id') . '=?' => $id];
            $connection->update($configTable, $bind, $where);
        }
    }
668532
public function optimize($table = null)
        {
            $table = empty($table) ? $this->_tableName : $table;
            $this->_query("OPTIMIZE TABLE " . $table);

            return $this;
        }