discourse/db/migrate/20220104053343_add_bookmark_polymorphic_columns.rb
Martin Brennan e21c640a3c
DEV: Add polymorphic bookmarkable columns (#15454)
We are planning on attaching bookmarks to more and
more other models, so it makes sense to make a polymorphic
relationship to handle this. This commit adds the new
columns and backfills them in the bookmark table, and
makes sure that any new bookmark changes fill in the columns
via DB triggers.

This way we can gradually change the frontend and backend
to use these new columns, and eventually delete the
old post_id and for_topic columns in `bookmarks`.
2022-01-06 08:56:05 +10:00

11 lines
367 B
Ruby

# frozen_string_literal: true
class AddBookmarkPolymorphicColumns < ActiveRecord::Migration[6.1]
def change
add_column :bookmarks, :bookmarkable_id, :integer
add_column :bookmarks, :bookmarkable_type, :string
add_index :bookmarks, [:user_id, :bookmarkable_type, :bookmarkable_id], name: "idx_bookmarks_user_polymorphic_unique", unique: true
end
end