DEV: Promote old post-deploy migrations to pre-deploy migrations (#13477)

DEV: Promote old post-deploy migrations to pre-deploy migrations (#13477)

Having a large number of post-deploy migrations running out-of-numerical-sequence with pre-deploy migrations can be problematic. For example, if we have the sequence

  • db/migrate/2017… - add column
  • db/post_migrate/2018… - drop the column
  • db/migrate/2021… - add the same column again

It will work fine in numerical order. But if you run the pre-deploy migrations followed by the post-deploy migrations, you will not get the same result.

Our post-deploy system is designed to allow for seamless upgrades of Discourse. However, it is reasonable for us to only support this totally seamless experience for a limited period of time. This commit moves all post_deploy migrations which are more than 1 year old (i.e. more than 2 major Discourse versions ago) into the regular pre-deploy migrations directory. This limits the impact of any edge cases caused by out-of-numerical-sequence migrations.

diff --git a/db/migrate/20180917024729_remove_superfluous_columns.rb b/db/migrate/20180917024729_remove_superfluous_columns.rb
new file mode 100644
index 0000000..a230734
--- /dev/null
+++ b/db/migrate/20180917024729_remove_superfluous_columns.rb
@@ -0,0 +1,87 @@
+# frozen_string_literal: true
+
+require 'migration/column_dropper'
+require 'badge_posts_view_manager'
+
+class RemoveSuperfluousColumns < ActiveRecord::Migration[5.2]
+  DROPPED_COLUMNS ||= {
+    user_profiles: %i{
+        card_image_badge_id
+      },
+    categories: %i{
+        logo_url
+        background_url
+        suppress_from_homepage
+      },
+    groups: %i{
+        visible
+        public
+        alias_level
+      },
+    theme_fields: %i{target},
+    user_stats: %i{first_topic_unread_at},
+    topics: %i{
+        auto_close_at
+        auto_close_user_id
+        auto_close_started_at
+        auto_close_based_on_last_post
+        auto_close_hours
+        inappropriate_count
+        bookmark_count
+        off_topic_count
+        illegal_count
+        notify_user_count
+        last_unread_at
+        vote_count
+      },
+    users: %i{
+        email
+        email_always
+        mailing_list_mode
+        email_digests
+        email_direct
+        email_private_messages
+        external_links_in_new_tab
+        enable_quoting
+        dynamic_favicon
+        disable_jump_reply
+        edit_history_public
+        automatically_unpin_topics
+        digest_after_days
+        auto_track_topics_after_msecs
+        new_topic_duration_minutes
+        last_redirected_to_top_at
+        auth_token
+        auth_token_updated_at
+        blocked
+        silenced
+        trust_level_locked
+      },
+    user_auth_tokens: %i{legacy},
+    user_options: %i{theme_key},
+    themes: %i{key},
+    email_logs: %i{
+        topic_id
+        reply_key
+        skipped
+        skipped_reason
+      },
+    posts: %i{vote_count}
+  }
+
+  def up
+    BadgePostsViewManager.drop!
+
+    DROPPED_COLUMNS.each do |table, columns|
+      Migration::ColumnDropper.execute_drop(table, columns)
+    end
+
+    DB.exec "DROP FUNCTION IF EXISTS first_unread_topic_for(int)"
+
+    BadgePostsViewManager.create!
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end
diff --git a/db/migrate/20180917034056_remove_superfluous_tables.rb b/db/migrate/20180917034056_remove_superfluous_tables.rb
new file mode 100644
index 0000000..f652452
--- /dev/null
+++ b/db/migrate/20180917034056_remove_superfluous_tables.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'migration/table_dropper'
+
+class RemoveSuperfluousTables < ActiveRecord::Migration[5.2]
+  DROPPED_TABLES ||= %i{
+      category_featured_users
+      versions
+      topic_status_updates
+    }
+
+  def up
+    DROPPED_TABLES.each do |table|
+      Migration::TableDropper.execute_drop(table)
+    end
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end
diff --git a/db/migrate/20181012123001_drop_group_locked_trust_level_from_user.rb b/db/migrate/20181012123001_drop_group_locked_trust_level_from_user.rb
new file mode 100644
index 0000000..3b3bd6e
--- /dev/null
+++ b/db/migrate/20181012123001_drop_group_locked_trust_level_from_user.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+require 'migration/column_dropper'
+
+class DropGroupLockedTrustLevelFromUser < ActiveRecord::Migration[5.2]
+  DROPPED_COLUMNS ||= {
+    posts: %i{group_locked_trust_level}
+  }
+
+  def up
+    DROPPED_COLUMNS.each do |table, columns|
+      Migration::ColumnDropper.execute_drop(table, columns)
+    end
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end
diff --git a/db/migrate/20181112013117_migrate_url_site_settings.rb b/db/migrate/20181112013117_migrate_url_site_settings.rb
new file mode 100644
index 0000000..def8f2b
--- /dev/null
+++ b/db/migrate/20181112013117_migrate_url_site_settings.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class MigrateUrlSiteSettings < ActiveRecord::Migration[5.2]
+  def change
+    # Do nothing, the migration was moved into a onceoff job
+  end
+end
diff --git a/db/migrate/20190103065652_remove_uploaded_meta_id_from_category.rb b/db/migrate/20190103065652_remove_uploaded_meta_id_from_category.rb
new file mode 100644
index 0000000..9aba22f
--- /dev/null
+++ b/db/migrate/20190103065652_remove_uploaded_meta_id_from_category.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+require 'migration/column_dropper'
+
+class RemoveUploadedMetaIdFromCategory < ActiveRecord::Migration[5.2]
+  DROPPED_COLUMNS ||= {
+    categories: %i{uploaded_meta_id}
+  }
+
+  def up
+    DROPPED_COLUMNS.each do |table, columns|
+      Migration::ColumnDropper.execute_drop(table, columns)
+    end
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end
diff --git a/db/migrate/20190121203023_drop_queued_post_id_from_user_actions.rb b/db/migrate/20190121203023_drop_queued_post_id_from_user_actions.rb
new file mode 100644
index 0000000..0a1f2b6
--- /dev/null
+++ b/db/migrate/20190121203023_drop_queued_post_id_from_user_actions.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class DropQueuedPostIdFromUserActions < ActiveRecord::Migration[5.2]
+  def up
+    remove_column :user_actions, :queued_post_id
+  end
+
+  def down
+    add_column :user_actions, :queued_post_id, :integer
+  end
+end
diff --git a/db/migrate/20190123171817_drop_queued_posts.rb b/db/migrate/20190123171817_drop_queued_posts.rb
new file mode 100644
index 0000000..704b984
--- /dev/null
+++ b/db/migrate/20190123171817_drop_queued_posts.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class DropQueuedPosts < ActiveRecord::Migration[5.2]
+  def up
+    drop_table :queued_posts
+  end
+end
diff --git a/db/migrate/20190205104116_drop_unused_auth_tables.rb b/db/migrate/20190205104116_drop_unused_auth_tables.rb
new file mode 100644
index 0000000..99fa6f7
--- /dev/null
+++ b/db/migrate/20190205104116_drop_unused_auth_tables.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+require 'migration/table_dropper'
+
+class DropUnusedAuthTables < ActiveRecord::Migration[5.2]
+  def change
+    # this migration was defect
+  end
+end
diff --git a/db/migrate/20190208144706_drop_unused_auth_tables_again.rb b/db/migrate/20190208144706_drop_unused_auth_tables_again.rb
new file mode 100644
index 0000000..6fb208c
--- /dev/null
+++ b/db/migrate/20190208144706_drop_unused_auth_tables_again.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+require 'migration/table_dropper'
+
+class DropUnusedAuthTablesAgain < ActiveRecord::Migration[5.2]
+  DROPPED_TABLES ||= %i{
+        facebook_user_infos
+        twitter_user_infos
+      }
+
+  def up
+    DROPPED_TABLES.each do |table|
+      Migration::TableDropper.execute_drop(table)
+    end
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end
diff --git a/db/migrate/20190312194528_drop_email_user_options_columns.rb b/db/migrate/20190312194528_drop_email_user_options_columns.rb
new file mode 100644
index 0000000..1b4203b
--- /dev/null
+++ b/db/migrate/20190312194528_drop_email_user_options_columns.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'migration/column_dropper'
+
+class DropEmailUserOptionsColumns < ActiveRecord::Migration[5.2]
+  DROPPED_COLUMNS ||= {
+    user_options: %i{
+        email_direct
+        email_private_messages
+        email_always
+      },
+  }
+
+  def up
+    DROPPED_COLUMNS.each do |table, columns|
+      Migration::ColumnDropper.execute_drop(table, columns)
+    end
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end
diff --git a/db/migrate/20190508141824_drop_claimed_by_id.rb b/db/migrate/20190508141824_drop_claimed_by_id.rb
new file mode 100644
index 0000000..ed9bca6
--- /dev/null
+++ b/db/migrate/20190508141824_drop_claimed_by_id.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+

[... diff too long, it was truncated ...]

GitHub sha: e76c583b91f7ae9c528dd5c04705427d7870677a

This commit appears in #13477 which was approved by eviltrout. It was merged by davidtaylorhq.