/** * Change Method. * * Write your reversible migrations using this method. * * More information on writing migrations is available here: * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class * * @return void */ public function change() { $table = $this->table('queued_tasks'); try { $adapter = new MysqlAdapter([]); if ($adapter->getSqlType('text', 'longtext')) { $table->changeColumn('data', 'text', ['limit' => MysqlAdapter::TEXT_LONG, 'null' => true, 'default' => null]); } } catch (Exception $e) { Debugger::dump($e->getMessage()); } }
public function testDropDatabase() { $this->assertFalse($this->adapter->hasDatabase('temp_phinx_database')); $this->adapter->createDatabase('temp_phinx_database'); $this->assertTrue($this->adapter->hasDatabase('temp_phinx_database')); $this->adapter->dropDatabase('temp_phinx_database'); }
public function testNullWithoutDefaultValue() { $this->markTestSkipped('Skipping for now. See Github Issue #265.'); // construct table with default/null combinations $table = new \Phinx\Db\Table('table1', array(), $this->adapter); $table->addColumn("aa", "string", array("null" => true))->addColumn("bb", "string", array("null" => false))->addColumn("cc", "string", array("null" => true, "default" => "some1"))->addColumn("dd", "string", array("null" => false, "default" => "some2"))->save(); // load table info $columns = $this->adapter->getColumns("table1"); $this->assertEquals(count($columns), 5); $aa = $columns[1]; $bb = $columns[2]; $cc = $columns[3]; $dd = $columns[4]; $this->assertEquals("aa", $aa->getName()); $this->assertEquals(true, $aa->isNull()); $this->assertEquals(null, $aa->getDefault()); $this->assertEquals("bb", $bb->getName()); $this->assertEquals(false, $bb->isNull()); $this->assertEquals(null, $bb->getDefault()); $this->assertEquals("cc", $cc->getName()); $this->assertEquals(true, $cc->isNull()); $this->assertEquals("some1", $cc->getDefault()); $this->assertEquals("dd", $dd->getName()); $this->assertEquals(false, $dd->isNull()); $this->assertEquals("some2", $dd->getDefault()); }
public function testAddColumnWithComment() { $table = new \Phinx\Db\Table('table1', array(), $this->adapter); $table->addColumn('column1', 'string', array('comment' => $comment = 'Comments from "column1"'))->save(); $rows = $this->adapter->fetchAll('SELECT column_name, column_comment FROM information_schema.columns WHERE table_name = "table1"'); $columnWithComment = $rows[1]; $this->assertEquals($comment, $columnWithComment['column_comment'], 'Dont set column comment correctly'); }
public function testAddEnumColumn() { $table = new \Phinx\Db\Table('table1', array(), $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('enum_column')); $table->addColumn('enum_column', 'enum', array('values' => array('one', 'two')))->save(); $rows = $this->adapter->fetchAll('SHOW COLUMNS FROM table1'); $this->assertEquals("enum('one','two')", $rows[1]['Type']); }
public function testInsertData() { $table = new \Phinx\Db\Table('table1', array(), $this->adapter); $table->addColumn('column1', 'string')->addColumn('column2', 'integer')->insert(array("column1", "column2"), array(array('value1', 1), array('value2', 2)))->save(); $rows = $this->adapter->fetchAll('SELECT * FROM table1'); $this->assertEquals('value1', $rows[0]['column1']); $this->assertEquals('value2', $rows[1]['column1']); $this->assertEquals(1, $rows[0]['column2']); $this->assertEquals(2, $rows[1]['column2']); }
public function testAddColumnWithComment() { $table = new \Phinx\Db\Table('table1', array(), $this->adapter); $table->addColumn('column1', 'string', array('comment' => $comment = 'Comments from "column1"'))->save(); $rows = $this->adapter->fetchAll('select * from sqlite_master where `type` = \'table\''); foreach ($rows as $row) { if ($row['tbl_name'] == 'table1') { $sql = $row['sql']; } } $this->assertRegExp('/\\/\\* Comments from "column1" \\*\\//', $sql); }
public function testInsertData() { $data = array(array('column1' => 'value1', 'column2' => 1), array('column1' => 'value2', 'column2' => 2), array('column1' => 'value3', 'column2' => 3, 'column3' => 'foo')); $table = new \Phinx\Db\Table('table1', array(), $this->adapter); $table->addColumn('column1', 'string')->addColumn('column2', 'integer')->addColumn('column3', 'string', array('default' => 'test'))->insert($data)->save(); $rows = $this->adapter->fetchAll('SELECT * FROM table1'); $this->assertEquals('value1', $rows[0]['column1']); $this->assertEquals('value2', $rows[1]['column1']); $this->assertEquals('value3', $rows[2]['column1']); $this->assertEquals(1, $rows[0]['column2']); $this->assertEquals(2, $rows[1]['column2']); $this->assertEquals(3, $rows[2]['column2']); $this->assertEquals('test', $rows[0]['column3']); $this->assertEquals('foo', $rows[2]['column3']); }
public function getForeignKeys($tableName) { return parent::getForeignKeys($tableName); }
/** * @return mysqli */ public function getConnection() { return parent::getConnection(); }
public function testPhinxTypeNotValidTypeRegex() { $this->setExpectedException('\\RuntimeException', 'Column type ?int? is not supported'); $this->adapter->getPhinxType('?int?'); }