Ejemplo n.º 1
0
 /**
  * Test the alterSchema capabilities of postgres
  *
  * @return void
  */
 public function testAlterSchema()
 {
     $Old = new CakeSchema(array('connection' => 'test', 'name' => 'AlterPosts', 'alter_posts' => array('id' => array('type' => 'integer', 'key' => 'primary'), 'author_id' => array('type' => 'integer', 'null' => false), 'title' => array('type' => 'string', 'null' => true), 'body' => array('type' => 'text'), 'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'), 'created' => array('type' => 'datetime'), 'updated' => array('type' => 'datetime'))));
     $this->Dbo->query($this->Dbo->createSchema($Old));
     $New = new CakeSchema(array('connection' => 'test', 'name' => 'AlterPosts', 'alter_posts' => array('id' => array('type' => 'integer', 'key' => 'primary'), 'author_id' => array('type' => 'integer', 'null' => true), 'title' => array('type' => 'string', 'null' => false, 'default' => 'my title'), 'body' => array('type' => 'string', 'length' => 500), 'status' => array('type' => 'integer', 'length' => 3, 'default' => 1), 'created' => array('type' => 'datetime'), 'updated' => array('type' => 'datetime'))));
     $this->Dbo->query($this->Dbo->alterSchema($New->compare($Old), 'alter_posts'));
     $model = new CakeTestModel(array('table' => 'alter_posts', 'ds' => 'test'));
     $result = $model->schema();
     $this->assertTrue(isset($result['status']));
     $this->assertFalse(isset($result['published']));
     $this->assertEquals('string', $result['body']['type']);
     $this->assertEquals(1, $result['status']['default']);
     $this->assertEquals(true, $result['author_id']['null']);
     $this->assertEquals(false, $result['title']['null']);
     $this->Dbo->query($this->Dbo->dropSchema($New));
     $New = new CakeSchema(array('connection' => 'test_suite', 'name' => 'AlterPosts', 'alter_posts' => array('id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'), 'author_id' => array('type' => 'integer', 'null' => false), 'title' => array('type' => 'string', 'null' => true), 'body' => array('type' => 'text'), 'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'), 'created' => array('type' => 'datetime'), 'updated' => array('type' => 'datetime'))));
     $result = $this->Dbo->alterSchema($New->compare($Old), 'alter_posts');
     $this->assertNotRegExp('/varchar\\(36\\) NOT NULL/i', $result);
 }
Ejemplo n.º 2
0
 /**
  * Test the alterSchema capabilities of postgres
  *
  * @access public
  * @return void
  */
 function testAlterSchema()
 {
     $Old =& new CakeSchema(array('connection' => 'test_suite', 'name' => 'AlterPosts', 'alter_posts' => array('id' => array('type' => 'integer', 'key' => 'primary'), 'author_id' => array('type' => 'integer', 'null' => false), 'title' => array('type' => 'string', 'null' => false), 'body' => array('type' => 'text'), 'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'), 'created' => array('type' => 'datetime'), 'updated' => array('type' => 'datetime'))));
     $this->db->query($this->db->createSchema($Old));
     $New =& new CakeSchema(array('connection' => 'test_suite', 'name' => 'AlterPosts', 'alter_posts' => array('id' => array('type' => 'integer', 'key' => 'primary'), 'author_id' => array('type' => 'integer', 'null' => false), 'title' => array('type' => 'string', 'null' => false), 'body' => array('type' => 'string', 'length' => 500), 'status' => array('type' => 'integer', 'length' => 3), 'created' => array('type' => 'datetime'), 'updated' => array('type' => 'datetime'))));
     $this->db->query($this->db->alterSchema($New->compare($Old), 'alter_posts'));
     $model = new CakeTestModel(array('table' => 'alter_posts', 'ds' => 'test_suite'));
     $result = $model->schema();
     $this->assertTrue(isset($result['status']));
     $this->assertFalse(isset($result['published']));
     $this->assertEqual($result['body']['type'], 'string');
     $this->db->query($this->db->dropSchema($New));
 }