Add migration to update the primary key and unique constraints on the kudos table

Description

This is the one prophesied to take down the site. Migration:

  • Change the primary key type from INT to BIGINT.

  • Add unique index for commentable_id + commentable_type + user_id. This will remove duplicate kudos for the same work from the same user.

  • Add unique index for commentable_id + commentable_type + ip_address. This will remove duplicate kudos for the same work from the same guest IP.

The migration will be different depending on the environment:

  • Add a usual Rails migration, to be used in dev and CI environments.

  • Add a comment with the pt-online-schema-change command to be run on staging and beta (similar to ).

How to test:

  • (Anyone) Test first.

  • (Server admin) Test the migration:

    1. Run the migration.

    2. Copy the commands that it prints to a file.

    3. Run the pt-online-schema-change command, but not any of the SQL commands that follow it.

    4. Create a brand new kudos, and note the ID in the database.

    5. Create another kudos on the same work, from the same user (by using the Rails console and skipping validation, .save(validate: false)). This is a duplicate of the kudos from the previous step.

    6. Run the SQL commands. (RENAME TABLE, DROP TRIGGER, and DROP TABLE)

    7. Check whether the kudos that you created is still there. Check that it has no duplicates (the duplicates should have been eaten by the pt-online-schema-change migration).

    8. From the Rails console: try to insert a duplicate kudos, bypassing validations, and make sure that it generates an error.

  • (Server admin) Test that the migration can run up and down and up again.

  • (Anyone) Finally, in the post-migration world:

    • Check that leaving logged in kudos still works.

    • Check that leaving logged in kudos a second time on the same work will get you the "left kudos here " message.

    • Check that you can no longer leave logged in kudos after changing default pseuds.

Environment

None

Assignee

ticking instant

Reporter

redsummernight

Roadmap

Misc

Priority

Medium

Affects versions

Fix versions

Components

BackEnd

Difficulty

Medium

Required Access Level

None

Milestone

Internal 0.9
Configure