29 private $statementDirectives = [
30 self::ALTER_TYPE =>
'ALTER TABLE %s %s',
31 self::CREATE_TYPE =>
'CREATE TABLE %s %s',
32 self::DROP_TYPE =>
'DROP TABLE %s' 40 private $tableOptions = [
41 'charset' =>
'DEFAULT CHARSET',
42 'collation' =>
'DEFAULT COLLATE',
44 'comment' =>
'COMMENT' 50 private $resourceConnection;
55 private $statementFactory;
60 private $dryRunLogger;
72 array $tableOptions = []
75 $this->statementFactory = $statementFactory;
76 $this->dryRunLogger = $dryRunLogger;
77 $this->tableOptions = array_replace($this->tableOptions, $tableOptions);
86 "(\n%s\n) ENGINE=%s DEFAULT CHARSET=%s DEFAULT COLLATE=%s %s",
87 implode(
", \n", $definition),
91 isset(
$options[
'comment']) ? sprintf(
'COMMENT="%s"',
$options[
'comment']) :
'' 94 return $this->statementFactory->create(
110 return $this->statementFactory->create(
128 private function getDropElementSQL(
$type,
$name)
132 return 'DROP PRIMARY KEY';
134 return sprintf(
'DROP KEY %s',
$name);
135 case \Magento\Framework\Setup\Declaration\Schema\Dto\Index::TYPE:
136 return sprintf(
'DROP INDEX %s',
$name);
138 return sprintf(
'DROP FOREIGN KEY %s',
$name);
140 return sprintf(
'DROP COLUMN %s',
$name);
151 $addElementSyntax = $elementType ===
Column::TYPE ?
'ADD COLUMN %s' :
'ADD %s';
156 return $this->statementFactory->create(
171 return $this->statementFactory->create(
175 sprintf(
"%s='%s'", $this->tableOptions[$optionName],
$optionValue),
191 return $this->statementFactory->create(
209 $this->getDropElementSQL(
214 return $this->statementFactory->create(
229 $sql =
'AUTO_INCREMENT = 1';
230 return $this->statementFactory->create(
231 sprintf(
'RESET_AUTOINCREMENT_%s',
$tableName),
247 foreach ($statementBank as $statement) {
248 $statementsSql[] = $statement->getStatement();
250 $adapter = $this->resourceConnection->getConnection($statement->getResource());
253 $this->dryRunLogger->log(
255 $this->statementDirectives[$statement->getType()],
256 $adapter->quoteIdentifier($statement->getTableName()),
257 implode(
", ", $statementsSql)
263 $this->statementDirectives[$statement->getType()],
264 $adapter->quoteIdentifier($statement->getTableName()),
265 implode(
", ", $statementsSql)
269 foreach ($statement->getTriggers() as
$trigger) {
resetAutoIncrement($tableName, $resource)
createTable($tableName, $resource, array $definition, array $options)
call_user_func($callable, $param)
addElement($elementName, $resource, $tableName, $elementDefinition, $elementType)
__construct(ResourceConnection $resourceConnection, StatementFactory $statementFactory, DryRunLogger $dryRunLogger, array $tableOptions=[])
dropElement($resource, $elementName, $tableName, $type)
modifyColumn($columnName, $resource, $tableName, $columnDefinition)
dropTable($tableName, $resource)
modifyTableOption($tableName, $resource, $optionName, $optionValue)
compile(StatementAggregator $statementAggregator, $dryRun)
if(!isset($_GET['name'])) $name