Skip to content
Snippets Groups Projects

Use transaction to change primary key

Closes #3454534

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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 from feeds_schema().

    Suggested change
    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 Smith
  • Tor F. Jacobsen changed this line in version 3 of the diff

    changed this line in version 3 of the diff

  • Thanks @ericgsmith for catching that! And great suggestion using the feeds_schema() function.

  • Please register or sign in to reply
  • added 1 commit

    • 8187f8d8 - get correct table definition from feeds_schema()

    Compare with previous version

  • Karl Shea added 1 commit

    added 1 commit

    Compare with previous version

  • Please register or sign in to reply
    Loading