20211213040746_update_account_summaries_to_version_2.rb 943 B

123456789101112131415161718192021222324
  1. class UpdateAccountSummariesToVersion2 < ActiveRecord::Migration[6.1]
  2. def up
  3. reapplication_follow_recommendations_v2 do
  4. drop_view :account_summaries, materialized: true
  5. create_view :account_summaries, version: 2, materialized: { no_data: true }
  6. safety_assured { add_index :account_summaries, :account_id, unique: true }
  7. end
  8. end
  9. def down
  10. reapplication_follow_recommendations_v2 do
  11. drop_view :account_summaries, materialized: true
  12. create_view :account_summaries, version: 1, materialized: { no_data: true }
  13. safety_assured { add_index :account_summaries, :account_id, unique: true }
  14. end
  15. end
  16. def reapplication_follow_recommendations_v2
  17. drop_view :follow_recommendations, materialized: true
  18. yield
  19. create_view :follow_recommendations, version: 2, materialized: { no_data: true }
  20. safety_assured { add_index :follow_recommendations, :account_id, unique: true }
  21. end
  22. end