Skip to content

Instantly share code, notes, and snippets.

@gudata
Created February 6, 2013 07:30
Show Gist options
  • Select an option

  • Save gudata/4720936 to your computer and use it in GitHub Desktop.

Select an option

Save gudata/4720936 to your computer and use it in GitHub Desktop.
Rails with Joomla Integration. This is when you have two databases and want to use the migrations. Use this code until you get rid of Joomla
desc "Sync the schema_migrations tables on both databases"
task :sync_schema_migrations => :environment do
class JoomlaSchemaMigrations < ActiveRecord::Base
establish_connection "joomla_#{Rails.env}"
self.table_name = 'schema_migrations'
self.inheritance_column = :sti_type
attr_accessible :version
end
class RailsSchemaMigrations < ActiveRecord::Base
self.table_name = 'schema_migrations'
self.inheritance_column = :sti_type
attr_accessible :version
end
joomla_migrations = JoomlaSchemaMigrations.all.collect(&:version)
rails_migrations = RailsSchemaMigrations.all.collect(&:version)
migrations_missing_in_rails = joomla_migrations - rails_migrations
migrations_missing_in_joomla = rails_migrations - joomla_migrations
puts "filling up the rails schema_migrations"
migrations_missing_in_rails.each do |version|
puts " adding...#{version}"
RailsSchemaMigrations.create(:version => version)
end
puts "filling up the joomla schema_migrations"
migrations_missing_in_joomla.each do |version|
puts " adding...#{version}"
JoomlaSchemaMigrations.create(:version => version)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment