In order to allow users to disable comments for AO3-5897, the works table needs to be modified to add a new column. This column should have type tinyint, so that it can take on three different values:
0 (enable_all) when all commenting on the work is enabled.
1 (disable_anon) when anonymous commenting is disabled, but registered comments are enabled.
2 (disable_all) when all commenting on the work is disabled.
There also needs to be a rake task to copy the existing value from anon_commenting_disabled to the new column.
(Note: From a migration perspective, it'd be easier to change the display width of the existing column and rename it, both of which are metadata-only changes and should be fairly instantaneous. But renaming columns with no downtime generally requires adding a copy of the column under the new name anyway, so we might as well change the type of the new column at the same time.)
Run the migration to add the new column.
Do a rolling restart of the unicorns to make sure that they know that the new column exists.
Once all unicorns have finished restarting, run the rake task After:copy_anon_commenting_disabled_to_comment_permissions to copy the contents of anon_commenting_disabled to the new column.
Find an old work that hasn't been edited since the deploy, with anonymous commenting disabled.
Using the rails console, check the value of comment_permissions for that work. Make sure that it equals disable_anon.
Edit the work to allow anonymous comments.
Use the rails console, check the value of comment_permissions for that work. Make sure that it equals enable_all.
After poking around the rails source code, I think my mistake was in the deploy steps – the workers need to be restarted a second time after the migration has been run, but before the rake task has been run. And they need to be 100% finished restarting before the rake task runs.
(The development environment doesn’t really cache enough to accurately simulate the production environment in this case.)
Checked an old work with anonymous commenting disabled, before migration: https://test.archiveofourown.org/works/1071689. It had the correct properties:
After migration + unicorn restarts + rake, edited the work to allow anonymous comments. Checked the console again, it had the correct properties:
Just for fun, edited the work to disable anon comments again. Checked the console, still looked correct:
Re-tested, and can confirm that this time, the comment_permissions came back "enable_all" after editing!
From July 1:
now restart all the unicorns