public function __construct(Table $before, Table $after) { $this->before = $before; $this->after = $after; $this->bindDatabase($before->database()); $this->alterExpression = new SimpleExpression('ALTER TABLE ?' . PHP_EOL, new Symbol($this->after->schemaName)); $this->alterLines = new SimpleExpression(); $this->alterLines->setOpComma(',' . PHP_EOL); $this->add($this->alterExpression); $this->alterExpression->appendExpr($this->alterLines); $this->processColumns(); $this->processIndexes(); $this->addFkExpression = new SimpleExpression(); $this->processForeignKeys(); $this->alterExpression->appendExpr($this->addFkExpression); if ($this->alterLines->isEmpty()) { $this->alterExpression->disable(); } }
public function __construct(Table $table) { $this->table = $table; $this->bindDatabase($table->database()); $this->createLines = new SimpleExpression(); $this->createLines->setOpComma(',' . PHP_EOL); $this->fkLines = new SimpleExpression(); $this->fkLines->setOpComma(',' . PHP_EOL); $createExpression = new SimpleExpression('CREATE TABLE ? (' . PHP_EOL, $this->table); $this->add($createExpression); $createExpression->appendExpr($this->createLines); $createExpression->appendExpr(PHP_EOL . ')'); $this->appendColumns(); $this->appendIndexes(); $this->createLines->commaExpr($this->fkLines); $this->appendForeignKeys(); $this->appendPrimaryKey(); if ($this->createLines->isEmpty()) { $createExpression->disable(); } }