Sha256: d8b8c0aef3de5b372089b262303b25c9b177a0f1a508e115e4f8096a222c3bdd

Contents?: true

Size: 784 Bytes

Versions: 3

Compression:

Stored size: 784 Bytes

Contents

# frozen_string_literal: true

module DummyApp
  module Migrations
    extend self

    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

    private

    def needs_migration?
      ActiveRecord::Migration.check_all_pending!
    rescue ActiveRecord::PendingMigrationError, ActiveRecord::NoDatabaseError
      true
    else
      false
    end

    def sh(cmd)
      puts cmd
      system cmd
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_core-4.4.2 lib/spree/testing_support/dummy_app/migrations.rb
solidus_core-4.4.1 lib/spree/testing_support/dummy_app/migrations.rb
solidus_core-4.4.0 lib/spree/testing_support/dummy_app/migrations.rb