// the type leaves the primary key in place even with existing data.
$this->connection
->
insert($table_name) ->
fields(['test_field' => 1, 'other_test_field' => 2
]) ->
execute();
$this->schema->
changeField($table_name, 'test_field', 'test_field',
['type' => 'int', 'not null' => TRUE
]);
$this->
assertTrue($this->schema->
fieldExists($table_name, 'test_field'
));
$this->
assertEquals($initial_primary_key,
$find_primary_key_columns->
invoke($this->schema,
$table_name));
// Make sure that adding the primary key can be done as part of changing
// a field, as well.
$this->schema->
dropPrimaryKey($table_name);
$this->
assertEquals([],
$find_primary_key_columns->
invoke($this->schema,
$table_name));
$this->schema->
changeField($table_name, 'test_field', 'test_field',
['type' => 'int', 'not null' => TRUE
],
['primary key' =>
$initial_primary_key]);
$this->
assertTrue($this->schema->
fieldExists($table_name, 'test_field'
));
$this->
assertEquals($initial_primary_key,
$find_primary_key_columns->
invoke($this->schema,
$table_name));
// Rename the field and make sure the primary key was updated.
$this->schema->
changeField($table_name, 'test_field', 'test_field_renamed',
['type' => 'int', 'not null' => TRUE
]);
$this->
assertTrue($this->schema->
fieldExists($table_name, 'test_field_renamed'
));
$this->
assertEquals($renamed_primary_key,
$find_primary_key_columns->
invoke($this->schema,
$table_name));
// Drop the field and make sure the primary key was dropped, as well.