lib/combustion/database.rb in combustion-0.5.3 vs lib/combustion/database.rb in combustion-0.5.4
- old
+ new
@@ -1,13 +1,11 @@
module Combustion
class Database
def self.setup
- silence_stream(STDOUT) do
- reset_database
- load_schema
- migrate
- end
+ reset_database
+ load_schema
+ migrate
end
def self.reset_database
ActiveRecord::Base.configurations = YAML.load(ERB.new(File.read("#{Rails.root}/config/database.yml")).result)
abcs = ActiveRecord::Base.configurations
@@ -55,18 +53,20 @@
end
end
def self.migrate
migrator = ActiveRecord::Migrator
+ engine_path = Rails.application.root.sub(::Combustion.path, '')
+ engine_migration_paths = Rails.application.paths['db/migrate'].to_a
- if migrator.respond_to?(:migrations_paths)
- paths = migrator.migrations_paths
+ if engine_migration_paths.include?(engine_path.join('db/migrate').to_s)
+ paths = []
else
- paths = Array('db/migrate/')
+ paths = base_migration_paths
end
- paths += Rails.application.paths['db/migrate'].to_a
+ paths += engine_migration_paths
paths.uniq!
# Append the migrations inside the internal app's db/migrate directory
paths << File.join(Rails.root, 'db/migrate')
@@ -76,9 +76,17 @@
paths.each { |path| migrator.migrate path, nil }
end
end
private
+
+ def self.base_migration_paths
+ if ActiveRecord::Migrator.respond_to?(:migrations_paths)
+ ActiveRecord::Migrator.migrations_paths
+ else
+ Array('db/migrate/')
+ end
+ end
def self.create_database(config)
begin
if config['adapter'] =~ /sqlite/
if File.exist?(config['database'])