Skip to content

Commit

Permalink
Add a upgrader for tags
Browse files Browse the repository at this point in the history
Since the acts-as-taggable-on migrations make use of the ActsAsTaggableOn class, we want to skip the tasks inside of these migrations. We renamed the tables anyway, but in order to be able to re-run these migrations without harm it makes sense to skip these migrations.
  • Loading branch information
tvdeyen committed Feb 27, 2018
1 parent 7631a82 commit 5a46220
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
29 changes: 29 additions & 0 deletions lib/alchemy/upgrader/four_point_one.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require_relative 'tasks/harden_acts_as_taggable_on_migrations'

module Alchemy
class Upgrader::FourPointOne < Upgrader
class << self
def harden_acts_as_taggable_on_migrations
desc 'Harden `acts_as_taggable_on_migrations`'
`bundle exec rake railties:install:migrations FROM=acts_as_taggable_on_engine`
Alchemy::Upgrader::Tasks::HardenActsAsTaggableOnMigrations.new.patch_migrations
`bundle exec rake db:migrate`
end

def alchemy_4_1_todos
notice = <<-NOTE
Changed tagging provider to Gutentag
------------------------------------
The automatic updater that just ran updated all existing `acts_as_taggable_on_migrations`,
so that they don't blow up if the `acts_as_taggable_on` gem is no longer available.
All your existing tags have been migrated to `Gutentag::Tag`s.
NOTE
todo notice, 'Alchemy v4.1 changes'
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'thor'

module Alchemy::Upgrader::Tasks
class HardenActsAsTaggableOnMigrations < Thor
include Thor::Actions

no_tasks do
def patch_migrations
sentinel = /add_column.*/
aato_file = Dir.glob('db/migrate/*_add_taggings_counter_cache_to_tags.*.rb').first
if aato_file
inject_into_file aato_file,
"\n\n # inserted by Alchemy CMS upgrader\n return unless defined?(ActsAsTaggableOn)",
{ after: sentinel, verbose: true }
end

sentinel = /def up/
aato_file = Dir.glob('db/migrate/*_change_collation_for_tag_names.*.rb').first
if aato_file
inject_into_file aato_file,
"\n # inserted by Alchemy CMS upgrader\n return unless defined?(ActsAsTaggableOn)\n",
{ after: sentinel, verbose: true }
end
end
end
end
end
25 changes: 24 additions & 1 deletion lib/tasks/alchemy/upgrade.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ require 'alchemy/version'
namespace :alchemy do
desc "Upgrades your app to AlchemyCMS v#{Alchemy::VERSION}."
task upgrade: [
'alchemy:upgrade:prepare'
'alchemy:upgrade:prepare',
'alchemy:upgrade:4.1:run', 'alchemy:upgrade:4.1:todo'
] do
Alchemy::Upgrader.display_todos
end
Expand Down Expand Up @@ -33,5 +34,27 @@ namespace :alchemy do
picture.update_column(:image_file_format, picture.image_file_format.to_s.chomp)
end
end

desc 'Upgrade Alchemy to v4.1'
task '4.1' => [
'alchemy:upgrade:prepare',
'alchemy:upgrade:4.1:run',
'alchemy:upgrade:4.1:todo'
] do
Alchemy::Upgrader.display_todos
end

namespace '4.1' do
task run: ['alchemy:upgrade:4.1:harden_acts_as_taggable_on_migrations']

desc 'Harden acts_as_taggable_on migrations'
task harden_acts_as_taggable_on_migrations: [:environment] do
Alchemy::Upgrader::FourPointOne.harden_acts_as_taggable_on_migrations
end

task :todo do
Alchemy::Upgrader::FourPointOne.alchemy_4_1_todos
end
end
end
end

0 comments on commit 5a46220

Please sign in to comment.