/** * update * * @return static */ public function update() { foreach ($this->columns as $column) { $length = $column->getLength(); $length = $length ? '(' . $length . ')' : null; $sequence = null; if ($column->getAutoIncrement()) { $column->type(PostgresqlType::SERIAL); } $query = PostgresqlQueryBuilder::addColumn($this->table, $column->getName(), $column->getType() . $length, $column->getAllowNull(), $column->getDefault()); $this->db->setQuery($query)->execute(); if ($column->getComment()) { $query = PostgresqlQueryBuilder::comment('COLUMN', $this->table, $column->getName(), $column->getComment()); $this->db->setQuery($query)->execute(); } } foreach ($this->indexes as $index) { $query = PostgresqlQueryBuilder::addIndex($this->table, $index->getType(), $index->getName(), $index->getColumns()); $this->db->setQuery($query)->execute(); if ($index->getComment()) { $query = PostgresqlQueryBuilder::comment('INDEX', 'public', $index->getName(), $index->getComment()); $this->db->setQuery($query)->execute(); } } return $this; }
/** * Method to test addColumn(). * * @return void * * @covers Windwalker\Query\Postgresql\PostgresqlQueryBuilder::addColumn */ public function testAddColumn() { $expected = "ALTER TABLE {$this->qn}foo{$this->qn} ADD {$this->qn}bar{$this->qn} int(11) UNSIGNED NOT NULL DEFAULT '1' COMMENT 'Test' FIRST"; $actual = PostgresqlQueryBuilder::addColumn('foo', 'bar', 'int(11)', true, true, '1', 'FIRST', 'Test'); $this->assertEquals(\SqlFormatter::compress($expected), \SqlFormatter::compress($actual)); }
/** * Method to test addColumn(). * * @return void * * @covers Windwalker\Query\Postgresql\PostgresqlQueryBuilder::addColumn */ public function testAddColumn() { $expected = "ALTER TABLE {$this->qn('foo')} ADD {$this->qn('bar')} int(11) NOT NULL DEFAULT '1'"; $actual = PostgresqlQueryBuilder::addColumn('foo', 'bar', 'int(11)', false, '1'); $this->assertEquals($this->format($expected), $this->format($actual)); }