Permalink
Browse files

rails 3 compatibility, closes #4

  • Loading branch information...
1 parent 76fdd32 commit c97d9cdf34add3d10c62dab63c7e9af693d7cca9 @jenseng committed Apr 17, 2011
Showing with 19 additions and 7 deletions.
  1. +3 −1 Gemfile
  2. +1 −1 README.rdoc
  3. +1 −1 Rakefile
  4. +4 −0 lib/hair_trigger.rb
  5. +2 −1 lib/hair_trigger/adapter.rb
  6. +1 −1 lib/hair_trigger/builder.rb
  7. +7 −2 spec/schema_dumper_spec.rb
View
@@ -1,12 +1,14 @@
source "http://rubygems.org"
-gem "activerecord", ">=2.3.0", "<3.0"
+#gem "activerecord", ">=2.3.0", "<3.0"
+gem "activerecord", ">=2.3.0"
group :development do
gem "rspec", "~> 2.3.0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.2"
gem "rcov", ">= 0"
gem 'mysql', '>= 2.8.1'
+ gem 'mysql2', '>= 0.2.7'
gem 'pg', '>= 0.10.1'
gem 'sqlite3-ruby', '>= 1.3.2'
end
View
@@ -203,7 +203,7 @@ you want to support.
== Compatibility
-* Rails 2.3.x
+* Rails 2.3+
* Postgres 8.0+
* MySQL 5.0.10+
* SQLite 3.3.8+
View
@@ -19,7 +19,7 @@ Jeweler::Tasks.new do |gem|
gem.description = %Q{allows you to declare database triggers in ruby in your models, and then generate appropriate migrations as they change}
gem.email = "jenseng@gmail.com"
gem.authors = ["Jon Jensen"]
- gem.add_dependency "activerecord", ">=2.3.0", "<3.0"
+ gem.add_dependency "activerecord", ">=2.3.0"
gem.add_development_dependency "rspec", "~> 2.3.0"
end
Jeweler::RubygemsDotOrgTasks.new
View
@@ -175,6 +175,10 @@ def schema_rb_path
def migration_path
@migration_path ||= 'db/migrate'
end
+
+ def adapter_name_for(adapter)
+ adapter.adapter_name.downcase.sub(/\d$/, '').to_sym
+ end
end
end
@@ -15,7 +15,8 @@ def drop_trigger(name, table, options = {})
def triggers(options = {})
triggers = {}
name_clause = options[:only] ? "IN ('" + options[:only].join("', '") + "')" : nil
- case self.adapter_name.downcase.to_sym
+ adapter_name = HairTrigger.adapter_name_for(self)
+ case adapter_name
when :sqlite
select_rows("SELECT name, sql FROM sqlite_master WHERE type = 'trigger' #{name_clause ? " AND name " + name_clause : ""}").each do |(name, definition)|
triggers[name] = definition + ";\n"
@@ -270,7 +270,7 @@ def maybe_execute(&block)
end
def adapter_name
- @adapter_name ||= adapter.adapter_name.downcase.to_sym
+ @adapter_name ||= HairTrigger.adapter_name_for(adapter)
end
def adapter
@@ -1,7 +1,9 @@
require 'active_record'
+require 'logger'
require 'active_record/connection_adapters/postgresql_adapter'
require 'active_record/connection_adapters/mysql_adapter'
require 'active_record/connection_adapters/sqlite3_adapter'
+require 'mysql2'
require 'rspec'
require 'hair_trigger'
@@ -25,7 +27,7 @@ def initialize_db(adapter)
reset_tmp
config = {:database => 'hairtrigger_schema_test', :username => 'hairtrigger', :adapter => adapter.to_s, :host => 'localhost'}
case adapter
- when :mysql
+ when :mysql, :mysql2
ret = `echo "drop database if exists hairtrigger_schema_test; create database hairtrigger_schema_test;" | mysql hairtrigger_schema_test -u hairtrigger`
raise "error creating database: #{ret}" unless $?.exitstatus == 0
when :sqlite3
@@ -36,13 +38,16 @@ def initialize_db(adapter)
raise "error creating database: #{ret}" unless $?.exitstatus == 0
config[:min_messages] = :error
end
+ # Arel has an issue in that it keeps using original connection for quoting,
+ # etc. (which breaks stuff) unless you do this:
+ Arel::Visitors::ENGINE_VISITORS.delete(ActiveRecord::Base) if defined?(Arel)
ActiveRecord::Base.establish_connection(config)
ActiveRecord::Base.logger = Logger.new('/dev/null')
ActiveRecord::Migrator.migrate(HairTrigger.migration_path)
end
describe "schema" do
- [:mysql, :postgresql, :sqlite3].each do |adapter|
+ [:mysql, :mysql2, :postgresql, :sqlite3].each do |adapter|
it "should correctly dump #{adapter}" do
ActiveRecord::Migration.verbose = false
initialize_db(adapter)

0 comments on commit c97d9cd

Please sign in to comment.