コード例 #1
0
 /**
  * test case for creating an index with a custom name
  */
 public function test_can_create_index_with_custom_name()
 {
     //create it
     $this->adapter->execute_ddl("CREATE TABLE `users` ( name varchar(20), age int(3) );");
     $base = new Ruckusing_Migration_Base($this->adapter);
     $base->add_index("users", "name", array('name' => 'my_special_index'));
     //ensure it exists
     $this->assertEquals(true, $this->adapter->has_index("users", "name", array('name' => 'my_special_index')));
     //drop it
     $base->remove_index("users", "name", array('name' => 'my_special_index'));
     $this->assertEquals(false, $this->adapter->has_index("users", "my_special_index"));
 }
コード例 #2
0
 public function test_multiple_primary_keys()
 {
     $bm = new Ruckusing_Migration_Base($this->adapter);
     $ts = time();
     $table_name = "users_{$ts}";
     $table = $bm->create_table($table_name, array('id' => false));
     $table->column('user_id', 'integer', array('primary_key' => true));
     $table->column('username', 'string', array('primary_key' => true));
     $table->finish();
     $this->adapter->column_info($table_name, "user_id");
     $this->adapter->column_info($table_name, "username");
     $primary_keys = $this->adapter->primary_keys($table_name);
     $this->assertEquals(true, is_array($primary_keys));
     $field_names = array();
     foreach ($primary_keys as $key) {
         $field_names[] = $key['name'];
     }
     $this->assertEquals(true, in_array('user_id', $field_names));
     $this->assertEquals(true, in_array('username', $field_names));
     //make sure there is NO 'id' column
     $id_actual = $this->adapter->column_info($table_name, "id");
     $this->assertEquals(array(), $id_actual);
     $bm->drop_table($table_name);
 }
コード例 #3
0
 /**
  * test remove named timestamps
  */
 public function test_remove_named_timestamps()
 {
     $bm = new Ruckusing_Migration_Base($this->adapter);
     $table_name = 'users';
     $created_name = 'created';
     $updated_name = 'updated';
     //create it
     $this->adapter->execute_ddl("CREATE TABLE {$table_name} ( name varchar(20), {$created_name} timestamp not null, {$updated_name} timestamp not null );");
     //verify they exists
     $col = $this->adapter->column_info($table_name, $created_name);
     $this->assertEquals($created_name, $col['field']);
     $col = $this->adapter->column_info($table_name, $updated_name);
     $this->assertEquals($updated_name, $col['field']);
     //drop them
     $bm->remove_timestamps($table_name, $created_name, $updated_name);
     //verify they does not exist
     $col = $this->adapter->column_info($table_name, $created_name);
     fwrite(STDERR, print_r($col, TRUE));
     $this->assertEquals(null, $col);
     $col = $this->adapter->column_info($table_name, $updated_name);
     fwrite(STDERR, print_r($col, TRUE));
     $this->assertEquals(null, $col);
     $this->drop_table($table_name);
 }
コード例 #4
0
 /**
  * test custom primary key with auto increment
  */
 public function test_custom_primary_key_with_auto_increment()
 {
     $bm = new Ruckusing_Migration_Base($this->adapter);
     $ts = time();
     $table_name = "users_{$ts}";
     $table = $bm->create_table($table_name, array('id' => false));
     $table->column('user_id', 'integer', array('primary_key' => true, 'auto_increment' => true));
     $sql = $table->finish();
     $user_id_actual = $this->adapter->column_info($table_name, "user_id");
     $primary_keys = $this->adapter->primary_keys($table_name);
     $this->assertEquals(true, is_array($primary_keys));
     $this->assertEquals('user_id', $primary_keys[0]['name']);
     //make sure there is NO 'id' column
     $id_actual = $this->adapter->column_info($table_name, "id");
     $this->assertEquals(null, $id_actual);
     $bm->drop_table($table_name);
 }
コード例 #5
0
 /**
  * test index name too long
  */
 public function test_index_name_too_long_throws_exception()
 {
     $bm = new Ruckusing_Migration_Base($this->adapter);
     try {
         srand();
         $table_name = "users_" . rand(0, 1000000);
         $table = $bm->create_table($table_name, array('id' => false));
         $table->column('somecolumnthatiscrazylong', 'integer');
         $table->column('anothercolumnthatiscrazylongrodeclown', 'integer');
         $sql = $table->finish();
         $bm->add_index($table_name, array('somecolumnthatiscrazylong', 'anothercolumnthatiscrazylongrodeclown'));
     } catch (Ruckusing_Exception $exception) {
         if (Ruckusing_Exception::INVALID_INDEX_NAME == $exception->getCode()) {
             $bm->drop_table($table_name);
             return;
         }
     }
     $this->fail('Expected to raise & catch Ruckusing_Exception::INVALID_INDEX_NAME');
 }