Sha256: b8f993bcaf64e46bfe158626e3e53c1e0b8f7654e448ca9f7ff2d1e09249de2e
Contents?: true
Size: 1.05 KB
Versions: 48
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true module DummyApp module Migrations extend self # Ensure database exists def database_exists? ActiveRecord::Base.connection rescue ActiveRecord::NoDatabaseError false else true end 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 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 sh(cmd) puts cmd system cmd end end end
Version data entries
48 entries across 48 versions & 2 rubygems