Sha256: 66356adebc08ec795adf87463e959b9af852dc044d16586a04743a0464723c66

Contents?: true

Size: 969 Bytes

Versions: 9

Compression:

Stored size: 969 Bytes

Contents

# http://nithinbekal.com/posts/safe-rake-tasks

namespace :strong_migrations do
  task safety_assured: :environment do
    raise "Set SAFETY_ASSURED=1 to run this task in production" if Rails.env.production? && !ENV["SAFETY_ASSURED"]
  end

  # https://www.pgrs.net/2008/03/13/alphabetize-schema-rb-columns/
  task :alphabetize_columns do
    $stderr.puts "Dumping schema"
    ActiveRecord::Base.logger.level = Logger::INFO

    class << ActiveRecord::Base.connection
      alias_method :old_columns, :columns unless instance_methods.include?("old_columns")
      alias_method :old_extensions, :extensions unless instance_methods.include?("old_extensions")

      def columns(*args)
        old_columns(*args).sort_by(&:name)
      end

      def extensions(*args)
        old_extensions(*args).sort
      end
    end
  end
end

["db:drop", "db:reset", "db:schema:load", "db:structure:load"].each do |t|
  Rake::Task[t].enhance ["strong_migrations:safety_assured"]
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
strong_migrations-0.2.2 lib/tasks/strong_migrations.rake
strong_migrations-0.2.1 lib/tasks/strong_migrations.rake
strong_migrations-0.2.0 lib/tasks/strong_migrations.rake
strong_migrations-0.1.9 lib/tasks/strong_migrations.rake
strong_migrations-0.1.8 lib/tasks/strong_migrations.rake
strong_migrations-0.1.7 lib/tasks/strong_migrations.rake
strong_migrations-0.1.6 lib/tasks/strong_migrations.rake
strong_migrations-0.1.5 lib/tasks/strong_migrations.rake
strong_migrations-0.1.4 lib/tasks/strong_migrations.rake