DEV: Re-add polymorphic bookmark columns (#16261)
This commit is a redo of2f1ddadff7dd47f824070c8a3f633f00a27aacde which we reverted because it blew up an internal CI check. I looked into it, and it happened because the old migration to add the bookmark columns still existed, and those columns were dropped in a post migrate, so the two migrations to add the columns were conflicting before the post migrate was run. ------ This commit only includes the creation of the new columns and index, and does not add any triggers, backfilling, or new data. A backfill will be done in the final PR when we switch this over. Intermediate PRs will look something like this: Add an experimental site setting for using polymorphic bookmarks, and make sure in the places where bookmarks are created or updated we fill in the columns. This setting will be used in subsequent PRs as well. Listing and searching bookmarks based on polymorphic associations Creating post and topic bookmarks using polymorphic associations, and changing special for_topic logic to just rely on the Topic bookmarkable_type Querying bookmark reminders based on polymorphic associations Make sure various other areas like importers, bookmark guardian, and others all rely on the associations Prepare plugins that rely on the Bookmark model to use polymorphic associations The final core PR will remove all the setting gates and switch over to using the polymorphic associations, backfill the bookmarks table columns, and ignore the old post_id and for_topic colummns. Then it will just be a matter of dropping the old columns down the line.
This commit is contained in:
parent
cd7ce52138
commit
8040b95e8c
|
@ -4,8 +4,6 @@ class Bookmark < ActiveRecord::Base
|
|||
# these columns were here for a very short amount of time,
|
||||
# hence the very short ignore time
|
||||
self.ignored_columns = [
|
||||
"bookmarkable_id", # TODO 2022-04-01 remove
|
||||
"bookmarkable_type", # TODO 2022-04-01 remove
|
||||
"topic_id", # TODO 2022-04-01: remove
|
||||
"reminder_type" # TODO 2021-04-01: remove
|
||||
]
|
||||
|
@ -181,9 +179,12 @@ end
|
|||
# auto_delete_preference :integer default(0), not null
|
||||
# pinned :boolean default(FALSE)
|
||||
# for_topic :boolean default(FALSE), not null
|
||||
# bookmarkable_id :integer
|
||||
# bookmarkable_type :string
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# idx_bookmarks_user_polymorphic_unique (user_id,bookmarkable_type,bookmarkable_id) UNIQUE
|
||||
# index_bookmarks_on_post_id (post_id)
|
||||
# index_bookmarks_on_reminder_at (reminder_at)
|
||||
# index_bookmarks_on_reminder_set_at (reminder_set_at)
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DropBookmarkPolymorphicTrigger < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
DB.exec("DROP FUNCTION IF EXISTS sync_bookmarks_polymorphic_column_data CASCADE")
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DropBookmarkPolymorphicColumns < ActiveRecord::Migration[6.1]
|
||||
DROPPED_COLUMNS ||= {
|
||||
bookmarks: %i{bookmarkable_id bookmarkable_type}
|
||||
}
|
||||
|
||||
def up
|
||||
DROPPED_COLUMNS.each do |table, columns|
|
||||
Migration::ColumnDropper.execute_drop(table, columns)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue