diff options
Diffstat (limited to 'db/migrate')
3 files changed, 44 insertions, 0 deletions
diff --git a/db/migrate/20200921024447_add_curated_to_statuses.rb b/db/migrate/20200921024447_add_curated_to_statuses.rb new file mode 100644 index 000000000..05558ded3 --- /dev/null +++ b/db/migrate/20200921024447_add_curated_to_statuses.rb @@ -0,0 +1,7 @@ +class AddCuratedToStatuses < ActiveRecord::Migration[5.2] + def change + safety_assured do + add_column :statuses, :curated, :boolean, default: false, null: false + end + end +end diff --git a/db/migrate/20200921030158_backfill_curated_statuses.rb b/db/migrate/20200921030158_backfill_curated_statuses.rb new file mode 100644 index 000000000..f9bf32afb --- /dev/null +++ b/db/migrate/20200921030158_backfill_curated_statuses.rb @@ -0,0 +1,12 @@ +class BackfillCuratedStatuses < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def up + Status.with_public_visibility.joins(:status_stat).where('favourites_count != 0 OR reblogs_count != 0').in_batches.update_all(curated: true) + Status.with_public_visibility.where(curated: false).left_outer_joins(:bookmarks).where.not(bookmarks: { status_id: nil }).in_batches.update_all(curated: true) + end + + def down + nil + end +end diff --git a/db/migrate/20200923000000_update_status_indexes_202009.rb b/db/migrate/20200923000000_update_status_indexes_202009.rb new file mode 100644 index 000000000..9b6f58d3c --- /dev/null +++ b/db/migrate/20200923000000_update_status_indexes_202009.rb @@ -0,0 +1,25 @@ +class UpdateStatusIndexes202009 < ActiveRecord::Migration[5.2] + def up + safety_assured do + remove_index :statuses, name: "index_statuses_local" + remove_index :statuses, name: "index_statuses_local_reblogs" + remove_index :statuses, name: "index_statuses_public" + + add_index :statuses, :id, name: "index_statuses_local", order: { id: :desc }, where: "(published = TRUE) AND (local = TRUE OR (uri IS NULL)) AND (deleted_at IS NULL)" + add_index :statuses, :id, name: "index_statuses_curated", order: { id: :desc }, where: "(published = TRUE) AND (deleted_at IS NULL) AND (curated = TRUE)" + add_index :statuses, :id, name: "index_statuses_public", order: { id: :desc }, where: "(published = TRUE) AND (deleted_at IS NULL)" + end + end + + def down + safety_assured do + remove_index :statuses, name: "index_statuses_local" + remove_index :statuses, name: "index_statuses_curated" + remove_index :statuses, name: "index_statuses_public" + + add_index :statuses, ["id", "account_id"], name: "index_statuses_local", order: { id: :desc }, where: "((published = TRUE) AND (local = TRUE OR (uri IS NULL)) AND (deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((reply = FALSE) OR (in_reply_to_account_id = account_id)))" + add_index :statuses, ["id", "account_id"], name: "index_statuses_local_reblogs", where: "(((local = TRUE) OR (uri IS NULL)) AND (statuses.reblog_of_id IS NOT NULL))" + add_index :statuses, ["id", "account_id"], name: "index_statuses_public", order: { id: :desc }, where: "((published = TRUE) AND (deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((reply = FALSE) OR (in_reply_to_account_id = account_id)))" + end + end +end |