From 11d7c2a17b945d2a3d366659a1d94d6cb298a48b Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Thu, 26 Sep 2024 10:49:41 +0200 Subject: [PATCH] Remove data migrations workflow/gem These data migrations are meant to be run on production instances where we need to manipulate the data once and not to be run when setting up new instances. Also, if we skip a deploy on specific instances for some reason, which is not ideal, but does happen, there are too many considerations to be ideal. We have a PR to make them more idempotent, but even so the first ones were written when all instances were single tenant and we could be sure there was only one organization, but after introducing multi-tenancy, there is another layer that must be considered. --- Gemfile | 2 - Gemfile.lock | 4 -- ansible/roles/installation/tasks/main.yml | 5 -- ...7080438_scope_settings_to_organizations.rb | 58 ------------------- ...2092527_add_organization_id_to_requests.rb | 29 ---------- ...ganization_id_to_activity_notifications.rb | 29 ---------- ...6063319_add_organization_id_to_taggings.rb | 29 ---------- ...30085839_rebuild_pg_search_multi_search.rb | 15 ----- ...18_migrate_users_to_users_organizations.rb | 13 ----- 9 files changed, 184 deletions(-) delete mode 100644 db/data/20240717080438_scope_settings_to_organizations.rb delete mode 100644 db/data/20240722092527_add_organization_id_to_requests.rb delete mode 100644 db/data/20240726061113_add_organization_id_to_activity_notifications.rb delete mode 100644 db/data/20240726063319_add_organization_id_to_taggings.rb delete mode 100644 db/data/20240730085839_rebuild_pg_search_multi_search.rb delete mode 100644 db/data/20240812102718_migrate_users_to_users_organizations.rb diff --git a/Gemfile b/Gemfile index 4c81d3383..2cf9b6a1a 100644 --- a/Gemfile +++ b/Gemfile @@ -97,5 +97,3 @@ gem 'kaminari', '~> 1.2' # Encrypt attrs gem 'attr_encrypted' - -gem 'data_migrate', '~> 9.2.0' diff --git a/Gemfile.lock b/Gemfile.lock index ac306e9bf..b563b1b63 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -146,9 +146,6 @@ GEM cuprite (0.13) capybara (>= 2.1, < 4) ferrum (~> 0.11.0) - data_migrate (9.2.0) - activerecord (>= 6.1) - railties (>= 6.1) db-query-matchers (0.11.0) activesupport (>= 4.0, < 7.1) rspec (>= 3.0) @@ -460,7 +457,6 @@ DEPENDENCIES clearance counter_culture (~> 3.3) cuprite - data_migrate (~> 9.2.0) db-query-matchers delayed_job_active_record (~> 4.1) dotenv-rails diff --git a/ansible/roles/installation/tasks/main.yml b/ansible/roles/installation/tasks/main.yml index 1bdca7f43..145503f0e 100644 --- a/ansible/roles/installation/tasks/main.yml +++ b/ansible/roles/installation/tasks/main.yml @@ -77,8 +77,3 @@ command: cmd: docker compose -f docker-compose.yml -f docker-compose.prod.yml exec app bin/rails db:migrate chdir: /home/ansible - -- name: Run data migrations - command: - cmd: docker compose -f docker-compose.yml -f docker-compose.prod.yml exec app bin/rails data:migrate - chdir: /home/ansible diff --git a/db/data/20240717080438_scope_settings_to_organizations.rb b/db/data/20240717080438_scope_settings_to_organizations.rb deleted file mode 100644 index 5c7db7642..000000000 --- a/db/data/20240717080438_scope_settings_to_organizations.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -class ScopeSettingsToOrganizations < ActiveRecord::Migration[6.1] - def up - ActiveRecord::Base.transaction do - organization = Organization.singleton - return unless organization - - attrs = Setting.keys - attrs.each do |setting| - next unless organization.respond_to?("#{setting}=") - - organization.send("#{setting}=", Setting.send(setting)) - Rails.logger.debug '.' - end - - Setting.channels.each do |setting_key, _value| - organization.onboarding_allowed.each do |key, _value| - next unless setting_key.to_sym.eql?(key.to_sym) - - organization.onboarding_allowed[key] = Setting.channels[setting_key][:allow_onboarding] - end - end - - organization.threemarb_api_secret = ENV.fetch('THREEMARB_API_SECRET', nil) - organization.threemarb_private = ENV.fetch('THREEMARB_PRIVATE', nil) - - organization.onboarding_logo.attach(Setting.onboarding_logo) if Setting.onboarding_logo - organization.onboarding_hero.attach(Setting.onboarding_hero) if Setting.onboarding_hero - organization.channel_image.attach(Setting.channel_image) if Setting.channel_image - organization.save! - end - end - - def down - ActiveRecord::Base.transaction do - organization = Organization.singleton - return unless organization - - attrs = Setting.keys - attrs.each do |setting| - next unless organization.respond_to?("#{setting}=") - - organization.send("#{setting}=", nil) - Rails.logger.debug '.' - end - - organization.onboarding_allowed = { threema: true, telegram: true, email: true, signal: true, whats_app: true } - organization.threemarb_api_secret = nil - organization.threemarb_private = nil - - organization.onboarding_logo = nil - organization.onboarding_hero = nil - organization.channel_image = nil - organization.save! - end - end -end diff --git a/db/data/20240722092527_add_organization_id_to_requests.rb b/db/data/20240722092527_add_organization_id_to_requests.rb deleted file mode 100644 index 2943fb84d..000000000 --- a/db/data/20240722092527_add_organization_id_to_requests.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class AddOrganizationIdToRequests < ActiveRecord::Migration[6.1] - def up - ActiveRecord::Base.transaction do - organization = Organization.singleton - return unless organization - - Request.find_each do |request| - request.organization_id = organization.id - request.save!(validate: false) - Rails.logger.debug '.' - end - end - end - - def down - ActiveRecord::Base.transaction do - organization = Organization.singleton - return unless organization - - Request.find_each do |request| - request.organization_id = nil - request.save!(validate: false) - Rails.logger.debug '.' - end - end - end -end diff --git a/db/data/20240726061113_add_organization_id_to_activity_notifications.rb b/db/data/20240726061113_add_organization_id_to_activity_notifications.rb deleted file mode 100644 index 06f348b66..000000000 --- a/db/data/20240726061113_add_organization_id_to_activity_notifications.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class AddOrganizationIdToActivityNotifications < ActiveRecord::Migration[6.1] - def up - ActiveRecord::Base.transaction do - organization = Organization.singleton - return unless organization - - ActivityNotification.find_each do |notification| - notification.organization_id = organization.id - notification.save! - Rails.logger.debug '.' - end - end - end - - def down - ActiveRecord::Base.transaction do - organization = Organization.singleton - return unless organization - - ActivityNotification.find_each do |notification| - notification.organization_id = nil - notification.save! - Rails.logger.debug '.' - end - end - end -end diff --git a/db/data/20240726063319_add_organization_id_to_taggings.rb b/db/data/20240726063319_add_organization_id_to_taggings.rb deleted file mode 100644 index a5bd95ad5..000000000 --- a/db/data/20240726063319_add_organization_id_to_taggings.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class AddOrganizationIdToTaggings < ActiveRecord::Migration[6.1] - def up - ActiveRecord::Base.transaction do - organization = Organization.singleton - return unless organization - - ActsAsTaggableOn::Tagging.find_each do |tag| - tag.tenant = organization.id - tag.save! - Rails.logger.debug '.' - end - end - end - - def down - ActiveRecord::Base.transaction do - organization = Organization.singleton - return unless organization - - ActsAsTaggableOn::Tagging.find_each do |tag| - tag.tenant = nil - tag.save! - Rails.logger.debug '.' - end - end - end -end diff --git a/db/data/20240730085839_rebuild_pg_search_multi_search.rb b/db/data/20240730085839_rebuild_pg_search_multi_search.rb deleted file mode 100644 index f1302a1d3..000000000 --- a/db/data/20240730085839_rebuild_pg_search_multi_search.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class RebuildPgSearchMultiSearch < ActiveRecord::Migration[6.1] - def up - PgSearch::Multisearch.rebuild(Contributor) - PgSearch::Multisearch.rebuild(Message) - PgSearch::Multisearch.rebuild(Request) - end - - def down - PgSearch::Multisearch.rebuild(Contributor) - PgSearch::Multisearch.rebuild(Message) - PgSearch::Multisearch.rebuild(Request) - end -end diff --git a/db/data/20240812102718_migrate_users_to_users_organizations.rb b/db/data/20240812102718_migrate_users_to_users_organizations.rb deleted file mode 100644 index d049bedc2..000000000 --- a/db/data/20240812102718_migrate_users_to_users_organizations.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class MigrateUsersToUsersOrganizations < ActiveRecord::Migration[6.1] - def up - User.admin(false).find_each do |user| - UsersOrganization.create!(user_id: user.id, organization_id: user.organization_id) - end - end - - def down - UsersOrganization.destroy_all - end -end