/** * @param string|array|Column $column * @return AbstractMigration * @throws IncorrectMethodUsageException */ protected final function dropPrimaryKey($column = 'id') { if ($this->table === null) { throw new IncorrectMethodUsageException('Wrong use of method dropPrimaryKey(). Use method table() first.'); } if (is_string($column)) { $column = new Column($column, 'integer'); } if ($column instanceof Column) { $this->table->changeColumn($column->getName(), $column); } $this->table->dropPrimaryKey(); return $this; }
public function testColumns() { $table = new Table('test'); $table->addPrimary(true); $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->addColumn(new Column('title', 'string'))); $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->addColumn(new Column('total', 'int'))); $this->assertCount(3, $table->getColumns()); $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->changeColumn('title', new Column('new_title', 'string'))); $this->assertCount(3, $table->getColumns()); $this->assertCount(0, $table->getColumnsToChange()); $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->changeColumn('alias', new Column('new_alias', 'string'))); $this->assertCount(3, $table->getColumns()); $this->assertCount(1, $table->getColumnsToChange()); $this->assertCount(0, $table->getColumnsToDrop()); $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->dropColumn('title')); $this->assertCount(3, $table->getColumns()); $this->assertCount(1, $table->getColumnsToDrop()); }
public function testChangeAddedColumn() { $table = new Table('with_change_added_column'); $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->addColumn(new Column('old_name', 'integer'))); $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->changeColumn('old_name', new Column('new_name', 'string'))); $queryBuilder = new SqliteQueryBuilder(); $expectedQueries = ['ALTER TABLE "with_change_added_column" ADD COLUMN "new_name" varchar(255) NOT NULL;']; $this->assertEquals($expectedQueries, $queryBuilder->alterTable($table)); }
public function testChangeColumn() { $table = new Table('with_columns_to_change'); $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->changeColumn('old_name', new Column('new_name', 'integer'))); $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->changeColumn('no_name_change', new Column('no_name_change', 'integer'))); $queryBuilder = new PgsqlQueryBuilder(); $expectedQueries = ['ALTER TABLE "with_columns_to_change" RENAME COLUMN "old_name" TO "new_name";', 'ALTER TABLE "with_columns_to_change" ALTER COLUMN "new_name" TYPE int4 USING new_name::integer;', 'ALTER TABLE "with_columns_to_change" ALTER COLUMN "no_name_change" TYPE int4 USING no_name_change::integer;']; $this->assertEquals($expectedQueries, $queryBuilder->alterTable($table)); }