Module: DummyApp::Migrations

Extended by:
Migrations
Included in:
Migrations
Defined in:
lib/spree/testing_support/dummy_app/migrations.rb

Instance Method Summary collapse

Instance Method Details

#auto_migrateObject



26
27
28
29
30
31
32
33
34
# File 'lib/spree/testing_support/dummy_app/migrations.rb', line 26

def auto_migrate
  if needs_migration?
    puts "Configuration changed. Re-running migrations"
    sh 'rake db:reset VERBOSE=false'

    # We might have a brand new database, so we must re-establish our connection
    ActiveRecord::Base.establish_connection
  end
end

#database_exists?Boolean

Ensure database exists

Returns:

  • (Boolean)


8
9
10
11
12
13
14
# 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?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
# File 'lib/spree/testing_support/dummy_app/migrations.rb', line 16

def needs_migration?
  return true if !database_exists?
  if ActiveRecord::Base.connection.respond_to?(:migration_context)
    # Rails >= 5.2
    ActiveRecord::Base.connection.migration_context.needs_migration?
  else
    ActiveRecord::Migrator.needs_migration?
  end
end