Use transaction to change primary key
1 open thread
Closes #3454534
Merge request reports
Activity
added 1 commit
- 942e59f5 - Create new table to update primary key instead of changing the existing field
198 199 'length' => 255, 199 200 'not null' => TRUE, 200 201 ]; 201 $schema->dropPrimaryKey('feeds_clean_list'); 202 $schema->changeField('feeds_clean_list', 'entity_id', 'entity_id', $new); 203 $schema->addPrimaryKey('feeds_clean_list', ['feed_id', 'entity_id']); 202 // Create a new table with the desired primary key. 203 $schema->createTable('feeds_clean_list_new', [ This approach looks like it makes sense to resolve this issue.
The use of
$new
for both fields is incorrect though, I think can remove that and get the schema definition fromfeeds_schema()
.203 $schema->createTable('feeds_clean_list_new', [ 204 'fields' => [ 205 'feed_id' => $new, 206 'entity_id' => $new, 207 ], 208 'primary key' => ['feed_id', 'entity_id'], 209 ]); 203 $feeds_clean_list_table = feeds_schema()['feeds_clean_list']; 204 $schema->createTable('feeds_clean_list_new', $feeds_clean_list_table); It would be worth also adding a comment on 202 as to why we need create + drop the tables rather.
Edited by Eric Smithchanged this line in version 3 of the diff
Thanks @ericgsmith for catching that! And great suggestion using the
feeds_schema()
function.
added 1 commit
- 8187f8d8 - get correct table definition from feeds_schema()
Please register or sign in to reply