Sha256: 8d636c60134a9d3deaef15291d9c51ab53bbe0ff4df51440e95c384af19bc907
Contents?: true
Size: 908 Bytes
Versions: 64
Compression:
Stored size: 908 Bytes
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? ActiveRecord::Base.connection.migration_context.needs_migration? 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
64 entries across 64 versions & 1 rubygems