Skip to content

Commit

Permalink
fixed migrations bug of plugins (#221)
Browse files Browse the repository at this point in the history
great job in drilling down this bug!
  • Loading branch information
sukhbir-singh authored and cpg committed Aug 6, 2018
1 parent 4e008c9 commit a614718
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/models/plugin.rb
Expand Up @@ -56,8 +56,7 @@ def before_destroy
base = File.basename path
destination = File.join(Rails.root, "plugins", "#{1000+id}-#{base}")

Rails.application.paths["db/migrate"] << "#{destination}/db/migrate"
ActiveRecord::Migration.new.migrate(:down)
Plugin.run_migration(destination, :down)

FileUtils.rm_rf destination
# restart the rails stack -- FIXME: this is too much a restart would be best
Expand All @@ -81,15 +80,27 @@ def dir2plugin(source, config)
FileUtils.rm_rf destination
FileUtils.mv source, destination

Rails.application.paths["db/migrate"] << "#{destination}/db/migrate"
ActiveRecord::Migration.new.migrate(:up)
self.run_migration(destination, :up)

# restart the rails stack -- FIXME: this is too much a restart would be best
c = Command.new "touch /var/hda/platform/html/tmp/restart.txt"
c.execute
# return the plugin we just created
plugin
end

def run_migration(destination, type)
migration_files = Dir["#{destination}/db/migrate/*.rb"]
migration_files.each do |migration_file|
start_index = migration_file.index("_")+1
last_index = migration_file.rindex(".")-1
require "#{migration_file}"

class_name = migration_file[start_index..last_index].camelize.constantize
class_name.new.migrate(type)
end
end

end

end

0 comments on commit a614718

Please sign in to comment.