Class: Combustion::Database
- Inherits:
-
Object
- Object
- Combustion::Database
- Defined in:
- lib/combustion/database.rb
Class Method Summary collapse
Class Method Details
.load_schema ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/combustion/database.rb', line 45 def self.load_schema case Combustion.schema_format when :ruby load Rails.root.join('db', 'schema.rb') when :sql ActiveRecord::Base.connection.execute( File.read(Rails.root.join('db', 'structure.sql')) ) else raise "Unknown schema format: #{Combustion.schema_format}" end end |
.migrate ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/combustion/database.rb', line 58 def self.migrate migrator = ActiveRecord::Migrator paths = Array('db/migrate/') if migrator.respond_to?(:migrations_paths) paths = migrator.migrations_paths end # Append the migrations inside the internal app's db/migrate directory paths << File.join(Rails.root, 'db/migrate') if ActiveRecord::VERSION::STRING >= '3.1.0' migrator.migrate paths, nil else paths.each { |path| migrator.migrate path, nil } end end |
.reset_database ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/combustion/database.rb', line 11 def self.reset_database ActiveRecord::Base.configurations = YAML.load(ERB.new(File.read("#{Rails.root}/config/database.yml")).result) abcs = ActiveRecord::Base.configurations case abcs['test']['adapter'] when /mysql/ drop_database(abcs['test']['database']) create_database(abcs['test']) ActiveRecord::Base.establish_connection(:test) when /postgresql/ ActiveRecord::Base.clear_active_connections! drop_database(abcs['test']) create_database(abcs['test']) when /sqlite/ drop_database(abcs['test']) create_database(abcs['test']) when 'sqlserver' test = abcs.deep_dup['test'] test_database = test['database'] test['database'] = 'master' ActiveRecord::Base.establish_connection(test) ActiveRecord::Base.connection.recreate_database!(test_database) when "oci", "oracle" ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl| ActiveRecord::Base.connection.execute(ddl) end when 'firebird' ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.connection.recreate_database! else raise "Cannot reset databases for '#{abcs['test']['adapter']}'" end end |
.setup ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/combustion/database.rb', line 3 def self.setup silence_stream(STDOUT) do reset_database load_schema migrate end end |