You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1303 lines
60 KiB

8 years ago
8 years ago
8 years ago
Account domain blocks (#2381) * Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Account domain blocks (#2381) * Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb
7 years ago
8 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Revamp post filtering system (#18058) * Add model for custom filter keywords * Use CustomFilterKeyword internally Does not change the API * Fix /filters/edit and /filters/new * Add migration tests * Remove whole_word column from custom_filters (covered by custom_filter_keywords) * Redesign /filters Instead of a list, present a card that displays more information and handles multiple keywords per filter. * Redesign /filters/new and /filters/edit to add and remove keywords This adds a new gem dependency: cocoon, as well as a npm dependency: cocoon-js-vanilla. Those are used to easily populate and remove form fields from the user interface when manipulating multiple keyword filters at once. * Add /api/v2/filters to edit filter with multiple keywords Entities: - `Filter`: `id`, `title`, `filter_action` (either `hide` or `warn`), `context` `keywords` - `FilterKeyword`: `id`, `keyword`, `whole_word` API endpoits: - `GET /api/v2/filters` to list filters (including keywords) - `POST /api/v2/filters` to create a new filter `keywords_attributes` can also be passed to create keywords in one request - `GET /api/v2/filters/:id` to read a particular filter - `PUT /api/v2/filters/:id` to update a new filter `keywords_attributes` can also be passed to edit, delete or add keywords in one request - `DELETE /api/v2/filters/:id` to delete a particular filter - `GET /api/v2/filters/:id/keywords` to list keywords for a filter - `POST /api/v2/filters/:filter_id/keywords/:id` to add a new keyword to a filter - `GET /api/v2/filter_keywords/:id` to read a particular keyword - `PUT /api/v2/filter_keywords/:id` to edit a particular keyword - `DELETE /api/v2/filter_keywords/:id` to delete a particular keyword * Change from `irreversible` boolean to `action` enum * Remove irrelevent `irreversible_must_be_within_context` check * Fix /filters/new and /filters/edit with update for filter_action * Fix Rubocop/Codeclimate complaining about task names * Refactor FeedManager#phrase_filtered? This moves regexp building and filter caching to the `CustomFilter` class. This does not change the functional behavior yet, but this changes how the cache is built, doing per-custom_filter regexps so that filters can be matched independently, while still offering caching. * Perform server-side filtering and output result in REST API * Fix numerous filters_changed events being sent when editing multiple keywords at once * Add some tests * Use the new API in the WebUI - use client-side logic for filters we have fetched rules for. This is so that filter changes can be retroactively applied without reloading the UI. - use server-side logic for filters we haven't fetched rules for yet (e.g. network error, or initial timeline loading) * Minor optimizations and refactoring * Perform server-side filtering on the streaming server * Change the wording of filter action labels * Fix issues pointed out by linter * Change design of “Show anyway” link in accordence to review comments * Drop “irreversible” filtering behavior * Move /api/v2/filter_keywords to /api/v1/filters/keywords * Rename `filter_results` attribute to `filtered` * Rename REST::LegacyFilterSerializer to REST::V1::FilterSerializer * Fix systemChannelId value in streaming server * Simplify code by removing client-side filtering code The simplifcation comes at a cost though: filters aren't retroactively applied anymore.
2 years ago
Revamp post filtering system (#18058) * Add model for custom filter keywords * Use CustomFilterKeyword internally Does not change the API * Fix /filters/edit and /filters/new * Add migration tests * Remove whole_word column from custom_filters (covered by custom_filter_keywords) * Redesign /filters Instead of a list, present a card that displays more information and handles multiple keywords per filter. * Redesign /filters/new and /filters/edit to add and remove keywords This adds a new gem dependency: cocoon, as well as a npm dependency: cocoon-js-vanilla. Those are used to easily populate and remove form fields from the user interface when manipulating multiple keyword filters at once. * Add /api/v2/filters to edit filter with multiple keywords Entities: - `Filter`: `id`, `title`, `filter_action` (either `hide` or `warn`), `context` `keywords` - `FilterKeyword`: `id`, `keyword`, `whole_word` API endpoits: - `GET /api/v2/filters` to list filters (including keywords) - `POST /api/v2/filters` to create a new filter `keywords_attributes` can also be passed to create keywords in one request - `GET /api/v2/filters/:id` to read a particular filter - `PUT /api/v2/filters/:id` to update a new filter `keywords_attributes` can also be passed to edit, delete or add keywords in one request - `DELETE /api/v2/filters/:id` to delete a particular filter - `GET /api/v2/filters/:id/keywords` to list keywords for a filter - `POST /api/v2/filters/:filter_id/keywords/:id` to add a new keyword to a filter - `GET /api/v2/filter_keywords/:id` to read a particular keyword - `PUT /api/v2/filter_keywords/:id` to edit a particular keyword - `DELETE /api/v2/filter_keywords/:id` to delete a particular keyword * Change from `irreversible` boolean to `action` enum * Remove irrelevent `irreversible_must_be_within_context` check * Fix /filters/new and /filters/edit with update for filter_action * Fix Rubocop/Codeclimate complaining about task names * Refactor FeedManager#phrase_filtered? This moves regexp building and filter caching to the `CustomFilter` class. This does not change the functional behavior yet, but this changes how the cache is built, doing per-custom_filter regexps so that filters can be matched independently, while still offering caching. * Perform server-side filtering and output result in REST API * Fix numerous filters_changed events being sent when editing multiple keywords at once * Add some tests * Use the new API in the WebUI - use client-side logic for filters we have fetched rules for. This is so that filter changes can be retroactively applied without reloading the UI. - use server-side logic for filters we haven't fetched rules for yet (e.g. network error, or initial timeline loading) * Minor optimizations and refactoring * Perform server-side filtering on the streaming server * Change the wording of filter action labels * Fix issues pointed out by linter * Change design of “Show anyway” link in accordence to review comments * Drop “irreversible” filtering behavior * Move /api/v2/filter_keywords to /api/v1/filters/keywords * Rename `filter_results` attribute to `filtered` * Rename REST::LegacyFilterSerializer to REST::V1::FilterSerializer * Fix systemChannelId value in streaming server * Simplify code by removing client-side filtering code The simplifcation comes at a cost though: filters aren't retroactively applied anymore.
2 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Non-Serial ("Snowflake") IDs (#4801) * Use non-serial IDs This change makes a number of nontrivial tweaks to the data model in Mastodon: * All IDs are now 8 byte integers (rather than mixed 4- and 8-byte) * IDs are now assigned as: * Top 6 bytes: millisecond-resolution time from epoch * Bottom 2 bytes: serial (within the millisecond) sequence number * See /lib/tasks/db.rake's `define_timestamp_id` for details, but note that the purpose of these changes is to make it difficult to determine the number of objects in a table from the ID of any object. * The Redis sorted set used for the feed will have values used to look up toots, rather than scores. This is almost always the same as the existing behavior, except in the case of boosted toots. This change was made because Redis stores scores as double-precision floats, which cannot store the new ID format exactly. Note that this doesn't cause problems with sorting/pagination, because ZREVRANGEBYSCORE sorts lexicographically when scores are tied. (This will still cause sorting issues when the ID gains a new significant digit, but that's extraordinarily uncommon.) Note a couple of tradeoffs have been made in this commit: * lib/tasks/db.rake is used to enforce many/most column constraints, because this commit seems likely to take a while to bring upstream. Enforcing a post-migrate hook is an easier way to maintain the code in the interim. * Boosted toots will appear in the timeline as many times as they have been boosted. This is a tradeoff due to the way the feed is saved in Redis at the moment, but will be handled by a future commit. This would effectively close Mastodon's #1059, as it is a snowflake-like system of generating IDs. However, given how involved the changes were simply within Mastodon, it may have unexpected interactions with some clients, if they store IDs as doubles (or as 4-byte integers). This was a problem that Twitter ran into with their "snowflake" transition, particularly in JavaScript clients that treated IDs as JS integers, rather than strings. It therefore would be useful to test these changes at least in the web interface and popular clients before pushing them to all users. * Fix JavaScript interface with long IDs Somewhat predictably, the JS interface handled IDs as numbers, which in JS are IEEE double-precision floats. This loses some precision when working with numbers as large as those generated by the new ID scheme, so we instead handle them here as strings. This is relatively simple, and doesn't appear to have caused any problems, but should definitely be tested more thoroughly than the built-in tests. Several days of use appear to support this working properly. BREAKING CHANGE: The major(!) change here is that IDs are now returned as strings by the REST endpoints, rather than as integers. In practice, relatively few changes were required to make the existing JS UI work with this change, but it will likely hit API clients pretty hard: it's an entirely different type to consume. (The one API client I tested, Tusky, handles this with no problems, however.) Twitter ran into this issue when introducing Snowflake IDs, and decided to instead introduce an `id_str` field in JSON responses. I have opted to *not* do that, and instead force all IDs to 64-bit integers represented by strings in one go. (I believe Twitter exacerbated their problem by rolling out the changes three times: once for statuses, once for DMs, and once for user IDs, as well as by leaving an integer ID value in JSON. As they said, "If you’re using the `id` field with JSON in a Javascript-related language, there is a very high likelihood that the integers will be silently munged by Javascript interpreters. In most cases, this will result in behavior such as being unable to load or delete a specific direct message, because the ID you're sending to the API is different than the actual identifier associated with the message." [1]) However, given that this is a significant change for API users, alternatives or a transition time may be appropriate. 1: https://blog.twitter.com/developer/en_us/a/2011/direct-messages-going-snowflake-on-sep-30-2011.html * Restructure feed pushes/unpushes This was necessary because the previous behavior used Redis zset scores to identify statuses, but those are IEEE double-precision floats, so we can't actually use them to identify all 64-bit IDs. However, it leaves the code in a much better state for refactoring reblog handling / coalescing. Feed-management code has been consolidated in FeedManager, including: * BatchedRemoveStatusService no longer directly manipulates feed zsets * RemoveStatusService no longer directly manipulates feed zsets * PrecomputeFeedService has moved its logic to FeedManager#populate_feed (PrecomputeFeedService largely made lots of calls to FeedManager, but didn't follow the normal adding-to-feed process.) This has the effect of unifying all of the feed push/unpush logic in FeedManager, making it much more tractable to update it in the future. Due to some additional checks that must be made during, for example, batch status removals, some Redis pipelining has been removed. It does not appear that this should cause significantly increased load, but if necessary, some optimizations are possible in batch cases. These were omitted in the pursuit of simplicity, but a batch_push and batch_unpush would be possible in the future. Tests were added to verify that pushes happen under expected conditions, and to verify reblog behavior (both on pushing and unpushing). In the case of unpushing, this includes testing behavior that currently leads to confusion such as Mastodon's #2817, but this codifies that the behavior is currently expected. * Rubocop fixes I could swear I made these changes already, but I must have lost them somewhere along the line. * Address review comments This addresses the first two comments from review of this feature: https://github.com/tootsuite/mastodon/pull/4801#discussion_r139336735 https://github.com/tootsuite/mastodon/pull/4801#discussion_r139336931 This adds an optional argument to FeedManager#key, the subtype of feed key to generate. It also tests to ensure that FeedManager's settings are such that reblogs won't be tracked forever. * Hardcode IdToBigints migration columns This addresses a comment during review: https://github.com/tootsuite/mastodon/pull/4801#discussion_r139337452 This means we'll need to make sure that all _id columns going forward are bigints, but that should happen automatically in most cases. * Additional fixes for stringified IDs in JSON These should be the last two. These were identified using eslint to try to identify any plain casts to JavaScript numbers. (Some such casts are legitimate, but these were not.) Adding the following to .eslintrc.yml will identify casts to numbers: ~~~ no-restricted-syntax: - warn - selector: UnaryExpression[operator='+'] > :not(Literal) message: Avoid the use of unary + - selector: CallExpression[callee.name='Number'] message: Casting with Number() may coerce string IDs to numbers ~~~ The remaining three casts appear legitimate: two casts to array indices, one in a server to turn an environment variable into a number. * Only implement timestamp IDs for Status IDs Per discussion in #4801, this is only being merged in for Status IDs at this point. We do this in a migration, as there is no longer use for a post-migration hook. We keep the initialization of the timestamp_id function as a Rake task, as it is also needed after db:schema:load (as db/schema.rb doesn't store Postgres functions). * Change internal streaming payloads to stringified IDs as well This is equivalent to 591a9af356faf2d5c7e66e3ec715502796c875cd from #5019, with an extra change for the addition to FeedManager#unpush. * Ensure we have a status_id_seq sequence Apparently this is not a given when specifying a custom ID function, so now we ensure it gets created. This uses the generic version of this function to more easily support adding additional tables with timestamp IDs in the future, although it would be possible to cut this down to a less generic version if necessary. It is only run during db:schema:load or the relevant migration, so the overhead is extraordinarily minimal. * Transition reblogs to new Redis format This provides a one-way migration to transition old Redis reblog entries into the new format, with a separate tracking entry for reblogs. It is not invertible because doing so could (if timestamp IDs are used) require a database query for each status in each users' feed, which is likely to be a significant toll on major instances. * Address review comments from @akihikodaki No functional changes. * Additional review changes * Heredoc cleanup * Run db:schema:load hooks for test in development This matches the behavior in Rails' ActiveRecord::Tasks::DatabaseTasks.each_current_configuration, which would otherwise break `rake db:setup` in development. It also moves some functionality out to a library, which will be a good place to put additional related functionality in the near future.
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
8 years ago
8 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Add WebAuthn as an alternative 2FA method (#14466) * feat: add possibility of adding WebAuthn security keys to use as 2FA This adds a basic UI for enabling WebAuthn 2FA. We did a little refactor to the Settings page for editing the 2FA methods – now it will list the methods that are available to the user (TOTP and WebAuthn) and from there they'll be able to add or remove any of them. Also, it's worth mentioning that for enabling WebAuthn it's required to have TOTP enabled, so the first time that you go to the 2FA Settings page, you'll be asked to set it up. This work was inspired by the one donde by Github in their platform, and despite it could be approached in different ways, we decided to go with this one given that we feel that this gives a great UX. Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: add request for WebAuthn as second factor at login if enabled This commits adds the feature for using WebAuthn as a second factor for login when enabled. If users have WebAuthn enabled, now a page requesting for the use of a WebAuthn credential for log in will appear, although a link redirecting to the old page for logging in using a two-factor code will also be present. Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: add possibility of deleting WebAuthn Credentials Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: disable WebAuthn when an Admin disables 2FA for a user Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: remove ability to disable TOTP leaving only WebAuthn as 2FA Following examples form other platforms like Github, we decided to make Webauthn 2FA secondary to 2FA with TOTP, so that we removed the possibility of removing TOTP authentication only, leaving users with just WEbAuthn as 2FA. Instead, users will have to click on 'Disable 2FA' in order to remove second factor auth. The reason for WebAuthn being secondary to TOPT is that in that way, users will still be able to log in using their code from their phone's application if they don't have their security keys with them – or maybe even lost them. * We had to change a little the flow for setting up TOTP, given that now it's possible to setting up again if you already had TOTP, in order to let users modify their authenticator app – given that now it's not possible for them to disable TOTP and set it up again with another authenticator app. So, basically, now instead of storing the new `otp_secret` in the user, we store it in the session until the process of set up is finished. This was because, as it was before, when users clicked on 'Edit' in the new two-factor methods lists page, but then went back without finishing the flow, their `otp_secret` had been changed therefore invalidating their previous authenticator app, making them unable to log in again using TOTP. Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * refactor: fix eslint errors The PR build was failing given that linting returning some errors. This commit attempts to fix them. * refactor: normalize i18n translations The build was failing given that i18n translations files were not normalized. This commits fixes that. * refactor: avoid having the webauthn gem locked to a specific version * refactor: use symbols for routes without '/' * refactor: avoid sending webauthn disabled email when 2FA is disabled When an admins disable 2FA for users, we were sending two mails to them, one notifying that 2FA was disabled and the other to notify that WebAuthn was disabled. As the second one is redundant since the first email includes it, we can remove it and send just one email to users. * refactor: avoid creating new env variable for webauthn_origin config * refactor: improve flash error messages for webauthn pages Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com>
4 years ago
Web Push Notifications (#3243) * feat: Register push subscription * feat: Notify when mentioned * feat: Boost, favourite, reply, follow, follow request * feat: Notification interaction * feat: Handle change of public key * feat: Unsubscribe if things go wrong * feat: Do not send normal notifications if push is enabled * feat: Focus client if open * refactor: Move push logic to WebPushSubscription * feat: Better title and body * feat: Localize messages * chore: Fix lint errors * feat: Settings * refactor: Lazy load * fix: Check if push settings exist * feat: Device-based preferences * refactor: Simplify logic * refactor: Pull request feedback * refactor: Pull request feedback * refactor: Create /api/web/push_subscriptions endpoint * feat: Spec PushSubscriptionController * refactor: WebPushSubscription => Web::PushSubscription * feat: Spec Web::PushSubscription * feat: Display first media attachment * feat: Support direction * fix: Stuff broken while rebasing * refactor: Integration with session activations * refactor: Cleanup * refactor: Simplify implementation * feat: Set VAPID keys via environment * chore: Comments * fix: Crash when no alerts * fix: Set VAPID keys in testing environment * fix: Follow link * feat: Notification actions * fix: Delete previous subscription * chore: Temporary logs * refactor: Move migration to a later date * fix: Fetch the correct session activation and misc bugs * refactor: Move migration to a later date * fix: Remove follow request (no notifications) * feat: Send administrator contact to push service * feat: Set time-to-live * fix: Do not show sensitive images * fix: Reducer crash in error handling * feat: Add badge * chore: Fix lint error * fix: Checkbox label overlap * fix: Check for payload support * fix: Rename action "type" (crash in latest Chrome) * feat: Action to expand notification * fix: Lint errors * fix: Unescape notification body * fix: Do not allow boosting if the status is hidden * feat: Add VAPID keys to the production sample environment * fix: Strip HTML tags from status * refactor: Better error messages * refactor: Handle browser not implementing the VAPID protocol (Samsung Internet) * fix: Error when target_status is nil * fix: Handle lack of image * fix: Delete reference to invalid subscriptions * feat: Better error handling * fix: Unescape HTML characters after tags are striped * refactor: Simpify code * fix: Modify to work with #4091 * Sort strings alphabetically * i18n: Updated Polish translation it annoys me that it's not fully localized :P * refactor: Use current_session in PushSubscriptionController * fix: Rebase mistake * fix: Set cacheName to mastodon * refactor: Pull request feedback * refactor: Remove logging statements * chore(yarn): Fix conflicts with master * chore(yarn): Copy latest from master * chore(yarn): Readd offline-plugin * refactor: Use save! and update! * refactor: Send notifications async * fix: Allow retry when push fails * fix: Save track for failed pushes * fix: Minify sw.js * fix: Remove account_id from fabricator
7 years ago
Web Push Notifications (#3243) * feat: Register push subscription * feat: Notify when mentioned * feat: Boost, favourite, reply, follow, follow request * feat: Notification interaction * feat: Handle change of public key * feat: Unsubscribe if things go wrong * feat: Do not send normal notifications if push is enabled * feat: Focus client if open * refactor: Move push logic to WebPushSubscription * feat: Better title and body * feat: Localize messages * chore: Fix lint errors * feat: Settings * refactor: Lazy load * fix: Check if push settings exist * feat: Device-based preferences * refactor: Simplify logic * refactor: Pull request feedback * refactor: Pull request feedback * refactor: Create /api/web/push_subscriptions endpoint * feat: Spec PushSubscriptionController * refactor: WebPushSubscription => Web::PushSubscription * feat: Spec Web::PushSubscription * feat: Display first media attachment * feat: Support direction * fix: Stuff broken while rebasing * refactor: Integration with session activations * refactor: Cleanup * refactor: Simplify implementation * feat: Set VAPID keys via environment * chore: Comments * fix: Crash when no alerts * fix: Set VAPID keys in testing environment * fix: Follow link * feat: Notification actions * fix: Delete previous subscription * chore: Temporary logs * refactor: Move migration to a later date * fix: Fetch the correct session activation and misc bugs * refactor: Move migration to a later date * fix: Remove follow request (no notifications) * feat: Send administrator contact to push service * feat: Set time-to-live * fix: Do not show sensitive images * fix: Reducer crash in error handling * feat: Add badge * chore: Fix lint error * fix: Checkbox label overlap * fix: Check for payload support * fix: Rename action "type" (crash in latest Chrome) * feat: Action to expand notification * fix: Lint errors * fix: Unescape notification body * fix: Do not allow boosting if the status is hidden * feat: Add VAPID keys to the production sample environment * fix: Strip HTML tags from status * refactor: Better error messages * refactor: Handle browser not implementing the VAPID protocol (Samsung Internet) * fix: Error when target_status is nil * fix: Handle lack of image * fix: Delete reference to invalid subscriptions * feat: Better error handling * fix: Unescape HTML characters after tags are striped * refactor: Simpify code * fix: Modify to work with #4091 * Sort strings alphabetically * i18n: Updated Polish translation it annoys me that it's not fully localized :P * refactor: Use current_session in PushSubscriptionController * fix: Rebase mistake * fix: Set cacheName to mastodon * refactor: Pull request feedback * refactor: Remove logging statements * chore(yarn): Fix conflicts with master * chore(yarn): Copy latest from master * chore(yarn): Readd offline-plugin * refactor: Use save! and update! * refactor: Send notifications async * fix: Allow retry when push fails * fix: Save track for failed pushes * fix: Minify sw.js * fix: Remove account_id from fabricator
7 years ago
Add WebAuthn as an alternative 2FA method (#14466) * feat: add possibility of adding WebAuthn security keys to use as 2FA This adds a basic UI for enabling WebAuthn 2FA. We did a little refactor to the Settings page for editing the 2FA methods – now it will list the methods that are available to the user (TOTP and WebAuthn) and from there they'll be able to add or remove any of them. Also, it's worth mentioning that for enabling WebAuthn it's required to have TOTP enabled, so the first time that you go to the 2FA Settings page, you'll be asked to set it up. This work was inspired by the one donde by Github in their platform, and despite it could be approached in different ways, we decided to go with this one given that we feel that this gives a great UX. Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: add request for WebAuthn as second factor at login if enabled This commits adds the feature for using WebAuthn as a second factor for login when enabled. If users have WebAuthn enabled, now a page requesting for the use of a WebAuthn credential for log in will appear, although a link redirecting to the old page for logging in using a two-factor code will also be present. Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: add possibility of deleting WebAuthn Credentials Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: disable WebAuthn when an Admin disables 2FA for a user Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: remove ability to disable TOTP leaving only WebAuthn as 2FA Following examples form other platforms like Github, we decided to make Webauthn 2FA secondary to 2FA with TOTP, so that we removed the possibility of removing TOTP authentication only, leaving users with just WEbAuthn as 2FA. Instead, users will have to click on 'Disable 2FA' in order to remove second factor auth. The reason for WebAuthn being secondary to TOPT is that in that way, users will still be able to log in using their code from their phone's application if they don't have their security keys with them – or maybe even lost them. * We had to change a little the flow for setting up TOTP, given that now it's possible to setting up again if you already had TOTP, in order to let users modify their authenticator app – given that now it's not possible for them to disable TOTP and set it up again with another authenticator app. So, basically, now instead of storing the new `otp_secret` in the user, we store it in the session until the process of set up is finished. This was because, as it was before, when users clicked on 'Edit' in the new two-factor methods lists page, but then went back without finishing the flow, their `otp_secret` had been changed therefore invalidating their previous authenticator app, making them unable to log in again using TOTP. Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * refactor: fix eslint errors The PR build was failing given that linting returning some errors. This commit attempts to fix them. * refactor: normalize i18n translations The build was failing given that i18n translations files were not normalized. This commits fixes that. * refactor: avoid having the webauthn gem locked to a specific version * refactor: use symbols for routes without '/' * refactor: avoid sending webauthn disabled email when 2FA is disabled When an admins disable 2FA for users, we were sending two mails to them, one notifying that 2FA was disabled and the other to notify that WebAuthn was disabled. As the second one is redundant since the first email includes it, we can remove it and send just one email to users. * refactor: avoid creating new env variable for webauthn_origin config * refactor: improve flash error messages for webauthn pages Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com>
4 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Revamp post filtering system (#18058) * Add model for custom filter keywords * Use CustomFilterKeyword internally Does not change the API * Fix /filters/edit and /filters/new * Add migration tests * Remove whole_word column from custom_filters (covered by custom_filter_keywords) * Redesign /filters Instead of a list, present a card that displays more information and handles multiple keywords per filter. * Redesign /filters/new and /filters/edit to add and remove keywords This adds a new gem dependency: cocoon, as well as a npm dependency: cocoon-js-vanilla. Those are used to easily populate and remove form fields from the user interface when manipulating multiple keyword filters at once. * Add /api/v2/filters to edit filter with multiple keywords Entities: - `Filter`: `id`, `title`, `filter_action` (either `hide` or `warn`), `context` `keywords` - `FilterKeyword`: `id`, `keyword`, `whole_word` API endpoits: - `GET /api/v2/filters` to list filters (including keywords) - `POST /api/v2/filters` to create a new filter `keywords_attributes` can also be passed to create keywords in one request - `GET /api/v2/filters/:id` to read a particular filter - `PUT /api/v2/filters/:id` to update a new filter `keywords_attributes` can also be passed to edit, delete or add keywords in one request - `DELETE /api/v2/filters/:id` to delete a particular filter - `GET /api/v2/filters/:id/keywords` to list keywords for a filter - `POST /api/v2/filters/:filter_id/keywords/:id` to add a new keyword to a filter - `GET /api/v2/filter_keywords/:id` to read a particular keyword - `PUT /api/v2/filter_keywords/:id` to edit a particular keyword - `DELETE /api/v2/filter_keywords/:id` to delete a particular keyword * Change from `irreversible` boolean to `action` enum * Remove irrelevent `irreversible_must_be_within_context` check * Fix /filters/new and /filters/edit with update for filter_action * Fix Rubocop/Codeclimate complaining about task names * Refactor FeedManager#phrase_filtered? This moves regexp building and filter caching to the `CustomFilter` class. This does not change the functional behavior yet, but this changes how the cache is built, doing per-custom_filter regexps so that filters can be matched independently, while still offering caching. * Perform server-side filtering and output result in REST API * Fix numerous filters_changed events being sent when editing multiple keywords at once * Add some tests * Use the new API in the WebUI - use client-side logic for filters we have fetched rules for. This is so that filter changes can be retroactively applied without reloading the UI. - use server-side logic for filters we haven't fetched rules for yet (e.g. network error, or initial timeline loading) * Minor optimizations and refactoring * Perform server-side filtering on the streaming server * Change the wording of filter action labels * Fix issues pointed out by linter * Change design of “Show anyway” link in accordence to review comments * Drop “irreversible” filtering behavior * Move /api/v2/filter_keywords to /api/v1/filters/keywords * Rename `filter_results` attribute to `filtered` * Rename REST::LegacyFilterSerializer to REST::V1::FilterSerializer * Fix systemChannelId value in streaming server * Simplify code by removing client-side filtering code The simplifcation comes at a cost though: filters aren't retroactively applied anymore.
2 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Make IdsToBigints (mostly!) non-blocking (#5088) * Make IdsToBigints (mostly!) non-blocking This pulls in GitLab's MigrationHelpers, which include code to make column changes in ways that Postgres can do without locking. In general, this involves creating a new column, adding an index and any foreign keys as appropriate, adding a trigger to keep it populated alongside the old column, and then progressively copying data over to the new column, before removing the old column and replacing it with the new one. A few changes to GitLab's MigrationHelpers were necessary: * Some changes were made to remove dependencies on other GitLab code. * We explicitly wait for index creation before forging ahead on column replacements. * We use different temporary column names, to avoid running into index name length limits. * We rename the generated indices back to what they "should" be after replacing columns. * We rename the generated foreign keys to use the new column names when we had to create them. (This allows the migration to be rolled back without incident.) # Big Scary Warning There are two things here that may trip up large instances: 1. The change for tables' "id" columns is not concurrent. In particular, the stream_entries table may be big, and does not concurrently migrate its id column. (On the other hand, x_id type columns are all concurrent.) 2. This migration will take a long time to run, *but it should not lock tables during that time* (with the exception of the "id" columns as described above). That means this should probably be run in `screen` or some other session that can be run for a long time. Notably, the migration will take *longer* than it would without these changes, but the website will still be responsive during that time. These changes were tested on a relatively large statuses table (256k entries), and the service remained responsive during the migration. Migrations both forward and backward were tested. * Rubocop fixes * MigrationHelpers: Support ID columns in some cases This doesn't work in cases where the ID column is referred to as a foreign key by another table. * MigrationHelpers: support foreign keys for ID cols Note that this does not yet support foreign keys on non-primary-key columns, but Mastodon also doesn't yet have any that we've needed to migrate. This means we can perform fully "concurrent" migrations to change ID column types, and the IdsToBigints migration can happen with effectively no downtime. (A few operations require a transaction, such as renaming columns or deleting them, but these transactions should not block for noticeable amounts of time.) The algorithm for generating foreign key names has changed with this, and therefore all of those changed in schema.rb. * Provide status, allow for interruptions The MigrationHelpers now allow restarting the rename of a column if it was interrupted, by removing the old "new column" and re-starting the process. Along with this, they now provide status updates on the changes which are happening, as well as indications about when the changes can be safely interrupted (when there are at least 10 seconds estimated to be left before copying data is complete). The IdsToBigints migration now also sorts the columns it migrates by size, starting with the largest tables. This should provide administrators a worst-case scenario estimate for the length of migrations: each successive change will get faster, giving admins a chance to abort early on if they need to run the migration later. The idea is that this does not force them to try to time interruptions between smaller migrations. * Fix column sorting in IdsToBigints Not a significant change, but it impacts the order of columns in the database and db/schema.rb. * Actually pause before IdsToBigints
7 years ago
Add WebAuthn as an alternative 2FA method (#14466) * feat: add possibility of adding WebAuthn security keys to use as 2FA This adds a basic UI for enabling WebAuthn 2FA. We did a little refactor to the Settings page for editing the 2FA methods – now it will list the methods that are available to the user (TOTP and WebAuthn) and from there they'll be able to add or remove any of them. Also, it's worth mentioning that for enabling WebAuthn it's required to have TOTP enabled, so the first time that you go to the 2FA Settings page, you'll be asked to set it up. This work was inspired by the one donde by Github in their platform, and despite it could be approached in different ways, we decided to go with this one given that we feel that this gives a great UX. Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: add request for WebAuthn as second factor at login if enabled This commits adds the feature for using WebAuthn as a second factor for login when enabled. If users have WebAuthn enabled, now a page requesting for the use of a WebAuthn credential for log in will appear, although a link redirecting to the old page for logging in using a two-factor code will also be present. Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: add possibility of deleting WebAuthn Credentials Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: disable WebAuthn when an Admin disables 2FA for a user Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * feat: remove ability to disable TOTP leaving only WebAuthn as 2FA Following examples form other platforms like Github, we decided to make Webauthn 2FA secondary to 2FA with TOTP, so that we removed the possibility of removing TOTP authentication only, leaving users with just WEbAuthn as 2FA. Instead, users will have to click on 'Disable 2FA' in order to remove second factor auth. The reason for WebAuthn being secondary to TOPT is that in that way, users will still be able to log in using their code from their phone's application if they don't have their security keys with them – or maybe even lost them. * We had to change a little the flow for setting up TOTP, given that now it's possible to setting up again if you already had TOTP, in order to let users modify their authenticator app – given that now it's not possible for them to disable TOTP and set it up again with another authenticator app. So, basically, now instead of storing the new `otp_secret` in the user, we store it in the session until the process of set up is finished. This was because, as it was before, when users clicked on 'Edit' in the new two-factor methods lists page, but then went back without finishing the flow, their `otp_secret` had been changed therefore invalidating their previous authenticator app, making them unable to log in again using TOTP. Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com> * refactor: fix eslint errors The PR build was failing given that linting returning some errors. This commit attempts to fix them. * refactor: normalize i18n translations The build was failing given that i18n translations files were not normalized. This commits fixes that. * refactor: avoid having the webauthn gem locked to a specific version * refactor: use symbols for routes without '/' * refactor: avoid sending webauthn disabled email when 2FA is disabled When an admins disable 2FA for users, we were sending two mails to them, one notifying that 2FA was disabled and the other to notify that WebAuthn was disabled. As the second one is redundant since the first email includes it, we can remove it and send just one email to users. * refactor: avoid creating new env variable for webauthn_origin config * refactor: improve flash error messages for webauthn pages Co-authored-by: Facundo Padula <facundo.padula@cedarcode.com>
4 years ago
  1. # This file is auto-generated from the current state of the database. Instead
  2. # of editing this file, please use the migrations feature of Active Record to
  3. # incrementally modify your database, and then regenerate this schema definition.
  4. #
  5. # This file is the source Rails uses to define your schema when running `bin/rails
  6. # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
  7. # be faster and is potentially less error prone than running all of your
  8. # migrations from scratch. Old migrations may fail to apply correctly if those
  9. # migrations use external dependencies or application code.
  10. #
  11. # It's strongly recommended that you check this file into your version control system.
  12. ActiveRecord::Schema.define(version: 2022_08_29_192658) do
  13. # These are extensions that must be enabled in order to support this database
  14. enable_extension "plpgsql"
  15. create_table "account_aliases", force: :cascade do |t|
  16. t.bigint "account_id"
  17. t.string "acct", default: "", null: false
  18. t.string "uri", default: "", null: false
  19. t.datetime "created_at", null: false
  20. t.datetime "updated_at", null: false
  21. t.index ["account_id"], name: "index_account_aliases_on_account_id"
  22. end
  23. create_table "account_conversations", force: :cascade do |t|
  24. t.bigint "account_id"
  25. t.bigint "conversation_id"
  26. t.bigint "participant_account_ids", default: [], null: false, array: true
  27. t.bigint "status_ids", default: [], null: false, array: true
  28. t.bigint "last_status_id"
  29. t.integer "lock_version", default: 0, null: false
  30. t.boolean "unread", default: false, null: false
  31. t.index ["account_id", "conversation_id", "participant_account_ids"], name: "index_unique_conversations", unique: true
  32. t.index ["conversation_id"], name: "index_account_conversations_on_conversation_id"
  33. end
  34. create_table "account_deletion_requests", force: :cascade do |t|
  35. t.bigint "account_id"
  36. t.datetime "created_at", null: false
  37. t.datetime "updated_at", null: false
  38. t.index ["account_id"], name: "index_account_deletion_requests_on_account_id"
  39. end
  40. create_table "account_domain_blocks", force: :cascade do |t|
  41. t.string "domain"
  42. t.datetime "created_at", null: false
  43. t.datetime "updated_at", null: false
  44. t.bigint "account_id"
  45. t.index ["account_id", "domain"], name: "index_account_domain_blocks_on_account_id_and_domain", unique: true
  46. end
  47. create_table "account_migrations", force: :cascade do |t|
  48. t.bigint "account_id"
  49. t.string "acct", default: "", null: false
  50. t.bigint "followers_count", default: 0, null: false
  51. t.bigint "target_account_id"
  52. t.datetime "created_at", null: false
  53. t.datetime "updated_at", null: false
  54. t.index ["account_id"], name: "index_account_migrations_on_account_id"
  55. t.index ["target_account_id"], name: "index_account_migrations_on_target_account_id", where: "(target_account_id IS NOT NULL)"
  56. end
  57. create_table "account_moderation_notes", force: :cascade do |t|
  58. t.text "content", null: false
  59. t.bigint "account_id", null: false
  60. t.bigint "target_account_id", null: false
  61. t.datetime "created_at", null: false
  62. t.datetime "updated_at", null: false
  63. t.index ["account_id"], name: "index_account_moderation_notes_on_account_id"
  64. t.index ["target_account_id"], name: "index_account_moderation_notes_on_target_account_id"
  65. end
  66. create_table "account_notes", force: :cascade do |t|
  67. t.bigint "account_id"
  68. t.bigint "target_account_id"
  69. t.text "comment", null: false
  70. t.datetime "created_at", null: false
  71. t.datetime "updated_at", null: false
  72. t.index ["account_id", "target_account_id"], name: "index_account_notes_on_account_id_and_target_account_id", unique: true
  73. t.index ["target_account_id"], name: "index_account_notes_on_target_account_id"
  74. end
  75. create_table "account_pins", force: :cascade do |t|
  76. t.bigint "account_id"
  77. t.bigint "target_account_id"
  78. t.datetime "created_at", null: false
  79. t.datetime "updated_at", null: false
  80. t.index ["account_id", "target_account_id"], name: "index_account_pins_on_account_id_and_target_account_id", unique: true
  81. t.index ["target_account_id"], name: "index_account_pins_on_target_account_id"
  82. end
  83. create_table "account_stats", force: :cascade do |t|
  84. t.bigint "account_id", null: false
  85. t.bigint "statuses_count", default: 0, null: false
  86. t.bigint "following_count", default: 0, null: false
  87. t.bigint "followers_count", default: 0, null: false
  88. t.datetime "created_at", null: false
  89. t.datetime "updated_at", null: false
  90. t.datetime "last_status_at"
  91. t.index ["account_id"], name: "index_account_stats_on_account_id", unique: true
  92. end
  93. create_table "account_statuses_cleanup_policies", force: :cascade do |t|
  94. t.bigint "account_id", null: false
  95. t.boolean "enabled", default: true, null: false
  96. t.integer "min_status_age", default: 1209600, null: false
  97. t.boolean "keep_direct", default: true, null: false
  98. t.boolean "keep_pinned", default: true, null: false
  99. t.boolean "keep_polls", default: false, null: false
  100. t.boolean "keep_media", default: false, null: false
  101. t.boolean "keep_self_fav", default: true, null: false
  102. t.boolean "keep_self_bookmark", default: true, null: false
  103. t.integer "min_favs"
  104. t.integer "min_reblogs"
  105. t.datetime "created_at", precision: 6, null: false
  106. t.datetime "updated_at", precision: 6, null: false
  107. t.index ["account_id"], name: "index_account_statuses_cleanup_policies_on_account_id"
  108. end
  109. create_table "account_warning_presets", force: :cascade do |t|
  110. t.text "text", default: "", null: false
  111. t.datetime "created_at", null: false
  112. t.datetime "updated_at", null: false
  113. t.string "title", default: "", null: false
  114. end
  115. create_table "account_warnings", force: :cascade do |t|
  116. t.bigint "account_id"
  117. t.bigint "target_account_id"
  118. t.integer "action", default: 0, null: false
  119. t.text "text", default: "", null: false
  120. t.datetime "created_at", null: false
  121. t.datetime "updated_at", null: false
  122. t.bigint "report_id"
  123. t.string "status_ids", array: true
  124. t.datetime "overruled_at"
  125. t.index ["account_id"], name: "index_account_warnings_on_account_id"
  126. t.index ["target_account_id"], name: "index_account_warnings_on_target_account_id"
  127. end
  128. create_table "accounts", id: :bigint, default: -> { "timestamp_id('accounts'::text)" }, force: :cascade do |t|
  129. t.string "username", default: "", null: false
  130. t.string "domain"
  131. t.text "private_key"
  132. t.text "public_key", default: "", null: false
  133. t.datetime "created_at", null: false
  134. t.datetime "updated_at", null: false
  135. t.text "note", default: "", null: false
  136. t.string "display_name", default: "", null: false
  137. t.string "uri", default: "", null: false
  138. t.string "url"
  139. t.string "avatar_file_name"
  140. t.string "avatar_content_type"
  141. t.integer "avatar_file_size"
  142. t.datetime "avatar_updated_at"
  143. t.string "header_file_name"
  144. t.string "header_content_type"
  145. t.integer "header_file_size"
  146. t.datetime "header_updated_at"
  147. t.string "avatar_remote_url"
  148. t.boolean "locked", default: false, null: false
  149. t.string "header_remote_url", default: "", null: false
  150. t.datetime "last_webfingered_at"
  151. t.string "inbox_url", default: "", null: false
  152. t.string "outbox_url", default: "", null: false
  153. t.string "shared_inbox_url", default: "", null: false
  154. t.string "followers_url", default: "", null: false
  155. t.integer "protocol", default: 0, null: false
  156. t.boolean "memorial", default: false, null: false
  157. t.bigint "moved_to_account_id"
  158. t.string "featured_collection_url"
  159. t.jsonb "fields"
  160. t.string "actor_type"
  161. t.boolean "discoverable"
  162. t.string "also_known_as", array: true
  163. t.datetime "silenced_at"
  164. t.datetime "suspended_at"
  165. t.boolean "hide_collections"
  166. t.integer "avatar_storage_schema_version"
  167. t.integer "header_storage_schema_version"
  168. t.string "devices_url"
  169. t.integer "suspension_origin"
  170. t.datetime "sensitized_at"
  171. t.boolean "trendable"
  172. t.datetime "reviewed_at"
  173. t.datetime "requested_review_at"
  174. t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
  175. t.index "lower((username)::text), COALESCE(lower((domain)::text), ''::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
  176. t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id", where: "(moved_to_account_id IS NOT NULL)"
  177. t.index ["uri"], name: "index_accounts_on_uri"
  178. t.index ["url"], name: "index_accounts_on_url", opclass: :text_pattern_ops, where: "(url IS NOT NULL)"
  179. end
  180. create_table "accounts_tags", id: false, force: :cascade do |t|
  181. t.bigint "account_id", null: false
  182. t.bigint "tag_id", null: false
  183. t.index ["account_id", "tag_id"], name: "index_accounts_tags_on_account_id_and_tag_id"
  184. t.index ["tag_id", "account_id"], name: "index_accounts_tags_on_tag_id_and_account_id", unique: true
  185. end
  186. create_table "admin_action_logs", force: :cascade do |t|
  187. t.bigint "account_id"
  188. t.string "action", default: "", null: false
  189. t.string "target_type"
  190. t.bigint "target_id"
  191. t.datetime "created_at", null: false
  192. t.datetime "updated_at", null: false
  193. t.string "human_identifier"
  194. t.string "route_param"
  195. t.string "permalink"
  196. t.index ["account_id"], name: "index_admin_action_logs_on_account_id"
  197. t.index ["target_type", "target_id"], name: "index_admin_action_logs_on_target_type_and_target_id"
  198. end
  199. create_table "announcement_mutes", force: :cascade do |t|
  200. t.bigint "account_id"
  201. t.bigint "announcement_id"
  202. t.datetime "created_at", null: false
  203. t.datetime "updated_at", null: false
  204. t.index ["account_id", "announcement_id"], name: "index_announcement_mutes_on_account_id_and_announcement_id", unique: true
  205. t.index ["announcement_id"], name: "index_announcement_mutes_on_announcement_id"
  206. end
  207. create_table "announcement_reactions", force: :cascade do |t|
  208. t.bigint "account_id"
  209. t.bigint "announcement_id"
  210. t.string "name", default: "", null: false
  211. t.bigint "custom_emoji_id"
  212. t.datetime "created_at", null: false
  213. t.datetime "updated_at", null: false
  214. t.index ["account_id", "announcement_id", "name"], name: "index_announcement_reactions_on_account_id_and_announcement_id", unique: true
  215. t.index ["announcement_id"], name: "index_announcement_reactions_on_announcement_id"
  216. t.index ["custom_emoji_id"], name: "index_announcement_reactions_on_custom_emoji_id", where: "(custom_emoji_id IS NOT NULL)"
  217. end
  218. create_table "announcements", force: :cascade do |t|
  219. t.text "text", default: "", null: false
  220. t.boolean "published", default: false, null: false
  221. t.boolean "all_day", default: false, null: false
  222. t.datetime "scheduled_at"
  223. t.datetime "starts_at"
  224. t.datetime "ends_at"
  225. t.datetime "created_at", null: false
  226. t.datetime "updated_at", null: false
  227. t.datetime "published_at"
  228. t.bigint "status_ids", array: true
  229. end
  230. create_table "appeals", force: :cascade do |t|
  231. t.bigint "account_id", null: false
  232. t.bigint "account_warning_id", null: false
  233. t.text "text", default: "", null: false
  234. t.datetime "approved_at"
  235. t.bigint "approved_by_account_id"
  236. t.datetime "rejected_at"
  237. t.bigint "rejected_by_account_id"
  238. t.datetime "created_at", precision: 6, null: false
  239. t.datetime "updated_at", precision: 6, null: false
  240. t.index ["account_id"], name: "index_appeals_on_account_id"
  241. t.index ["account_warning_id"], name: "index_appeals_on_account_warning_id", unique: true
  242. t.index ["approved_by_account_id"], name: "index_appeals_on_approved_by_account_id", where: "(approved_by_account_id IS NOT NULL)"
  243. t.index ["rejected_by_account_id"], name: "index_appeals_on_rejected_by_account_id", where: "(rejected_by_account_id IS NOT NULL)"
  244. end
  245. create_table "backups", force: :cascade do |t|
  246. t.bigint "user_id"
  247. t.string "dump_file_name"
  248. t.string "dump_content_type"
  249. t.datetime "dump_updated_at"
  250. t.boolean "processed", default: false, null: false
  251. t.datetime "created_at", null: false
  252. t.datetime "updated_at", null: false
  253. t.bigint "dump_file_size"
  254. end
  255. create_table "blocks", force: :cascade do |t|
  256. t.datetime "created_at", null: false
  257. t.datetime "updated_at", null: false
  258. t.bigint "account_id", null: false
  259. t.bigint "target_account_id", null: false
  260. t.string "uri"
  261. t.index ["account_id", "target_account_id"], name: "index_blocks_on_account_id_and_target_account_id", unique: true
  262. t.index ["target_account_id"], name: "index_blocks_on_target_account_id"
  263. end
  264. create_table "bookmarks", force: :cascade do |t|
  265. t.bigint "account_id", null: false
  266. t.bigint "status_id", null: false
  267. t.datetime "created_at", null: false
  268. t.datetime "updated_at", null: false
  269. t.index ["account_id", "status_id"], name: "index_bookmarks_on_account_id_and_status_id", unique: true
  270. t.index ["status_id"], name: "index_bookmarks_on_status_id"
  271. end
  272. create_table "canonical_email_blocks", force: :cascade do |t|
  273. t.string "canonical_email_hash", default: "", null: false
  274. t.bigint "reference_account_id"
  275. t.datetime "created_at", precision: 6, null: false
  276. t.datetime "updated_at", precision: 6, null: false
  277. t.index ["canonical_email_hash"], name: "index_canonical_email_blocks_on_canonical_email_hash", unique: true
  278. t.index ["reference_account_id"], name: "index_canonical_email_blocks_on_reference_account_id"
  279. end
  280. create_table "conversation_mutes", force: :cascade do |t|
  281. t.bigint "conversation_id", null: false
  282. t.bigint "account_id", null: false
  283. t.index ["account_id", "conversation_id"], name: "index_conversation_mutes_on_account_id_and_conversation_id", unique: true
  284. end
  285. create_table "conversations", force: :cascade do |t|
  286. t.string "uri"
  287. t.datetime "created_at", null: false
  288. t.datetime "updated_at", null: false
  289. t.index ["uri"], name: "index_conversations_on_uri", unique: true, opclass: :text_pattern_ops, where: "(uri IS NOT NULL)"
  290. end
  291. create_table "custom_emoji_categories", force: :cascade do |t|
  292. t.string "name"
  293. t.datetime "created_at", null: false
  294. t.datetime "updated_at", null: false
  295. t.index ["name"], name: "index_custom_emoji_categories_on_name", unique: true
  296. end
  297. create_table "custom_emojis", force: :cascade do |t|
  298. t.string "shortcode", default: "", null: false
  299. t.string "domain"
  300. t.string "image_file_name"
  301. t.string "image_content_type"
  302. t.integer "image_file_size"
  303. t.datetime "image_updated_at"
  304. t.datetime "created_at", null: false
  305. t.datetime "updated_at", null: false
  306. t.boolean "disabled", default: false, null: false
  307. t.string "uri"
  308. t.string "image_remote_url"
  309. t.boolean "visible_in_picker", default: true, null: false
  310. t.bigint "category_id"
  311. t.integer "image_storage_schema_version"
  312. t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true
  313. end
  314. create_table "custom_filter_keywords", force: :cascade do |t|
  315. t.bigint "custom_filter_id", null: false
  316. t.text "keyword", default: "", null: false
  317. t.boolean "whole_word", default: true, null: false
  318. t.datetime "created_at", precision: 6, null: false
  319. t.datetime "updated_at", precision: 6, null: false
  320. t.index ["custom_filter_id"], name: "index_custom_filter_keywords_on_custom_filter_id"
  321. end
  322. create_table "custom_filter_statuses", force: :cascade do |t|
  323. t.bigint "custom_filter_id", null: false
  324. t.bigint "status_id", null: false
  325. t.datetime "created_at", precision: 6, null: false
  326. t.datetime "updated_at", precision: 6, null: false
  327. t.index ["custom_filter_id"], name: "index_custom_filter_statuses_on_custom_filter_id"
  328. t.index ["status_id"], name: "index_custom_filter_statuses_on_status_id"
  329. end
  330. create_table "custom_filters", force: :cascade do |t|
  331. t.bigint "account_id"
  332. t.datetime "expires_at"
  333. t.text "phrase", default: "", null: false
  334. t.string "context", default: [], null: false, array: true
  335. t.datetime "created_at", null: false
  336. t.datetime "updated_at", null: false
  337. t.integer "action", default: 0, null: false
  338. t.index ["account_id"], name: "index_custom_filters_on_account_id"
  339. end
  340. create_table "devices", force: :cascade do |t|
  341. t.bigint "access_token_id"
  342. t.bigint "account_id"
  343. t.string "device_id", default: "", null: false
  344. t.string "name", default: "", null: false
  345. t.text "fingerprint_key", default: "", null: false
  346. t.text "identity_key", default: "", null: false
  347. t.datetime "created_at", null: false
  348. t.datetime "updated_at", null: false
  349. t.index ["access_token_id"], name: "index_devices_on_access_token_id"
  350. t.index ["account_id"], name: "index_devices_on_account_id"
  351. end
  352. create_table "domain_allows", force: :cascade do |t|
  353. t.string "domain", default: "", null: false
  354. t.datetime "created_at", null: false
  355. t.datetime "updated_at", null: false
  356. t.index ["domain"], name: "index_domain_allows_on_domain", unique: true
  357. end
  358. create_table "domain_blocks", force: :cascade do |t|
  359. t.string "domain", default: "", null: false
  360. t.datetime "created_at", null: false
  361. t.datetime "updated_at", null: false
  362. t.integer "severity", default: 0
  363. t.boolean "reject_media", default: false, null: false
  364. t.boolean "reject_reports", default: false, null: false
  365. t.text "private_comment"
  366. t.text "public_comment"
  367. t.boolean "obfuscate", default: false, null: false
  368. t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true
  369. end
  370. create_table "email_domain_blocks", force: :cascade do |t|
  371. t.string "domain", default: "", null: false
  372. t.datetime "created_at", null: false
  373. t.datetime "updated_at", null: false
  374. t.bigint "parent_id"
  375. t.index ["domain"], name: "index_email_domain_blocks_on_domain", unique: true
  376. end
  377. create_table "encrypted_messages", id: :bigint, default: -> { "timestamp_id('encrypted_messages'::text)" }, force: :cascade do |t|
  378. t.bigint "device_id"
  379. t.bigint "from_account_id"
  380. t.string "from_device_id", default: "", null: false
  381. t.integer "type", default: 0, null: false
  382. t.text "body", default: "", null: false
  383. t.text "digest", default: "", null: false
  384. t.text "message_franking", default: "", null: false
  385. t.datetime "created_at", null: false
  386. t.datetime "updated_at", null: false
  387. t.index ["device_id"], name: "index_encrypted_messages_on_device_id"
  388. t.index ["from_account_id"], name: "index_encrypted_messages_on_from_account_id"
  389. end
  390. create_table "favourites", force: :cascade do |t|
  391. t.datetime "created_at", null: false
  392. t.datetime "updated_at", null: false
  393. t.bigint "account_id", null: false
  394. t.bigint "status_id", null: false
  395. t.index ["account_id", "id"], name: "index_favourites_on_account_id_and_id"
  396. t.index ["account_id", "status_id"], name: "index_favourites_on_account_id_and_status_id", unique: true
  397. t.index ["status_id"], name: "index_favourites_on_status_id"
  398. end
  399. create_table "featured_tags", force: :cascade do |t|
  400. t.bigint "account_id", null: false
  401. t.bigint "tag_id", null: false
  402. t.bigint "statuses_count", default: 0, null: false
  403. t.datetime "last_status_at"
  404. t.datetime "created_at", null: false
  405. t.datetime "updated_at", null: false
  406. t.index ["account_id"], name: "index_featured_tags_on_account_id"
  407. t.index ["tag_id"], name: "index_featured_tags_on_tag_id"
  408. end
  409. create_table "follow_recommendation_suppressions", force: :cascade do |t|
  410. t.bigint "account_id", null: false
  411. t.datetime "created_at", precision: 6, null: false
  412. t.datetime "updated_at", precision: 6, null: false
  413. t.index ["account_id"], name: "index_follow_recommendation_suppressions_on_account_id", unique: true
  414. end
  415. create_table "follow_requests", force: :cascade do |t|
  416. t.datetime "created_at", null: false
  417. t.datetime "updated_at", null: false
  418. t.bigint "account_id", null: false
  419. t.bigint "target_account_id", null: false
  420. t.boolean "show_reblogs", default: true, null: false
  421. t.string "uri"
  422. t.boolean "notify", default: false, null: false
  423. t.string "languages", array: true
  424. t.index ["account_id", "target_account_id"], name: "index_follow_requests_on_account_id_and_target_account_id", unique: true
  425. end
  426. create_table "follows", force: :cascade do |t|
  427. t.datetime "created_at", null: false
  428. t.datetime "updated_at", null: false
  429. t.bigint "account_id", null: false
  430. t.bigint "target_account_id", null: false
  431. t.boolean "show_reblogs", default: true, null: false
  432. t.string "uri"
  433. t.boolean "notify", default: false, null: false
  434. t.string "languages", array: true
  435. t.index ["account_id", "target_account_id"], name: "index_follows_on_account_id_and_target_account_id", unique: true
  436. t.index ["target_account_id"], name: "index_follows_on_target_account_id"
  437. end
  438. create_table "identities", force: :cascade do |t|
  439. t.string "provider", default: "", null: false
  440. t.string "uid", default: "", null: false
  441. t.datetime "created_at", null: false
  442. t.datetime "updated_at", null: false
  443. t.bigint "user_id"
  444. t.index ["user_id"], name: "index_identities_on_user_id"
  445. end
  446. create_table "imports", force: :cascade do |t|
  447. t.integer "type", null: false
  448. t.boolean "approved", default: false, null: false
  449. t.datetime "created_at", null: false
  450. t.datetime "updated_at", null: false
  451. t.string "data_file_name"
  452. t.string "data_content_type"
  453. t.integer "data_file_size"
  454. t.datetime "data_updated_at"
  455. t.bigint "account_id", null: false
  456. t.boolean "overwrite", default: false, null: false
  457. end
  458. create_table "invites", force: :cascade do |t|
  459. t.bigint "user_id", null: false
  460. t.string "code", default: "", null: false
  461. t.datetime "expires_at"
  462. t.integer "max_uses"
  463. t.integer "uses", default: 0, null: false
  464. t.datetime "created_at", null: false
  465. t.datetime "updated_at", null: false
  466. t.boolean "autofollow", default: false, null: false
  467. t.text "comment"
  468. t.index ["code"], name: "index_invites_on_code", unique: true
  469. t.index ["user_id"], name: "index_invites_on_user_id"
  470. end
  471. create_table "ip_blocks", force: :cascade do |t|
  472. t.datetime "created_at", null: false
  473. t.datetime "updated_at", null: false
  474. t.datetime "expires_at"
  475. t.inet "ip", default: "0.0.0.0", null: false
  476. t.integer "severity", default: 0, null: false
  477. t.text "comment", default: "", null: false
  478. end
  479. create_table "list_accounts", force: :cascade do |t|
  480. t.bigint "list_id", null: false
  481. t.bigint "account_id", null: false
  482. t.bigint "follow_id"
  483. t.index ["account_id", "list_id"], name: "index_list_accounts_on_account_id_and_list_id", unique: true
  484. t.index ["follow_id"], name: "index_list_accounts_on_follow_id", where: "(follow_id IS NOT NULL)"
  485. t.index ["list_id", "account_id"], name: "index_list_accounts_on_list_id_and_account_id"
  486. end
  487. create_table "lists", force: :cascade do |t|
  488. t.bigint "account_id", null: false
  489. t.string "title", default: "", null: false
  490. t.datetime "created_at", null: false
  491. t.datetime "updated_at", null: false
  492. t.integer "replies_policy", default: 0, null: false
  493. t.index ["account_id"], name: "index_lists_on_account_id"
  494. end
  495. create_table "login_activities", force: :cascade do |t|
  496. t.bigint "user_id", null: false
  497. t.string "authentication_method"
  498. t.string "provider"
  499. t.boolean "success"
  500. t.string "failure_reason"
  501. t.inet "ip"
  502. t.string "user_agent"
  503. t.datetime "created_at"
  504. t.index ["user_id"], name: "index_login_activities_on_user_id"
  505. end
  506. create_table "markers", force: :cascade do |t|
  507. t.bigint "user_id"
  508. t.string "timeline", default: "", null: false
  509. t.bigint "last_read_id", default: 0, null: false
  510. t.integer "lock_version", default: 0, null: false
  511. t.datetime "created_at", null: false
  512. t.datetime "updated_at", null: false
  513. t.index ["user_id", "timeline"], name: "index_markers_on_user_id_and_timeline", unique: true
  514. end
  515. create_table "media_attachments", id: :bigint, default: -> { "timestamp_id('media_attachments'::text)" }, force: :cascade do |t|
  516. t.bigint "status_id"
  517. t.string "file_file_name"
  518. t.string "file_content_type"
  519. t.integer "file_file_size"
  520. t.datetime "file_updated_at"
  521. t.string "remote_url", default: "", null: false
  522. t.datetime "created_at", null: false
  523. t.datetime "updated_at", null: false
  524. t.string "shortcode"
  525. t.integer "type", default: 0, null: false
  526. t.json "file_meta"
  527. t.bigint "account_id"
  528. t.text "description"
  529. t.bigint "scheduled_status_id"
  530. t.string "blurhash"
  531. t.integer "processing"
  532. t.integer "file_storage_schema_version"
  533. t.string "thumbnail_file_name"
  534. t.string "thumbnail_content_type"
  535. t.integer "thumbnail_file_size"
  536. t.datetime "thumbnail_updated_at"
  537. t.string "thumbnail_remote_url"
  538. t.index ["account_id", "status_id"], name: "index_media_attachments_on_account_id_and_status_id", order: { status_id: :desc }
  539. t.index ["scheduled_status_id"], name: "index_media_attachments_on_scheduled_status_id", where: "(scheduled_status_id IS NOT NULL)"
  540. t.index ["shortcode"], name: "index_media_attachments_on_shortcode", unique: true, opclass: :text_pattern_ops, where: "(shortcode IS NOT NULL)"
  541. t.index ["status_id"], name: "index_media_attachments_on_status_id"
  542. end
  543. create_table "mentions", force: :cascade do |t|
  544. t.bigint "status_id"
  545. t.datetime "created_at", null: false
  546. t.datetime "updated_at", null: false
  547. t.bigint "account_id"
  548. t.boolean "silent", default: false, null: false
  549. t.index ["account_id", "status_id"], name: "index_mentions_on_account_id_and_status_id", unique: true
  550. t.index ["status_id"], name: "index_mentions_on_status_id"
  551. end
  552. create_table "mutes", force: :cascade do |t|
  553. t.datetime "created_at", null: false
  554. t.datetime "updated_at", null: false
  555. t.boolean "hide_notifications", default: true, null: false
  556. t.bigint "account_id", null: false
  557. t.bigint "target_account_id", null: false
  558. t.datetime "expires_at"
  559. t.index ["account_id", "target_account_id"], name: "index_mutes_on_account_id_and_target_account_id", unique: true
  560. t.index ["target_account_id"], name: "index_mutes_on_target_account_id"
  561. end
  562. create_table "notifications", force: :cascade do |t|
  563. t.bigint "activity_id", null: false
  564. t.string "activity_type", null: false
  565. t.datetime "created_at", null: false
  566. t.datetime "updated_at", null: false
  567. t.bigint "account_id", null: false
  568. t.bigint "from_account_id", null: false
  569. t.string "type"
  570. t.index ["account_id", "id", "type"], name: "index_notifications_on_account_id_and_id_and_type", order: { id: :desc }
  571. t.index ["activity_id", "activity_type"], name: "index_notifications_on_activity_id_and_activity_type"
  572. t.index ["from_account_id"], name: "index_notifications_on_from_account_id"
  573. end
  574. create_table "oauth_access_grants", force: :cascade do |t|
  575. t.string "token", null: false
  576. t.integer "expires_in", null: false
  577. t.text "redirect_uri", null: false
  578. t.datetime "created_at", null: false
  579. t.datetime "revoked_at"
  580. t.string "scopes"
  581. t.bigint "application_id", null: false
  582. t.bigint "resource_owner_id", null: false
  583. t.index ["resource_owner_id"], name: "index_oauth_access_grants_on_resource_owner_id"
  584. t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true
  585. end
  586. create_table "oauth_access_tokens", force: :cascade do |t|
  587. t.string "token", null: false
  588. t.string "refresh_token"
  589. t.integer "expires_in"
  590. t.datetime "revoked_at"
  591. t.datetime "created_at", null: false
  592. t.string "scopes"
  593. t.bigint "application_id"
  594. t.bigint "resource_owner_id"
  595. t.datetime "last_used_at"
  596. t.inet "last_used_ip"
  597. t.index ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true, opclass: :text_pattern_ops, where: "(refresh_token IS NOT NULL)"
  598. t.index ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id", where: "(resource_owner_id IS NOT NULL)"
  599. t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true
  600. end
  601. create_table "oauth_applications", force: :cascade do |t|
  602. t.string "name", null: false
  603. t.string "uid", null: false
  604. t.string "secret", null: false
  605. t.text "redirect_uri", null: false
  606. t.string "scopes", default: "", null: false
  607. t.datetime "created_at"
  608. t.datetime "updated_at"
  609. t.boolean "superapp", default: false, null: false
  610. t.string "website"
  611. t.string "owner_type"
  612. t.bigint "owner_id"
  613. t.boolean "confidential", default: true, null: false
  614. t.index ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type"
  615. t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true
  616. end
  617. create_table "one_time_keys", force: :cascade do |t|
  618. t.bigint "device_id"
  619. t.string "key_id", default: "", null: false
  620. t.text "key", default: "", null: false
  621. t.text "signature", default: "", null: false
  622. t.datetime "created_at", null: false
  623. t.datetime "updated_at", null: false
  624. t.index ["device_id"], name: "index_one_time_keys_on_device_id"
  625. t.index ["key_id"], name: "index_one_time_keys_on_key_id"
  626. end
  627. create_table "pghero_space_stats", force: :cascade do |t|
  628. t.text "database"
  629. t.text "schema"
  630. t.text "relation"
  631. t.bigint "size"
  632. t.datetime "captured_at"
  633. t.index ["database", "captured_at"], name: "index_pghero_space_stats_on_database_and_captured_at"
  634. end
  635. create_table "poll_votes", force: :cascade do |t|
  636. t.bigint "account_id"
  637. t.bigint "poll_id"
  638. t.integer "choice", default: 0, null: false
  639. t.datetime "created_at", null: false
  640. t.datetime "updated_at", null: false
  641. t.string "uri"
  642. t.index ["account_id"], name: "index_poll_votes_on_account_id"
  643. t.index ["poll_id"], name: "index_poll_votes_on_poll_id"
  644. end
  645. create_table "polls", force: :cascade do |t|
  646. t.bigint "account_id"
  647. t.bigint "status_id"
  648. t.datetime "expires_at"
  649. t.string "options", default: [], null: false, array: true
  650. t.bigint "cached_tallies", default: [], null: false, array: true
  651. t.boolean "multiple", default: false, null: false
  652. t.boolean "hide_totals", default: false, null: false
  653. t.bigint "votes_count", default: 0, null: false
  654. t.datetime "last_fetched_at"
  655. t.datetime "created_at", null: false
  656. t.datetime "updated_at", null: false
  657. t.integer "lock_version", default: 0, null: false
  658. t.bigint "voters_count"
  659. t.index ["account_id"], name: "index_polls_on_account_id"
  660. t.index ["status_id"], name: "index_polls_on_status_id"
  661. end
  662. create_table "preview_card_providers", force: :cascade do |t|
  663. t.string "domain", default: "", null: false
  664. t.string "icon_file_name"
  665. t.string "icon_content_type"
  666. t.bigint "icon_file_size"
  667. t.datetime "icon_updated_at"
  668. t.boolean "trendable"
  669. t.datetime "reviewed_at"
  670. t.datetime "requested_review_at"
  671. t.datetime "created_at", precision: 6, null: false
  672. t.datetime "updated_at", precision: 6, null: false
  673. t.index ["domain"], name: "index_preview_card_providers_on_domain", unique: true
  674. end
  675. create_table "preview_cards", force: :cascade do |t|
  676. t.string "url", default: "", null: false
  677. t.string "title", default: "", null: false
  678. t.string "description", default: "", null: false
  679. t.string "image_file_name"
  680. t.string "image_content_type"
  681. t.integer "image_file_size"
  682. t.datetime "image_updated_at"
  683. t.integer "type", default: 0, null: false
  684. t.text "html", default: "", null: false
  685. t.string "author_name", default: "", null: false
  686. t.string "author_url", default: "", null: false
  687. t.string "provider_name", default: "", null: false
  688. t.string "provider_url", default: "", null: false
  689. t.integer "width", default: 0, null: false
  690. t.integer "height", default: 0, null: false
  691. t.datetime "created_at", null: false
  692. t.datetime "updated_at", null: false
  693. t.string "embed_url", default: "", null: false
  694. t.integer "image_storage_schema_version"
  695. t.string "blurhash"
  696. t.string "language"
  697. t.float "max_score"
  698. t.datetime "max_score_at"
  699. t.boolean "trendable"
  700. t.integer "link_type"
  701. t.index ["url"], name: "index_preview_cards_on_url", unique: true
  702. end
  703. create_table "preview_cards_statuses", id: false, force: :cascade do |t|
  704. t.bigint "preview_card_id", null: false
  705. t.bigint "status_id", null: false
  706. t.index ["status_id", "preview_card_id"], name: "index_preview_cards_statuses_on_status_id_and_preview_card_id"
  707. end
  708. create_table "relays", force: :cascade do |t|
  709. t.string "inbox_url", default: "", null: false
  710. t.string "follow_activity_id"
  711. t.datetime "created_at", null: false
  712. t.datetime "updated_at", null: false
  713. t.integer "state", default: 0, null: false
  714. end
  715. create_table "report_notes", force: :cascade do |t|
  716. t.text "content", null: false
  717. t.bigint "report_id", null: false
  718. t.bigint "account_id", null: false
  719. t.datetime "created_at", null: false
  720. t.datetime "updated_at", null: false
  721. t.index ["account_id"], name: "index_report_notes_on_account_id"
  722. t.index ["report_id"], name: "index_report_notes_on_report_id"
  723. end
  724. create_table "reports", force: :cascade do |t|
  725. t.bigint "status_ids", default: [], null: false, array: true
  726. t.text "comment", default: "", null: false
  727. t.datetime "created_at", null: false
  728. t.datetime "updated_at", null: false
  729. t.bigint "account_id", null: false
  730. t.bigint "action_taken_by_account_id"
  731. t.bigint "target_account_id", null: false
  732. t.bigint "assigned_account_id"
  733. t.string "uri"
  734. t.boolean "forwarded"
  735. t.integer "category", default: 0, null: false
  736. t.datetime "action_taken_at"
  737. t.bigint "rule_ids", array: true
  738. t.index ["account_id"], name: "index_reports_on_account_id"
  739. t.index ["action_taken_by_account_id"], name: "index_reports_on_action_taken_by_account_id", where: "(action_taken_by_account_id IS NOT NULL)"
  740. t.index ["assigned_account_id"], name: "index_reports_on_assigned_account_id", where: "(assigned_account_id IS NOT NULL)"
  741. t.index ["target_account_id"], name: "index_reports_on_target_account_id"
  742. end
  743. create_table "rules", force: :cascade do |t|
  744. t.integer "priority", default: 0, null: false
  745. t.datetime "deleted_at"
  746. t.text "text", default: "", null: false
  747. t.datetime "created_at", null: false
  748. t.datetime "updated_at", null: false
  749. end
  750. create_table "scheduled_statuses", force: :cascade do |t|
  751. t.bigint "account_id"
  752. t.datetime "scheduled_at"
  753. t.jsonb "params"
  754. t.index ["account_id"], name: "index_scheduled_statuses_on_account_id"
  755. t.index ["scheduled_at"], name: "index_scheduled_statuses_on_scheduled_at"
  756. end
  757. create_table "session_activations", force: :cascade do |t|
  758. t.string "session_id", null: false
  759. t.datetime "created_at", null: false
  760. t.datetime "updated_at", null: false
  761. t.string "user_agent", default: "", null: false
  762. t.inet "ip"
  763. t.bigint "access_token_id"
  764. t.bigint "user_id", null: false
  765. t.bigint "web_push_subscription_id"
  766. t.index ["access_token_id"], name: "index_session_activations_on_access_token_id"
  767. t.index ["session_id"], name: "index_session_activations_on_session_id", unique: true
  768. t.index ["user_id"], name: "index_session_activations_on_user_id"
  769. end
  770. create_table "settings", force: :cascade do |t|
  771. t.string "var", null: false
  772. t.text "value"
  773. t.string "thing_type"
  774. t.datetime "created_at"
  775. t.datetime "updated_at"
  776. t.bigint "thing_id"
  777. t.index ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true
  778. end
  779. create_table "site_uploads", force: :cascade do |t|
  780. t.string "var", default: "", null: false
  781. t.string "file_file_name"
  782. t.string "file_content_type"
  783. t.integer "file_file_size"
  784. t.datetime "file_updated_at"
  785. t.json "meta"
  786. t.datetime "created_at", null: false
  787. t.datetime "updated_at", null: false
  788. t.index ["var"], name: "index_site_uploads_on_var", unique: true
  789. end
  790. create_table "status_edits", force: :cascade do |t|
  791. t.bigint "status_id", null: false
  792. t.bigint "account_id"
  793. t.text "text", default: "", null: false
  794. t.text "spoiler_text", default: "", null: false
  795. t.datetime "created_at", precision: 6, null: false
  796. t.datetime "updated_at", precision: 6, null: false
  797. t.string "content_type"
  798. t.bigint "ordered_media_attachment_ids", array: true
  799. t.text "media_descriptions", array: true
  800. t.string "poll_options", array: true
  801. t.boolean "sensitive"
  802. t.index ["account_id"], name: "index_status_edits_on_account_id"
  803. t.index ["status_id"], name: "index_status_edits_on_status_id"
  804. end
  805. create_table "status_pins", force: :cascade do |t|
  806. t.bigint "account_id", null: false
  807. t.bigint "status_id", null: false
  808. t.datetime "created_at", default: -> { "now()" }, null: false
  809. t.datetime "updated_at", default: -> { "now()" }, null: false
  810. t.index ["account_id", "status_id"], name: "index_status_pins_on_account_id_and_status_id", unique: true
  811. t.index ["status_id"], name: "index_status_pins_on_status_id"
  812. end
  813. create_table "status_stats", force: :cascade do |t|
  814. t.bigint "status_id", null: false
  815. t.bigint "replies_count", default: 0, null: false
  816. t.bigint "reblogs_count", default: 0, null: false
  817. t.bigint "favourites_count", default: 0, null: false
  818. t.datetime "created_at", null: false
  819. t.datetime "updated_at", null: false
  820. t.index ["status_id"], name: "index_status_stats_on_status_id", unique: true
  821. end
  822. create_table "statuses", id: :bigint, default: -> { "timestamp_id('statuses'::text)" }, force: :cascade do |t|
  823. t.string "uri"
  824. t.text "text", default: "", null: false
  825. t.datetime "created_at", null: false
  826. t.datetime "updated_at", null: false
  827. t.bigint "in_reply_to_id"
  828. t.bigint "reblog_of_id"
  829. t.string "url"
  830. t.boolean "sensitive", default: false, null: false
  831. t.integer "visibility", default: 0, null: false
  832. t.text "spoiler_text", default: "", null: false
  833. t.boolean "reply", default: false, null: false
  834. t.string "language"
  835. t.bigint "conversation_id"
  836. t.boolean "local"
  837. t.bigint "account_id", null: false
  838. t.bigint "application_id"
  839. t.bigint "in_reply_to_account_id"
  840. t.boolean "local_only"
  841. t.bigint "poll_id"
  842. t.string "content_type"
  843. t.datetime "deleted_at"
  844. t.datetime "edited_at"
  845. t.boolean "trendable"
  846. t.bigint "ordered_media_attachment_ids", array: true
  847. t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20190820", order: { id: :desc }, where: "(deleted_at IS NULL)"
  848. t.index ["account_id"], name: "index_statuses_on_account_id"
  849. t.index ["deleted_at"], name: "index_statuses_on_deleted_at", where: "(deleted_at IS NOT NULL)"
  850. t.index ["id", "account_id"], name: "index_statuses_local_20190824", order: { id: :desc }, where: "((local OR (uri IS NULL)) AND (deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))"
  851. t.index ["id", "account_id"], name: "index_statuses_public_20200119", order: { id: :desc }, where: "((deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))"
  852. t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id", where: "(in_reply_to_account_id IS NOT NULL)"
  853. t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id", where: "(in_reply_to_id IS NOT NULL)"
  854. t.index ["reblog_of_id", "account_id"], name: "index_statuses_on_reblog_of_id_and_account_id"
  855. t.index ["uri"], name: "index_statuses_on_uri", unique: true, opclass: :text_pattern_ops, where: "(uri IS NOT NULL)"
  856. end
  857. create_table "statuses_tags", id: false, force: :cascade do |t|
  858. t.bigint "status_id", null: false
  859. t.bigint "tag_id", null: false
  860. t.index ["status_id"], name: "index_statuses_tags_on_status_id"
  861. t.index ["tag_id", "status_id"], name: "index_statuses_tags_on_tag_id_and_status_id", unique: true
  862. end
  863. create_table "system_keys", force: :cascade do |t|
  864. t.binary "key"
  865. t.datetime "created_at", null: false
  866. t.datetime "updated_at", null: false
  867. end
  868. create_table "tag_follows", force: :cascade do |t|
  869. t.bigint "tag_id", null: false
  870. t.bigint "account_id", null: false
  871. t.datetime "created_at", precision: 6, null: false
  872. t.datetime "updated_at", precision: 6, null: false
  873. t.index ["account_id", "tag_id"], name: "index_tag_follows_on_account_id_and_tag_id", unique: true
  874. t.index ["tag_id"], name: "index_tag_follows_on_tag_id"
  875. end
  876. create_table "tags", force: :cascade do |t|
  877. t.string "name", default: "", null: false
  878. t.datetime "created_at", null: false
  879. t.datetime "updated_at", null: false
  880. t.boolean "usable"
  881. t.boolean "trendable"
  882. t.boolean "listable"
  883. t.datetime "reviewed_at"
  884. t.datetime "requested_review_at"
  885. t.datetime "last_status_at"
  886. t.float "max_score"
  887. t.datetime "max_score_at"
  888. t.string "display_name"
  889. t.index "lower((name)::text) text_pattern_ops", name: "index_tags_on_name_lower_btree", unique: true
  890. end
  891. create_table "tombstones", force: :cascade do |t|
  892. t.bigint "account_id"
  893. t.string "uri", null: false
  894. t.datetime "created_at", null: false
  895. t.datetime "updated_at", null: false
  896. t.boolean "by_moderator"
  897. t.index ["account_id"], name: "index_tombstones_on_account_id"
  898. t.index ["uri"], name: "index_tombstones_on_uri"
  899. end
  900. create_table "unavailable_domains", force: :cascade do |t|
  901. t.string "domain", default: "", null: false
  902. t.datetime "created_at", null: false
  903. t.datetime "updated_at", null: false
  904. t.index ["domain"], name: "index_unavailable_domains_on_domain", unique: true
  905. end
  906. create_table "user_invite_requests", force: :cascade do |t|
  907. t.bigint "user_id"
  908. t.text "text"
  909. t.datetime "created_at", null: false
  910. t.datetime "updated_at", null: false
  911. t.index ["user_id"], name: "index_user_invite_requests_on_user_id"
  912. end
  913. create_table "user_roles", force: :cascade do |t|
  914. t.string "name", default: "", null: false
  915. t.string "color", default: "", null: false
  916. t.integer "position", default: 0, null: false
  917. t.bigint "permissions", default: 0, null: false
  918. t.boolean "highlighted", default: false, null: false
  919. t.datetime "created_at", precision: 6, null: false
  920. t.datetime "updated_at", precision: 6, null: false
  921. end
  922. create_table "users", force: :cascade do |t|
  923. t.string "email", default: "", null: false
  924. t.datetime "created_at", null: false
  925. t.datetime "updated_at", null: false
  926. t.string "encrypted_password", default: "", null: false
  927. t.string "reset_password_token"
  928. t.datetime "reset_password_sent_at"
  929. t.integer "sign_in_count", default: 0, null: false
  930. t.datetime "current_sign_in_at"
  931. t.datetime "last_sign_in_at"
  932. t.boolean "admin", default: false, null: false
  933. t.string "confirmation_token"
  934. t.datetime "confirmed_at"
  935. t.datetime "confirmation_sent_at"
  936. t.string "unconfirmed_email"
  937. t.string "locale"
  938. t.string "encrypted_otp_secret"
  939. t.string "encrypted_otp_secret_iv"
  940. t.string "encrypted_otp_secret_salt"
  941. t.integer "consumed_timestep"
  942. t.boolean "otp_required_for_login", default: false, null: false
  943. t.datetime "last_emailed_at"
  944. t.string "otp_backup_codes", array: true
  945. t.bigint "account_id", null: false
  946. t.boolean "disabled", default: false, null: false
  947. t.boolean "moderator", default: false, null: false
  948. t.bigint "invite_id"
  949. t.string "chosen_languages", array: true
  950. t.bigint "created_by_application_id"
  951. t.boolean "approved", default: true, null: false
  952. t.string "sign_in_token"
  953. t.datetime "sign_in_token_sent_at"
  954. t.string "webauthn_id"
  955. t.inet "sign_up_ip"
  956. t.boolean "skip_sign_in_token"
  957. t.bigint "role_id"
  958. t.index ["account_id"], name: "index_users_on_account_id"
  959. t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
  960. t.index ["created_by_application_id"], name: "index_users_on_created_by_application_id", where: "(created_by_application_id IS NOT NULL)"
  961. t.index ["email"], name: "index_users_on_email", unique: true
  962. t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, opclass: :text_pattern_ops, where: "(reset_password_token IS NOT NULL)"
  963. t.index ["role_id"], name: "index_users_on_role_id", where: "(role_id IS NOT NULL)"
  964. end
  965. create_table "web_push_subscriptions", force: :cascade do |t|
  966. t.string "endpoint", null: false
  967. t.string "key_p256dh", null: false
  968. t.string "key_auth", null: false
  969. t.json "data"
  970. t.datetime "created_at", null: false
  971. t.datetime "updated_at", null: false
  972. t.bigint "access_token_id"
  973. t.bigint "user_id"
  974. t.index ["access_token_id"], name: "index_web_push_subscriptions_on_access_token_id", where: "(access_token_id IS NOT NULL)"
  975. t.index ["user_id"], name: "index_web_push_subscriptions_on_user_id"
  976. end
  977. create_table "web_settings", force: :cascade do |t|
  978. t.json "data"
  979. t.datetime "created_at", null: false
  980. t.datetime "updated_at", null: false
  981. t.bigint "user_id", null: false
  982. t.index ["user_id"], name: "index_web_settings_on_user_id", unique: true
  983. end
  984. create_table "webauthn_credentials", force: :cascade do |t|
  985. t.string "external_id", null: false
  986. t.string "public_key", null: false
  987. t.string "nickname", null: false
  988. t.bigint "sign_count", default: 0, null: false
  989. t.bigint "user_id"
  990. t.datetime "created_at", null: false
  991. t.datetime "updated_at", null: false
  992. t.index ["external_id"], name: "index_webauthn_credentials_on_external_id", unique: true
  993. t.index ["user_id"], name: "index_webauthn_credentials_on_user_id"
  994. end
  995. create_table "webhooks", force: :cascade do |t|
  996. t.string "url", null: false
  997. t.string "events", default: [], null: false, array: true
  998. t.string "secret", default: "", null: false
  999. t.boolean "enabled", default: true, null: false
  1000. t.datetime "created_at", precision: 6, null: false
  1001. t.datetime "updated_at", precision: 6, null: false
  1002. t.index ["url"], name: "index_webhooks_on_url", unique: true
  1003. end
  1004. add_foreign_key "account_aliases", "accounts", on_delete: :cascade
  1005. add_foreign_key "account_conversations", "accounts", on_delete: :cascade
  1006. add_foreign_key "account_conversations", "conversations", on_delete: :cascade
  1007. add_foreign_key "account_deletion_requests", "accounts", on_delete: :cascade
  1008. add_foreign_key "account_domain_blocks", "accounts", name: "fk_206c6029bd", on_delete: :cascade
  1009. add_foreign_key "account_migrations", "accounts", column: "target_account_id", on_delete: :nullify
  1010. add_foreign_key "account_migrations", "accounts", on_delete: :cascade
  1011. add_foreign_key "account_moderation_notes", "accounts"
  1012. add_foreign_key "account_moderation_notes", "accounts", column: "target_account_id"
  1013. add_foreign_key "account_notes", "accounts", column: "target_account_id", on_delete: :cascade
  1014. add_foreign_key "account_notes", "accounts", on_delete: :cascade
  1015. add_foreign_key "account_pins", "accounts", column: "target_account_id", on_delete: :cascade
  1016. add_foreign_key "account_pins", "accounts", on_delete: :cascade
  1017. add_foreign_key "account_stats", "accounts", on_delete: :cascade
  1018. add_foreign_key "account_statuses_cleanup_policies", "accounts", on_delete: :cascade
  1019. add_foreign_key "account_warnings", "accounts", column: "target_account_id", on_delete: :cascade
  1020. add_foreign_key "account_warnings", "accounts", on_delete: :nullify
  1021. add_foreign_key "account_warnings", "reports", on_delete: :cascade
  1022. add_foreign_key "accounts", "accounts", column: "moved_to_account_id", on_delete: :nullify
  1023. add_foreign_key "admin_action_logs", "accounts", on_delete: :cascade
  1024. add_foreign_key "announcement_mutes", "accounts", on_delete: :cascade
  1025. add_foreign_key "announcement_mutes", "announcements", on_delete: :cascade
  1026. add_foreign_key "announcement_reactions", "accounts", on_delete: :cascade
  1027. add_foreign_key "announcement_reactions", "announcements", on_delete: :cascade
  1028. add_foreign_key "announcement_reactions", "custom_emojis", on_delete: :cascade
  1029. add_foreign_key "appeals", "account_warnings", on_delete: :cascade
  1030. add_foreign_key "appeals", "accounts", column: "approved_by_account_id", on_delete: :nullify
  1031. add_foreign_key "appeals", "accounts", column: "rejected_by_account_id", on_delete: :nullify
  1032. add_foreign_key "appeals", "accounts", on_delete: :cascade
  1033. add_foreign_key "backups", "users", on_delete: :nullify
  1034. add_foreign_key "blocks", "accounts", column: "target_account_id", name: "fk_9571bfabc1", on_delete: :cascade
  1035. add_foreign_key "blocks", "accounts", name: "fk_4269e03e65", on_delete: :cascade
  1036. add_foreign_key "bookmarks", "accounts", on_delete: :cascade
  1037. add_foreign_key "bookmarks", "statuses", on_delete: :cascade
  1038. add_foreign_key "canonical_email_blocks", "accounts", column: "reference_account_id", on_delete: :cascade
  1039. add_foreign_key "conversation_mutes", "accounts", name: "fk_225b4212bb", on_delete: :cascade
  1040. add_foreign_key "conversation_mutes", "conversations", on_delete: :cascade
  1041. add_foreign_key "custom_filter_keywords", "custom_filters", on_delete: :cascade
  1042. add_foreign_key "custom_filter_statuses", "custom_filters", on_delete: :cascade
  1043. add_foreign_key "custom_filter_statuses", "statuses", on_delete: :cascade
  1044. add_foreign_key "custom_filters", "accounts", on_delete: :cascade
  1045. add_foreign_key "devices", "accounts", on_delete: :cascade
  1046. add_foreign_key "devices", "oauth_access_tokens", column: "access_token_id", on_delete: :cascade
  1047. add_foreign_key "email_domain_blocks", "email_domain_blocks", column: "parent_id", on_delete: :cascade
  1048. add_foreign_key "encrypted_messages", "accounts", column: "from_account_id", on_delete: :cascade
  1049. add_foreign_key "encrypted_messages", "devices", on_delete: :cascade
  1050. add_foreign_key "favourites", "accounts", name: "fk_5eb6c2b873", on_delete: :cascade
  1051. add_foreign_key "favourites", "statuses", name: "fk_b0e856845e", on_delete: :cascade
  1052. add_foreign_key "featured_tags", "accounts", on_delete: :cascade
  1053. add_foreign_key "featured_tags", "tags", on_delete: :cascade
  1054. add_foreign_key "follow_recommendation_suppressions", "accounts", on_delete: :cascade
  1055. add_foreign_key "follow_requests", "accounts", column: "target_account_id", name: "fk_9291ec025d", on_delete: :cascade
  1056. add_foreign_key "follow_requests", "accounts", name: "fk_76d644b0e7", on_delete: :cascade
  1057. add_foreign_key "follows", "accounts", column: "target_account_id", name: "fk_745ca29eac", on_delete: :cascade
  1058. add_foreign_key "follows", "accounts", name: "fk_32ed1b5560", on_delete: :cascade
  1059. add_foreign_key "identities", "users", name: "fk_bea040f377", on_delete: :cascade
  1060. add_foreign_key "imports", "accounts", name: "fk_6db1b6e408", on_delete: :cascade
  1061. add_foreign_key "invites", "users", on_delete: :cascade
  1062. add_foreign_key "list_accounts", "accounts", on_delete: :cascade
  1063. add_foreign_key "list_accounts", "follows", on_delete: :cascade
  1064. add_foreign_key "list_accounts", "lists", on_delete: :cascade
  1065. add_foreign_key "lists", "accounts", on_delete: :cascade
  1066. add_foreign_key "login_activities", "users", on_delete: :cascade
  1067. add_foreign_key "markers", "users", on_delete: :cascade
  1068. add_foreign_key "media_attachments", "accounts", name: "fk_96dd81e81b", on_delete: :nullify
  1069. add_foreign_key "media_attachments", "scheduled_statuses", on_delete: :nullify
  1070. add_foreign_key "media_attachments", "statuses", on_delete: :nullify
  1071. add_foreign_key "mentions", "accounts", name: "fk_970d43f9d1", on_delete: :cascade
  1072. add_foreign_key "mentions", "statuses", on_delete: :cascade
  1073. add_foreign_key "mutes", "accounts", column: "target_account_id", name: "fk_eecff219ea", on_delete: :cascade
  1074. add_foreign_key "mutes", "accounts", name: "fk_b8d8daf315", on_delete: :cascade
  1075. add_foreign_key "notifications", "accounts", column: "from_account_id", name: "fk_fbd6b0bf9e", on_delete: :cascade
  1076. add_foreign_key "notifications", "accounts", name: "fk_c141c8ee55", on_delete: :cascade
  1077. add_foreign_key "oauth_access_grants", "oauth_applications", column: "application_id", name: "fk_34d54b0a33", on_delete: :cascade
  1078. add_foreign_key "oauth_access_grants", "users", column: "resource_owner_id", name: "fk_63b044929b", on_delete: :cascade
  1079. add_foreign_key "oauth_access_tokens", "oauth_applications", column: "application_id", name: "fk_f5fc4c1ee3", on_delete: :cascade
  1080. add_foreign_key "oauth_access_tokens", "users", column: "resource_owner_id", name: "fk_e84df68546", on_delete: :cascade
  1081. add_foreign_key "oauth_applications", "users", column: "owner_id", name: "fk_b0988c7c0a", on_delete: :cascade
  1082. add_foreign_key "one_time_keys", "devices", on_delete: :cascade
  1083. add_foreign_key "poll_votes", "accounts", on_delete: :cascade
  1084. add_foreign_key "poll_votes", "polls", on_delete: :cascade
  1085. add_foreign_key "polls", "accounts", on_delete: :cascade
  1086. add_foreign_key "polls", "statuses", on_delete: :cascade
  1087. add_foreign_key "report_notes", "accounts", on_delete: :cascade
  1088. add_foreign_key "report_notes", "reports", on_delete: :cascade
  1089. add_foreign_key "reports", "accounts", column: "action_taken_by_account_id", name: "fk_bca45b75fd", on_delete: :nullify
  1090. add_foreign_key "reports", "accounts", column: "assigned_account_id", on_delete: :nullify
  1091. add_foreign_key "reports", "accounts", column: "target_account_id", name: "fk_eb37af34f0", on_delete: :cascade
  1092. add_foreign_key "reports", "accounts", name: "fk_4b81f7522c", on_delete: :cascade
  1093. add_foreign_key "scheduled_statuses", "accounts", on_delete: :cascade
  1094. add_foreign_key "session_activations", "oauth_access_tokens", column: "access_token_id", name: "fk_957e5bda89", on_delete: :cascade
  1095. add_foreign_key "session_activations", "users", name: "fk_e5fda67334", on_delete: :cascade
  1096. add_foreign_key "status_edits", "accounts", on_delete: :nullify
  1097. add_foreign_key "status_edits", "statuses", on_delete: :cascade
  1098. add_foreign_key "status_pins", "accounts", name: "fk_d4cb435b62", on_delete: :cascade
  1099. add_foreign_key "status_pins", "statuses", on_delete: :cascade
  1100. add_foreign_key "status_stats", "statuses", on_delete: :cascade
  1101. add_foreign_key "statuses", "accounts", column: "in_reply_to_account_id", name: "fk_c7fa917661", on_delete: :nullify
  1102. add_foreign_key "statuses", "accounts", name: "fk_9bda1543f7", on_delete: :cascade
  1103. add_foreign_key "statuses", "statuses", column: "in_reply_to_id", on_delete: :nullify
  1104. add_foreign_key "statuses", "statuses", column: "reblog_of_id", on_delete: :cascade
  1105. add_foreign_key "statuses_tags", "statuses", on_delete: :cascade
  1106. add_foreign_key "statuses_tags", "tags", name: "fk_3081861e21", on_delete: :cascade
  1107. add_foreign_key "tag_follows", "accounts", on_delete: :cascade
  1108. add_foreign_key "tag_follows", "tags", on_delete: :cascade
  1109. add_foreign_key "tombstones", "accounts", on_delete: :cascade
  1110. add_foreign_key "user_invite_requests", "users", on_delete: :cascade
  1111. add_foreign_key "users", "accounts", name: "fk_50500f500d", on_delete: :cascade
  1112. add_foreign_key "users", "invites", on_delete: :nullify
  1113. add_foreign_key "users", "oauth_applications", column: "created_by_application_id", on_delete: :nullify
  1114. add_foreign_key "users", "user_roles", column: "role_id", on_delete: :nullify
  1115. add_foreign_key "web_push_subscriptions", "oauth_access_tokens", column: "access_token_id", on_delete: :cascade
  1116. add_foreign_key "web_push_subscriptions", "users", on_delete: :cascade
  1117. add_foreign_key "web_settings", "users", name: "fk_11910667b2", on_delete: :cascade
  1118. add_foreign_key "webauthn_credentials", "users"
  1119. create_view "instances", materialized: true, sql_definition: <<-SQL
  1120. WITH domain_counts(domain, accounts_count) AS (
  1121. SELECT accounts.domain,
  1122. count(*) AS accounts_count
  1123. FROM accounts
  1124. WHERE (accounts.domain IS NOT NULL)
  1125. GROUP BY accounts.domain
  1126. )
  1127. SELECT domain_counts.domain,
  1128. domain_counts.accounts_count
  1129. FROM domain_counts
  1130. UNION
  1131. SELECT domain_blocks.domain,
  1132. COALESCE(domain_counts.accounts_count, (0)::bigint) AS accounts_count
  1133. FROM (domain_blocks
  1134. LEFT JOIN domain_counts ON (((domain_counts.domain)::text = (domain_blocks.domain)::text)))
  1135. UNION
  1136. SELECT domain_allows.domain,
  1137. COALESCE(domain_counts.accounts_count, (0)::bigint) AS accounts_count
  1138. FROM (domain_allows
  1139. LEFT JOIN domain_counts ON (((domain_counts.domain)::text = (domain_allows.domain)::text)));
  1140. SQL
  1141. add_index "instances", ["domain"], name: "index_instances_on_domain", unique: true
  1142. create_view "user_ips", sql_definition: <<-SQL
  1143. SELECT t0.user_id,
  1144. t0.ip,
  1145. max(t0.used_at) AS used_at
  1146. FROM ( SELECT users.id AS user_id,
  1147. users.sign_up_ip AS ip,
  1148. users.created_at AS used_at
  1149. FROM users
  1150. WHERE (users.sign_up_ip IS NOT NULL)
  1151. UNION ALL
  1152. SELECT session_activations.user_id,
  1153. session_activations.ip,
  1154. session_activations.updated_at
  1155. FROM session_activations
  1156. UNION ALL
  1157. SELECT login_activities.user_id,
  1158. login_activities.ip,
  1159. login_activities.created_at
  1160. FROM login_activities
  1161. WHERE (login_activities.success = true)) t0
  1162. GROUP BY t0.user_id, t0.ip;
  1163. SQL
  1164. create_view "account_summaries", materialized: true, sql_definition: <<-SQL
  1165. SELECT accounts.id AS account_id,
  1166. mode() WITHIN GROUP (ORDER BY t0.language) AS language,
  1167. mode() WITHIN GROUP (ORDER BY t0.sensitive) AS sensitive
  1168. FROM (accounts
  1169. CROSS JOIN LATERAL ( SELECT statuses.account_id,
  1170. statuses.language,
  1171. statuses.sensitive
  1172. FROM statuses
  1173. WHERE ((statuses.account_id = accounts.id) AND (statuses.deleted_at IS NULL) AND (statuses.reblog_of_id IS NULL))
  1174. ORDER BY statuses.id DESC
  1175. LIMIT 20) t0)
  1176. WHERE ((accounts.suspended_at IS NULL) AND (accounts.silenced_at IS NULL) AND (accounts.moved_to_account_id IS NULL) AND (accounts.discoverable = true) AND (accounts.locked = false))
  1177. GROUP BY accounts.id;
  1178. SQL
  1179. add_index "account_summaries", ["account_id"], name: "index_account_summaries_on_account_id", unique: true
  1180. create_view "follow_recommendations", materialized: true, sql_definition: <<-SQL
  1181. SELECT t0.account_id,
  1182. sum(t0.rank) AS rank,
  1183. array_agg(t0.reason) AS reason
  1184. FROM ( SELECT account_summaries.account_id,
  1185. ((count(follows.id))::numeric / (1.0 + (count(follows.id))::numeric)) AS rank,
  1186. 'most_followed'::text AS reason
  1187. FROM (((follows
  1188. JOIN account_summaries ON ((account_summaries.account_id = follows.target_account_id)))
  1189. JOIN users ON ((users.account_id = follows.account_id)))
  1190. LEFT JOIN follow_recommendation_suppressions ON ((follow_recommendation_suppressions.account_id = follows.target_account_id)))
  1191. WHERE ((users.current_sign_in_at >= (now() - 'P30D'::interval)) AND (account_summaries.sensitive = false) AND (follow_recommendation_suppressions.id IS NULL))
  1192. GROUP BY account_summaries.account_id
  1193. HAVING (count(follows.id) >= 5)
  1194. UNION ALL
  1195. SELECT account_summaries.account_id,
  1196. (sum((status_stats.reblogs_count + status_stats.favourites_count)) / (1.0 + sum((status_stats.reblogs_count + status_stats.favourites_count)))) AS rank,
  1197. 'most_interactions'::text AS reason
  1198. FROM (((status_stats
  1199. JOIN statuses ON ((statuses.id = status_stats.status_id)))
  1200. JOIN account_summaries ON ((account_summaries.account_id = statuses.account_id)))
  1201. LEFT JOIN follow_recommendation_suppressions ON ((follow_recommendation_suppressions.account_id = statuses.account_id)))
  1202. WHERE ((statuses.id >= (((date_part('epoch'::text, (now() - 'P30D'::interval)) * (1000)::double precision))::bigint << 16)) AND (account_summaries.sensitive = false) AND (follow_recommendation_suppressions.id IS NULL))
  1203. GROUP BY account_summaries.account_id
  1204. HAVING (sum((status_stats.reblogs_count + status_stats.favourites_count)) >= (5)::numeric)) t0
  1205. GROUP BY t0.account_id
  1206. ORDER BY (sum(t0.rank)) DESC;
  1207. SQL
  1208. add_index "follow_recommendations", ["account_id"], name: "index_follow_recommendations_on_account_id", unique: true
  1209. end