module DummyApp::Migrations

Public Instance Methods

auto_migrate() click to toggle source
# File lib/spree/testing_support/dummy_app/migrations.rb, line 22
def auto_migrate
  if needs_migration?
    puts "Configuration changed. Re-running migrations"

    # Disconnect to avoid "database is being accessed by other users" on postgres
    ActiveRecord::Base.remove_connection

    sh 'rake db:reset VERBOSE=false'

    # We have a brand new database, so we must re-establish our connection
    ActiveRecord::Base.establish_connection
  end
end
database_exists?() click to toggle source

Ensure database exists

# File lib/spree/testing_support/dummy_app/migrations.rb, line 8
def database_exists?
  ActiveRecord::Base.connection
rescue ActiveRecord::NoDatabaseError
  false
else
  true
end
needs_migration?() click to toggle source
# File lib/spree/testing_support/dummy_app/migrations.rb, line 16
def needs_migration?
  return true if !database_exists?

  ActiveRecord::Base.connection.migration_context.needs_migration?
end

Private Instance Methods

sh(cmd) click to toggle source
# File lib/spree/testing_support/dummy_app/migrations.rb, line 38
def sh(cmd)
  puts cmd
  system cmd
end