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); }
/** * 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'); }
/** * 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); }